主机名称 | IP地址 | 需要的应用服务 | 工具包 | 系统版本 |
---|---|---|---|---|
node1 | 192.168.110.14 | tomcat、jenkins | git、maven | redhat 8 |
node2 | 192.168.110.13 | tomcat | 无 | redhat |
//node1和node2
systemctl disable --now firewalld
sed -ri ‘s/^(SELINUX=).*/\1disabled/g‘ /etc/sysconfig/selinux
setenforce 0
//node1
#在本机查看一下
[root@node1 ~]# ls
anaconda-ks.cfg apache-tomcat-9.0.46.tar.gz jenkins.war
//node1
#安装java环境
[root@node1 ~]# yum -y install java-11-openjdk
#安装工具包
[root@node1 ~]# yum -y install maven git
#解压安装包,创建jenkins项目
[root@node1 ~]# tar xf apache-tomcat-9.0.46.tar.gz
[root@node1 ~]# ls
anaconda-ks.cfg apache-tomcat-9.0.46 apache-tomcat-9.0.46.tar.gz jenkins.war
[root@node1 ~]# mkdir -p /usr/local/tomcat/jenkins
[root@node1 ~]# cp -r apache-tomcat-9.0.46/* /usr/local/tomcat/jenkins/
[root@node1 ~]# cp jenkins.war /usr/local/tomcat/jenkins/webapps/
#启动jenkins项目
[root@node1 ~]# /usr/local/tomcat/jenkins/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat/jenkins
Using CATALINA_HOME: /usr/local/tomcat/jenkins
Using CATALINA_TMPDIR: /usr/local/tomcat/jenkins/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/jenkins/bin/bootstrap.jar:/usr/local/tomcat/jenkins/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@node1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 *:8080 *:*
//node1
#生成密钥,直接回车4下
[root@node1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh‘.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:gns7tHucexs/lfoIp5e07uMYi9HO1ozGOZeiPenOtkg root@node1
The key‘s randomart image is:
+---[RSA 3072]----+
| |
| |
| |
| . |
| . . S . |
| ... . . o |
| ...oEo=B.* |
| .oo+O&X%. |
| o+=X&%*+. |
+----[SHA256]-----+
#密钥传给node2
[root@node1 ~]# ssh-copy-id root@192.168.110.13
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host ‘192.168.110.13 (192.168.110.13)‘ can‘t be established.
ECDSA key fingerprint is SHA256:+UR5bwjFNEKZsJ+X/qSSsMGCvtq5ByludUEL47JqwoU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.110.13‘s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh ‘root@192.168.110.13‘"
and check to make sure that only the key(s) you wanted were added.
//node1
#使用scp命令把Tomcat包传给node2
[root@node1 ~]# scp apache-tomcat-9.0.46.tar.gz root@192.168.110.13:/root/
apache-tomcat-9.0.46.tar.gz 100% 11MB 42.6MB/s 00:00
//node2
#安装java环境
[root@node2 ~]# yum -y install java-11-openjdk
#查看
[root@node2 ~]# ls
anaconda-ks.cfg apache-tomcat-9.0.46.tar.gz
#解压安装包
[root@node2 ~]# mkdir /usr/local/tomcat
[root@node2 ~]# tar xf apache-tomcat-9.0.46.tar.gz
[root@nide2 ~]# cp -r apache-tomcat-9.0.46/* /usr/local/tomcat/
[root@node2 ~]# ls /usr/local/tomcat/
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
安装和配置jenkins详情可以参考:jenkins安装和界面说明
选择推荐插件安装(这一步需要注意,其它步骤一致)
访问192.168.110.14:8080/jenkins
创建任务
输入任务名称test,选择流水线
配置test任务
流水线脚本内容
pipeline {
agent any
stages {
stage(‘pull code‘) {
steps {
git ‘http://github.com/lizhenliang/tomcat-java-demo.git‘
}
}
stage(‘package‘) {
steps {
sh """
mvn clean
mvn package
"""
}
}
stage(‘deploy‘) {
steps {
sh """
scp target/ly-simple-tomcat-0.0.1-SNAPSHOT.war root@192.168.110.13:/usr/local/tomcat/webapps/
ssh root@192.168.110.13 ‘/usr/local/tomcat/bin/shutdown.sh && /usr/local/tomcat/bin/startup.sh‘
"""
}
}
}
}
构建任务
构建成功
//node2
[root@node2 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 128 [::]:22 [::]:*
//项目文件
[root@node2 ~]# ls /usr/local/tomcat/webapps/
docs ly-simple-tomcat-0.0.1-SNAPSHOT ROOT
examples ly-simple-tomcat-0.0.1-SNAPSHOT.war
host-manager manager
原文:https://www.cnblogs.com/leixixi/p/14783564.html