java程序发布步骤
1.拉取代码并打包
2.备份原程序
3.拷贝新程序到服务器的webapps目录中,停一会修改配置
4.重启tomcat
5.验证
主机名 | IP |
jenkins | 192.168.57.135 |
server | 192.168.57.140 |
//启动两台
[root@jenkins ~]# /usr/local/jenkins/bin/startup.sh
//启动两台
[root@server ~]# /usr/local/jenkins/bin/startup.sh
//手动部署
//拉取代码需要用到git命令下载git
[root@jenkins ~]# yum -y install git
[root@jenkins ~]# cd /opt/
[root@jenkins opt]# git clone https://gitee.com/forgotten/tomcat-java-demo.git
正克隆到 'tomcat-java-demo'...
remote: Enumerating objects: 558, done.
remote: Counting objects: 100% (558/558), done.
remote: Compressing objects: 100% (316/316), done.
remote: Total 558 (delta 217), reused 558 (delta 217), pack-reused 0
接收对象中: 100% (558/558), 5.08 MiB | 1.16 MiB/s, 完成.
处理 delta 中: 100% (217/217), 完成.
[root@jenkins opt]# ls
tomcat-java-demo
[root@jenkins opt]# cd tomcat-java-demo/
[root@jenkins tomcat-java-demo]# yum -y install maven
[root@jenkins tomcat-java-demo]# mvn clean package
[INFO] Scanning for projects...
此处省略······
[INFO] Webapp assembled in [301 msecs]
[INFO] Building war: /opt/tomcat-java-dem//因为要把包传到server端,所以要做免密登录,在Jenkins生成公钥传给servero/target/ly-simple-tomcat-0.0.1-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:46 min
[INFO] Finished at: 2021-10-20T11:52:44+08:00
[INFO] ------------------------------------------------------------------------
[root@jenkins tomcat-java-demo]# ls
db deploy.yaml Dockerfile jenkinsfile LICENSE pom.xml README.md src target
[root@jenkins tomcat-java-demo]# ls target/
classes ly-simple-tomcat-0.0.1-SNAPSHOT maven-archiver
generated-sources ly-simple-tomcat-0.0.1-SNAPSHOT.war maven-status
[root@jenkins tomcat-java-demo]# mv target/ly-simple-tomcat-0.0.1-SNAPSHOT.war target/myapp.war
[root@jenkins tomcat-java-demo]# ls target/
classes ly-simple-tomcat-0.0.1-SNAPSHOT maven-status
generated-sources maven-archiver myapp.war
//因为要把包传到server端,所以要做免密登录,在Jenkins生成公钥传给server
[root@jenkins tomcat-java-demo]# ssh-keygen -t rsa
[root@jenkins tomcat-java-demo]# ssh-copy-id root@192.168.47.163
[root@jenkins tomcat-java-demo]# scp target/myapp.war root@192.168.57.140:/usr/local/tomcat/webapps
myapp.war
//查看
[root@server tomcat]# ls webapps/
docs examples host-manager manager myapp myapp.war ROOT
自动部署