Skip to content

Latest commit

 

History

History
121 lines (95 loc) · 6.93 KB

暂时没时间整理的都放这里怕将来忘记.md

File metadata and controls

121 lines (95 loc) · 6.93 KB

暂时没时间整理的都放这里,曾经有很多优秀的内容没记录,导致想不起,很遗憾

  • 很多之前明明遇到的问题,踩过的坑和掌握的工具, 因为没有及时记录, 到后面要用时全忘了。 一切从头开始做一遍,杯具了
java最优配置参数生成的一个例子
# 2核4G内存的生成的最优配置参数例子
-Xmx2688M -Xms2688M -Xmn960M -XX:MaxMetaspaceSize=512M -XX:MetaspaceSize=512M -XX:+UseConcMarkSweepGC -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses -XX:+CMSClassUnloadingEnabled -XX:+ParallelRefProcEnabled -XX:+CMSScavengeBeforeRemark -XX:ErrorFile=/opt/soft/services/hs_err_pid%p.log   -Xloggc:/opt/soft/services/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -verbose:class -XX:+PrintCommandLineFlags

docker和docker-compose添加自定义域名和IP映射的配置

version: '3.3'

services:
  nginx:
    image: 1.17.0-alpine
    extra_hosts:
      - "a.com:192.168.31.174"
      - "b.com:192.168.31.136"


docker run -it --rm --add-host domain1:192.168.4.152 --add-host domain2:192.168.4.152 nginx:1.17.0-alpine sh
# ping domain1 和 ping domain2 的域名看看
# cat /etc/hosts

有很多重要的东西,由于初始没做记录,到最后都忘了

  • ant-design-pro官方提供的去掉国际化的命令 npm run i18n-removes

  • postgresql,mongo数据库的官方docker镜像尽量加 --privileged=true 参数,虽然不加没什么问题,但是在某些情况下某些操作会提示没有权限,当时没截图,忘了之前出现过什么问题

  • MySQL的官方docker镜像, 无论是docker环境或者docker-compose环境下,都不能加 --privileged=true 参数, 否则启动时老是抛错, 导致数据库运行不了,导致团队的部署环境MySQL跑不起来,这个锅有点重,背不起。下面提供测试命令

# 换了好几个版本的MySQL官方docker镜像,还是有问题,老是抛错
docker run -itd --restart always --privileged=true -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro -e MYSQL_ROOT_PASSWORD=root --name test-mysql mysql:5.7.29
  • gradle的docker镜像打包jar包,用root用户登录centos操作系统,然后用官方提供的命令打jar包,发现出错,提示权限不足之类的错误,官方命令是在容器中以gradle用户运行的
# 部分抛错信息
org.gradle.internal.service.ServiceCreationException: Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
Caused by: org.gradle.internal.service.ServiceCreationException: Could not create service of type CrossBuildFileHashCache using BuildSessionScopeServices.createCrossBuildFileHashCache().
Caused by: org.gradle.api.UncheckedIOException: Failed to create directory '/home/gradle/project/.gradle/4.8.1/fileHashes'
Caused by: org.gradle.api.UncheckedIOException: java.io.IOException: Permission denied
# 官方命令,由于gradle用户没有权限在当前路径创建 .gradle 目录导致的
docker run --rm -u gradle -v "$PWD":/home/gradle/project -w /home/gradle/project gradle:4.8-jdk-alpine gradle build --stacktrace
# 14 --privileged 也提示没权限
docker run --rm --privileged -u gradle -v "$PWD":/home/gradle/project -w /home/gradle/project gradle:4.8-jdk-alpine gradle build --stacktrace
# docker镜像使用 -u root参数后,打包没问题
docker run --rm -u root -v "$PWD":/home/gradle/project -w /home/gradle/project gradle:4.8-jdk-alpine gradle build -x test --stacktrace

用git协议克隆github代码时, 提示 Please make sure you have the correct access rights and the repository exists , 年前是可以的,过年半个月后回公司, 出现这个问题可能有多种原因

  • 公钥确定是加入仓库的,但是git clone不了代码,解决方法是在~/.ssh/known_hosts删掉仓库地址与IP的记录关系 或者重命名 ~/.ssh/known_hosts 文件
  • 事件的全过程, 年前是可以通过git协议克隆代码的, 春节回家过年再回公司, 发现不能克隆了, 老是提示错误 Connection to github.com closed by remote host. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
# 克隆代码提示出错
hgp@hgp-PC:~/workspace/idea$ git clone git@github.com:hegphegp/docker-learning.git
# 正克隆到 'docker-learning'...
# Received disconnect from 13.229.188.59 port 22:11: Bye Bye
# Connection to github.com closed by remote host.
# fatal: Could not read from remote repository.
# 
# Please make sure you have the correct access rights
# and the repository exists.

# 年前是给 /etc/hosts 添加git的dns记录的, 现在手动删掉git的dns记录, 再克隆代码, 还是抛和上面一样的错误

# 删掉 ~/.ssh/known_hosts 文件,git clone命令正常了,可以拉取线上的代码了
mv ~/.ssh/known_hosts ~/.ssh/known_hosts'-'`date +"%Y%m%d-%H%M%S"`
docker pull registry.cn-hangzhou.aliyuncs.com/hegp/ubuntu:18.04.5-20200807
docker tag registry.cn-hangzhou.aliyuncs.com/hegp/ubuntu:18.04.5-20200807 ubuntu:18.04.5-20200807
docker rmi registry.cn-hangzhou.aliyuncs.com/hegp/ubuntu:18.04.5-20200807

## 宿主机安装nginx,搭建apt源的http服务器
mkdir -p /etc/apt/sources.list.d
echo "deb [trusted=yes] https://nginx.org/packages/ubuntu/ $(lsb_release -cs) nginx" > /etc/apt/sources.list.d/nginx.list
echo "deb-src [trusted=yes] https://nginx.org/packages/ubuntu/ $(lsb_release -cs) nginx" >> /etc/apt/sources.list.d/nginx.list
apt-get update
apt-get install -y nginx
systemctl enable nginx
systemctl start nginx

##
docker run --privileged -itd --restart always -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /usr/share/nginx/html:/opt/repository --name ubuntu ubuntu:18.04.5-20200807 /sbin/init

docker exec -it ubuntu bash
mkdir -p /etc/apt/sources.list.d
echo "deb [trusted=yes] https://nginx.org/packages/ubuntu/ $(lsb_release -cs) nginx" > /etc/apt/sources.list.d/nginx.list
echo "deb-src [trusted=yes] https://nginx.org/packages/ubuntu/ $(lsb_release -cs) nginx" >> /etc/apt/sources.list.d/nginx.list

apt-get update

mkdir -p /opt/repository/bionic/nginx/packages
cd /opt/repository/bionic/nginx/packages
apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances nginx=1.18.0-1~bionic | grep "^\w")
exit

# 退出容器,回到宿主机
cd /usr/share/nginx/html/bionic/nginx/
mkdir -p dists/zesty/main/binary-amd64/
dpkg-scanpackages packages /dev/null | gzip > dists/zesty/main/binary-amd64/Packages.gz


docker stop ubuntu
docker rm ubuntu
docker run --privileged -itd --restart always -v /sys/fs/cgroup:/sys/fs/cgroup:ro --name ubuntu ubuntu:18.04.5-20200807 /sbin/init
docker exec -it ubuntu bash

echo "deb [trusted=yes arch=amd64] http://172.17.0.1/bionic/nginx/ zesty main" > /etc/apt/sources.list.d/nginx.list
apt-get update
apt-get install -y nginx