项目部署
- 运行容器
- 解决Centos8中yum命令遇到的问题
- 打包项目
- 拷贝`.jar`到容器中
- 安装jdk
- 后台运行`.jar`
- 后台运行`.jar`并输入日志
- 实时查看日志
- 查看/杀死运行程序
- 目录结构
- 日志配置
运行容器
$ docker run -d -p 8001:8001 -p 8081:8081 -p 8082:8082 --name=local_centos --privileged=true -it centos /usr/sbin/init
$ docker exec -it local_centos /bin/bash
解决Centos8中yum命令遇到的问题
在/etc/yum.repos.d
中更新一下源,使用vault.centos.org
代替mirror.centos.org
$ sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
$ sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
打包项目
拷贝.jar
到容器中
$ docker cp ./eureka-server-0.0.1-SNAPSHOT.jar local_centos:/home/server/
$ docker cp ./service-01-0.0.1-SNAPSHOT.jar local_centos:/home/server/
$ docker cp ./service-02-0.0.1-SNAPSHOT.jar local_centos:/home/server/
安装jdk
$ yum search java-1.8.0-openjdk
$ yum install java-1.8.0-openjdk.x86_64 -y
$ java -version
后台运行.jar
$ java -jar /home/server/eureka-server-0.0.1-SNAPSHOT.jar &
$ java -jar /home/server/service-01-0.0.1-SNAPSHOT.jar &
$ java -jar /home/server/service-02-0.0.1-SNAPSHOT.jar &
后台运行.jar
并输入日志
$ nohup java -jar /home/server/eureka-server-0.0.1-SNAPSHOT.jar > logs/debug8001.log 2>&1 &
$ nohup java -jar /home/server/service-01-0.0.1-SNAPSHOT.jar > logs/debug8081.log 2>&1 &
$ nohup java -jar /home/server/service-02-0.0.1-SNAPSHOT.jar > logs/debug8082.log 2>&1 &
实时查看日志
$ tail -100f logs/debug.log
查看/杀死运行程序
$ ps -ef|grep java
$ ps -aux|grep java # aux显示所有状态
$ kill -9 PID
目录结构
日志配置
pom.xml
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.36</version>
</dependency>
<dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.2.11</version>
</dependency>
resources/application.yml
logging:config: classpath:logback-spring.xmllevel:com.example.demo: trace
resources/logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration><include resource="org/springframework/boot/logging/logback/defaults.xml"/><appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"><encoder><pattern>${CONSOLE_LOG_PATTERN}</pattern></encoder></appender><root level="debug"><appender-ref ref="STDOUT"/></root></configuration>