10.安装使用jenkins及其插件
持续集成
1.安装jenkins
安装依赖
[root@jenkins ~]# yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel
用测试好的版本安装:
用rz上传rpm包
[root@jenkins ~]# rpm -ivh jenkins-2.32.3-1.1.noarch.rpm
最终还是升级到了164的版本
rpm包下载:此方式构建时卡住了,目前没有找到解决方法
https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/
wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.164.2-1.1.noarch.rpm
[root@jenkins ~]# rpm -ivh jenkins-2.164.2-1.1.noarch.rpm
共用
[root@jenkins ~]# systemctl status jenkins
[root@jenkins ~]# systemctl start jenkins
[root@jenkins ~]# systemctl enable jenkins
[root@jenkins ~]# netstat -lunpt |grep 8080
[root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
05aaa47a42f64fd2813bcd3de090cb3e
修改文件权限:
chown -R jenkins.jenkins /var/lib/jenkins/
注2019-05-06:由于不熟悉我选择推荐安装插件,之前测试过一次没有成功
在线安装插件:
plugins 用于拉取代码
在线安装
ssh
gitlab
离线安装插件:
下载好插件后解压到目录
cd /var/lib/jenkins/
tar -xvf plugins.tar.gz
对应的版本插件下载
http://updates.jenkins-ci.org/2.164/latest/
查看rpm程序目录:
rpm -ql jenkins
[root@jenkins ~]# rpm -ql jenkins
/etc/init.d/jenkins
/etc/logrotate.d/jenkins
/etc/sysconfig/jenkins
/usr/lib/jenkins
/usr/lib/jenkins/jenkins.war #程序包
/usr/sbin/rcjenkins
/var/cache/jenkins #war包解压程序存放,
/var/lib/jenkins #升级的时候直接把war包放此目录,解压后自动到cache
/var/log/jenkins
配置cmdb权限
vim /etc/sysconfig/jenkins
JENKINS_USER="jenkins"
JENKINS_USER="root"
[root@onecloud ~]# systemctl restart jenkins
jenkins控制root权限
[root@jenkins ~]# ps -ef|grep jenkins
root 7994 1 42 09:52 ? 00:00:15 /etc/alternatives/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
root 8085 7892 0 09:53 pts/0 00:00:00 grep --color=auto jenkins
备份:
tar scvf jenkins.tar.gz /var/lib/jenkins/
作业:写一个每天定时备份的脚本,保留15天备份
测试jenkins集成:
mkdir -p test/oldboy
echo "index" >index.html
echo 'a' >a.txt
echo 'b' >b.txt
[root@git oldboy]# ls
a.txt b.txt index.html
[root@git oldboy]# ll
total 12
-rw-r--r-- 1 root root 2 Apr 25 10:49 a.txt
-rw-r--r-- 1 root root 2 Apr 25 10:49 b.txt
-rw-r--r-- 1 root root 6 Apr 25 10:49 index.html
[root@git oldboy]# git add index.html
[root@git oldboy]# git commit -m "first"
[master (root-commit) 9411be5] first
1 file changed, 1 insertion(+)
create mode 100644 index.html
[root@git oldboy]# date
Thu Apr 25 10:50:45 CST 2019
[root@git oldboy]# git add a.txt
[root@git oldboy]# git commit -m "a"
[master 7c94d99] a
1 file changed, 1 insertion(+)
create mode 100644 a.txt
[root@git oldboy]# git add b.txt
[root@git oldboy]# git commit -m "b"
[master 231c3dd] b
1 file changed, 1 insertion(+)
create mode 100644 b.txt
[root@git oldboy]# git log
commit 231c3ddd2cfa0c1a1c3168dc6ae1a274477da18f
Author: Eric-xgc <741017474@qq.com>
Date: Thu Apr 25 10:51:29 2019 +0800
b
commit 7c94d99cd99376c1dfe0d09dc31aea541e5c7d52
Author: Eric-xgc <741017474@qq.com>
Date: Thu Apr 25 10:51:16 2019 +0800
a
commit 9411be51fdf533e949587642c2873d47b6683df1
Author: Eric-xgc <741017474@qq.com>
Date: Thu Apr 25 10:50:30 2019 +0800
first
以上在本地已经有3次提交:
创建分支并切换到分支:
[root@git oldboy]# git checkout -b testing
Switched to a new branch 'testing'
[root@git oldboy]# git status
On branch testing
nothing to commit, working tree clean
echo 'test1' >test1.txt
echo 'test2' >test2.txt
切换到主分支:
[root@git oldboy]# git checkout master
Switched to branch 'master'
echo 'master1' >master1.txt
echo 'master2' >master2.txt
合并分支merge:
将testing分支merge到master分支保留原分支
[root@git oldboy]# git merge testing
保存直接退出:wq
git log
会加大多一个提交
[root@git oldboy]# git branch
* master
testing
合并分支rebase:
将testing分支merge到master分支不保留原分支,细节丢失,去掉原分支
git rebase testing
升级jenkins:
停止服务:systemctl stop jenkins
在这个目录 : /usr/lib/jenkins
rpm -ql jenkins
下载更新war包
wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/war/2.176/jenkins.war
cd /usr/lib/jenkins/
mv jenkins.war jenkins-2.164.2.war.bak
mv /root/jenkins.war
备份原来的包:mv 旧的 旧的.bak
上传新的包:
启动服务:systemctl start jenkins
ss -anltup | grep 8080
netstat -lunpt|grep 8080
配置git clone拉取代码:
1.[root@jenkins ~]# ssh-keygen
2.一路回车
3.拷贝公钥到对应gitlab用户如下图
[root@jenkins ~]# cd .ssh/
[root@jenkins .ssh]# ls
id_rsa id_rsa.pub
[root@jenkins .ssh]# cat id_rsa.pub
4.必须在本地手动拉取一次代码用作测试最后OK
[root@jenkins test]# git clone git@192.168.50.184:java/app1.git
yes
5.立即构建成功非常奇怪之前很多次都是卡构建的位置,很开心能够通过构建,阻碍了我一个多月,
总结:
清华镜像的rpm包构建的一直报错,用版本32的rpm包安装后升级到164,中还升级到46过,然后之前卡构建的问题OK了,
个人觉得升级到164版本会稳定一点,测试通过很开心
免密配置:
[root@git ~]# vim /root/.ssh/authorized_keys
[root@git .ssh]# chmod 600 authorized_keys
将需要免密拉取代码的公钥复制到次文件
[root@jenkins .ssh]# ssh 192.168.50.184
重装jenkins (重装过很多次)
[root@jenkins ~]# systemctl stop jenkins
yum clean all //清理yum缓存,不执行也可以重新安装
yum -y remove jenkins
rm -rf /var/cache/jenkins
rm -rf /var/lib/jenkins/
远程发布构建:
rsync -raz --delete --progress * root@192.168.50.184:/data/www/php-deploy/
测试脚本:
[root@git php-deploy]# cd /data/www/php-deploy
[root@git php-deploy]# rm -rf *
[root@jenkins php-deploy]# cd /var/lib/jenkins/workspace/php-deploy
[root@jenkins php-deploy]# rm -rf *
使用脚本构建成功:
构建maven项目:20190530
安装插件:Maven Integration
下载maven:http://maven.apache.org/download.cgi
解压:[root@jenkins data]# tar -zxvf apache-maven-3.6.1-bin.tar.gz
重命名:[root@jenkins data]# mv apache-maven-3.6.1 apache-maven
配置maven系统环境:[root@jenkins data]# vim /etc/profile
MAVEN_HOME=/data/apache-maven
export MAVEN_HOME
export PATH=${PATH}:${MAVEN_HOME}/bin
[root@jenkins data]# source /etc/profile
[root@jenkins data]# pwd
/data
使用mvn -v 查看
[root@jenkins data]# mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /data/apache-maven
Java version: 1.8.0_212, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"
给jinkens配置maven
系统管理==》全局工具配置
在gitlab里面创建java/testweb项目:
将maven项目传到gitlab
cd /root/test/
git add .
git status
git commit -m "v1.0"
git config --global user.email "guocheng.xie@honortone.com"
git config --global user.name "xieguocheng"
git commit -m "v1.0"
git remote -v
git push origin master
学习测试构建java项目:2019-05-20开始
我有一个想法,想维护一套分布式系统的源代码,还是要把java捡起来,java比较强大。