-
- 对三台服务器进行简单说明
- 192.168.211.11_Jenkins: Jenkins服务器
- 192.168.211.12_Web-test: 代码服务器--git本地仓库服务器,需要安装git,提交代码到远程仓库服务器
- 对三台服务器进行简单说明
1.1.3 192.168.211.13_Git:git远程仓库服务器,需要安装git,并初始化仓库
2.三服务器安装软件
2.1 192.168.211.13_Git:git远程仓库服务器,需要安装git,并
初始化仓库
2.1.1 安装Git
[root@localhost ~]# yum install git
2.1.2 创建Git用户并设置密码
[root@localhost ~]# yum install git
[root@localhost ~]# passwd git
密码为 91995那个qq邮箱号
2.1.3 创建仓库
[root@localhost ~]# su – git
[git@localhost root]$ mkdir -p /home/git/repos/app.git
[git@localhost app.git]$ cd /home/git/repos/app.git
[git@localhost app.git]$ git --bare init
2.2 192.168.211.12_Web-test: 代码服务器—本地仓库服务器,需要安装git,提交测试文件到仓库服务器
2.2.1 安装Git,
[root@localhost ~]# yum install git
2.2.2 设置提交的用户名和邮箱
当安装Git后首先要做的事情是设置用户名称和email地址。这是非常重要的,因为每次Git提交都会使用该用户信息 设置用户信息 git config --global user.name “itcast”git config --global user.email “hello@itcast.cn” 查看配置信息 git config --list git config user.name 通过上面的命令设置的信息会保存在~/.gitconfig文件中
[root@localhost /]# git config --global user.name "cailiao_xiangshuai"
[root@localhost /]# git config --global user.email "2409479353@qq.com"
2.2.3 创建代码提交测试目录
root@localhost ~]# mkdir /test
2.2.4 从远程仓库服务器仓库clone代码到本地git仓库
用远程仓库服务器用户git及其密码将远程仓库服务器clone到代码服务器(当然因为仓库服务器此时没有东西,所以clone下来的就是空的)
[root@localhost test]# git clone git@192.168.211.13:/home/git/repos/app.git
2.2.4 创建要提交git仓库的文件
[root@localhost app]# cd /test/app
[root@localhost app]# ps -ef > index.html
[root@localhost app]# ps –ef|grep usr > test.txt
2.2.5 将app目录下的文件都加到暂存区
[root@localhost app]# git add ./
2.2.6 git commit 将暂存区的文件提交到本地仓库
[root@localhost app]# rm –rf /test/app/test.txt
[root@localhost app]# cd /test/app
[root@localhost app]# git commit -m "提交测试文件到git仓库" index.html
2.2.7将代码推送到远程仓库192.168.211.13的master分支。 命令形式: git push [remote-name][branch-name]
[root@localhost app]# git push origin master
2.1
2.3 SSH免密登录设置-- 本地仓库(192.168.211.12_Web-test)免密登录拉取远程仓库(192.168.211.13_Git)设置
2.3.1 在192.168.211.12本地仓库服务器上生成密钥
# ssh-keygen
再查出生成的公钥
[root@localhost ~]# cat ~/.ssh/id_rsa.pub
2.3.2 将本地git服务器生产的公钥复制到远程git服务器中
[root@localhost ~]# grep AuthorizedKeysFile /etc/ssh/sshd_config
[root@localhost ~]# su – git
[git@localhost ~]$ mkdir .ssh
[git@localhost ~]$ chmod 700 .ssh/
[git@localhost ~]$ vi .ssh/authorized_keys
将刚才本地git服务器查出来的密钥copy到此文件下保存即可
然后再设置下.ssh/authorized_keys文件权限为600
[git@localhost ~]$ chmod 600 .ssh/authorized_keys
2.3.3 去本地git服务器再从远程git服务器拉取下代码试试,还要不要输入git用户密码
[root@localhost ~]# mkdir /test2
[root@localhost ~]# cd test2
[root@localhost test2]# git clone git@192.168.211.13:/home/git/repos/app.git
图如下已经不需要输密码了,且之前git push的index.html也已经有了
2.4 192.168.211.11_Jenkins服务器—Jenkins在linux环境下直接安装与使用
2.4.1 安装命令在官网上可以看到
打开网址https://pkg.jenkins.io/redhat-stable/,可看到安装命令
2.4.1 按如上命令安装
[root@localhost ~]# cd
[root@localhost ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
[root@localhost ~]# sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
[root@localhost ~]# yum install jenkins –y
如果报如下错,解决方案如下
[root@localhost ~]# yum update
[root@localhost ~]# yum install jenkins -y
rpm -ql 包名 查看一个包安装了哪些文件
[root@localhost ~]# rpm -ql jenkins
2.4.2 如果java –version有java环境,那么可以直接启动j
ekins,否则,需要先安装java环境
安装jdk可参照D:\E\学习文档子目录压缩\专项进阶,如ngnix,webservice,linux,redis等\liunx下的02-数字化审计二期系统_系统部署方案V1.0.0(1).doc文件安装,其中jdk文件在平台基础软件.zip中,可百度网盘搜
安装好执行如下命令启动jekins
[root@localhost etc]# java -version
[root@localhost etc]# systemctl start jenkins
[root@localhost etc]# ps -ef|grep jenkins
2.4.4 访问jenkins --http://192.168.211.11:8080
去如下文件中查到密码输入进去就可以了
[root@localhost etc]# cat /var/lib/jenkins/secrets/initialAdminPassword
2.4.6 密码输入后安装插件
选择插件来安装->点安装
密码 root+五位数
2.4.5 配置jdk,maven,配完后记得点保存
jdk配置
[root@localhost soft]# grep JAVA_HOME /etc/profile
maven配置--待安装
2.4.6 用户管理插件:Role-based Authorization Strategy
跳过了,没学
2.4.7 参数化构建插件:Extended Choice Parameter与Git Parameter
2.4.7.1 安装参数化构建插件
2.4.7.2 构建一个任务,用来测试参数化构建插件
2.4.7.2测试参数化构建插件
重启jenkins
[root@localhost ~]# systemctl restart jenkins
记得点保存
另外这个下拉框的值还可以直接指定为服务器的配置文件,如下图
在构建一下任务,如下图,已经变成了test1,test2,test3
2.4.8 参数化构建插件: Git Parameter
2.4.7.1 安装git
[root@localhost ~]# yum install git
2.4.7.2设置提交的用户名和邮箱
[root@localhost /]# git config --global user.name "jenkins_fuq"
[root@localhost /]# git config --global user.email "2409479353@qq.com"
2.4.7.3创建代码测试目录
[root@localhost ~]# mkdir /test
2.4.7.4 参考2.3 SSH免密登录设置—将192.168.211.11_Jenkins也设置成可以免密登录拉取远程仓库(192.168.211.13_Git)
2.4.7.5 从远程仓库服务器仓库clone代码到本地git仓库
用远程仓库服务器用户git及其密码将远程仓库服务器clone到代码服务器(当然因为仓库服务器此时没有东西,所以clone下来的就是空的)
[root@localhost ~]# cd /test
[root@localhost test]# git clone git@192.168.211.13:/home/git/repos/app.git
2.4.7.6 修改JENKINS_USER的值为root,然后重启jenkins,如图
[root@localhost test]# vi /etc/sysconfig/jenkins
重启jenkis
[root@localhost test]# systemctl restart jenkins
2.4.7.7 jenkis根据我们设置的git地址拉取代码
7
3. Master-Slave架构
要先在从部署节点192.168.211.12_Web-test上安装java环境,安装jdk可参照D:\E\学习文档子目录压缩\专项进阶,如ngnix,webservice,linux,redis等\liunx下的02-数字化审计二期系统_系统部署方案V1.0.0(1).doc文件安装,其中jdk文件在平台基础软件.zip中,可百度网盘搜
-
- 192.168.211.11_Jenkins主, 192.168.211.12_Web-test从
3.1.1 设置从节点信息-- slave1-192.168.211.12_Web-test
cd /var/lib/jenkins 看从节点有没有这个目录,没有创建一个
3.1.2 在主节点上设置部署从节点信息
主节点192.168.211.11_Jenkins,部署从节点192.168.211.12_Web-test
4.流水线(Pipeline)--之前插件安装时已安装
4.1 jenkins新建一个Pipeline任务pipeline-test1--helloworld1
4.2 jenkins新建一个Pipeline任务pipeline-test2--helloworld2
上图git的地址有误,改成如下远程仓库地址,再次保存
4.3 jenkins新建一个Pipeline任务pipeline-test3—helloworld3,流水线脚本直接从git仓库中文件获取
4.3.1 将4.2的脚本直接保存到192.168.211.12_Web-test 的/test/jenkinsfile1文件中,并git提交到 在远程服务器192.168.211.13_Git:git 创建 /home/git/repos/jenkinsfile/目录, 并初始化仓库git --bare init --记得远程仓库用git用户,然后将在192.168.211.12_Web-test的/test目录下将这个仓库clone下来,并在
4.3.1.1创建脚本存放目录--在192.168.211.13_Git:git远程仓库服务器下
[root@localhost /]# su - git
[git@localhost ~]$ mkdir -p /home/git/repos/jenkinsfile
初始化仓库
[git@localhost ~]$ cd /home/git/repos/jenkinsfile
[git@localhost jenkinsfile]$ git --bare init
4.3.1.2 在192.168.211.12_Web-test的/test目录下将远程仓库clone下来,将4.2的流水线脚本保存到/test/jenkinsfile/jenkinsfile1文件中,并push到远程仓库--在192.168.211.12_Web-test服务器中进行
[root@localhost test]# cd /test
[root@localhost test]# git clone git@192.168.211.13:/home/git/repos/jenkinsfile
[root@localhost test]# cd jenkinsfile/
将4.2的脚本直接保存到192.168.211.12_Web-test 的/test/jenkinsfile/jenkinsfile1文件中
将文件jenkinsfile1,push到远程仓库
[root@localhost jenkinsfile]# git config --global user.name "test1"
[root@localhost jenkinsfile]# git config --global user.email "test1@qq.com"
[root@localhost jenkinsfile]# cd /test/jenkinsfile
[root@localhost jenkinsfile]# git add ./
[root@localhost jenkinsfile]# git commit -m "将pipeline测试脚本1提交到git仓库" jenkinsfile1
[root@localhost jenkinsfile]# git push origin master
4.3.2 新建一个Pipeline任务pipeline-test3,并指定流水线脚本从git远程仓库中获取
流水线文件jenkinsfile1地址所在目录--git@192.168.211.13:/home/git/repos/jenkinsfile
5. 构建状态邮件通知--插件:Email Extension Plugin之前已安装,如下图
5.1 163邮箱设置看是否能够发送成功--试了不行就放弃了我用163和qq都试了
(上图是QQ邮箱如何开通SMTP服务)
6.Jenkins+Pipeline+Git+Maven(上)--192.168.211.13_Git:git远程仓库服务器作为测试服务器—没有成功,因为打不成war包
6.1 为6.3构建 Pipeline任务A-java-1做准备,并安装Git,Maven,Jdk等环境--192.168.211.13上用root用户,并修改Pipeline构建流水线脚本
6.1.2 安装配置jdk环境 --192.168.211.13_Git:git远程仓库服务器
安装jdk可参照D:\E\学习文档子目录压缩\专项进阶,如ngnix,webservice,linux,redis等\liunx下的02-数字化审计二期系统_系统部署方案V1.0.0(1).doc文件安装,其中jdk文件在平台基础软件.zip中,可百度网盘搜
6.1.3安装配置maven环境 --192.168.211.13_Git:git远程仓库服务器
[root@localhost etc]#cd /app/soft
###没有就创建
[root@localhost etc]# mkdir -p /app/soft
##将apache-maven-3.5.3-bin.tar.gz上传至/app/soft下,并解压
[root@localhost soft]# cd /app/soft/
[root@localhost soft]# ls
[root@localhost soft]# tar zxvf apache-maven-3.5.3-bin.tar.gz
###将解压好的apache-maven-3.5.3移动到/usr/local目录下,并改名为maven
[root@localhost soft]# mv /app/soft/apache-maven-3.5.3 /usr/local
[root@localhost soft]# cd /usr/local
root@localhost local]# mv apache-maven-3.5.3 maven
6.1.4安装配置tomcat环境 --192.168.211.13_Git:git远程仓库服务器
[root@localhost etc]# mkdir -p /app/soft
##将apache-tomcat-8.5.31.tar.gz上传至/app/soft下,并解压
[root@localhost soft]# cd /app/soft/
[root@localhost soft]# ls
[root@localhost soft]# tar zxvf apache-tomcat-8.5.31.tar.gz
###将解压好的apache-maven-3.5.3移动到/usr/local目录下,并改名为tomcat
[root@localhost soft]# mv /app/soft/apache-tomcat-8.5.31 /usr/local
[root@localhost soft]# cd /usr/local
[root@localhost local]# mv apache-tomcat-8.5.31 tomcat
[root@localhost tomcat]# cd tomcat/webapps/
[root@localhost webapps]# rm -rf ./*
[root@localhost webapps]# ls
6.2 修改 Pipeline构建流水线的脚本,并创建流水线任务,如下
6.2.1 修改流程式脚本jenkinsfile-java-solo文件--将此文件的信息等都改成git远程服务器192.168.211.13的信息,并push到远程仓库服务器 ---在192.168.211.12_Web-test服务器中进行
将此文件上传到192.168.211.12_Web-test的/test/jenkinsfile目录下,并push到远程服务器—
因为在4.3的时候已经clone到/test目录下了,所以这里就不能clone了,
[root@localhost jenkinsfile]# cd /test/jenkinsfile
[root@localhost jenkinsfile]# ls –a
Jenkinsfile-java-sole- push到远程仓库--在192.168.211.12_Web-test服务器中进行
[root@localhost jenkinsfile]# git pull orgin master
[root@localhost jenkinsfile]# ls –a
[root@localhost jenkinsfile]# git commit -m "git jenkinsfile-java-solo"
[root@localhost jenkinsfile]# git push origin master
6.2.2 从github上拉取一个solo博客java项目到192.168.211.12_Web-test服务器的/test下作为测试项目,并将这个项目push到我们自己的远程仓库
6.2.1.1在192.168.211.12_Web-test的/test目,录下将远程测试博客代码clone下来
从github上clone代码--在192.168.211.12_Web-test服务器中进行
[root@localhost test]# cd /test
[root@localhost test]# git clone https://github.com/88250/solo.git
6.2.1.2 在192.168.211.13git远程服务器中用git用户创建目录/home/git/repos/solo用来做我们6.2.1.1clone下来solo项目的远程仓库
[git@localhost repos]$ cd /home/git/repos
[git@localhost repos]$ mkdir solo
[git@localhost repos]$ cd solo
[git@localhost solo]$ git --bare init
[git@localhost solo]$ ls -a
6.2.1.3 将192.168.211.12_Web-test的/test/solo 目录下所有代码add,commit到本地仓库并push到192.168.211.13git远程服务器的/home/git/repos/solo目录下 -- 192.168.211.12_Web-test中进行
6.2.1.3.1 删除原来远程仓库—github上的
[root@localhost solo]# cd /test/solo
----- 查看现在的远程仓库
[root@localhost solo]# git remote -v
[root@localhost solo]# ls –a
----- 删除远程仓库origin
[root@localhost solo]# git remote rm origin
[root@localhost solo]# git remote -v
[root@localhost solo]# ls -a
6.2.1.3.2将192.168.211.13git远程服务器的/home/git/repos/solo设为本地solo的远程仓库地址---- 192.168.211.12_Web-test中进行
[root@localhost solo]# cd /test/solo
[root@localhost solo]# git remote –v
----- 添加远程仓库origin
[root@localhost solo]# git remote add origin git@192.168.211.13:/home/git/repos/solo
[root@localhost solo]# git remote –v
6.2.1.3.3 将sole这个项目push到我们自己的远程仓库--192.168.211.12_Web-test中进行
[root@localhost solo]# cd /test/solo
---重新初始化git仓库
[root@localhost solo]# git status
[root@localhost solo]# git init
[root@localhost solo]# git status
[root@localhost solo]# git add .
[root@localhost solo]# git status
[root@localhost solo]# git commit -m "all"
root@localhost solo]# git push origin master
6.3 192.168.211.11_Jenkins服务器主, 192.168.211.13_Git服务器从
3.1.1 设置从节点信息-- slave2-192.168.211.13_Git
cd /var/lib/jenkins 看192.168.211.13服务器从节点有没有这个目录,没有创建一个
然后点保存
3.1.2 ---
6.4 jenkins新建一个Pipeline任务A-java-1,并为其配置Git,Maven,Jdk等环境--192.168.211.13上用root用户,并用Pipeline构建流水线
6.3.1 jenkins新建一个Pipeline任务A-java-1
6.3.2 为这个任务指定流水线脚本
6.3.3 参考2.3SSH免密登录设置—为远程仓库root用户在远程仓库服务器设置公钥进去
[root@localhost jenkinsfile]# ssh-keygen
如果build报如下错
直接clone下
百度下后可以这样解决
[root@localhost test]# ssh -o StrictHostKeyChecking=no 192.168.211.13
root@192.168.211.13's password:
Last login: Mon Jul 12 18:22:57 2021 from 192.168.211.1
可以看到现在不用输密码了,那么就可以继续去build了
继续报错
百度下解决方案如下https://blog.csdn.net/weixin_45489155/article/details/106326704
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.211.2
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 223.5.5.5
nameserver 223.6.6.6
继续报错解压zip报错,如下
解决办法下个unzip
[root@localhost ~]# clear
[root@localhost ~]# yum install unzip –y
然后就去build