0x0、安装所需要依赖的环境Java-jdk
安装Jenkins需要有java环境,请先安装并配置好jdk。安装之前必须保证环境中有jdk。最好是高于1.8版本的!否则会报错。
#查看系统中是否安装了Java包
[root@gitlab home]# rpm -qa | grep java
[root@gitlab home]# yum list java*
[root@gitlab home]# yum --showduplicate list java* | grep 1.8.0
ava-1.8.0-openjdk.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-accessibility.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-accessibility.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-accessibility.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-accessibility-debug.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-accessibility-debug.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-accessibility-debug.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-accessibility-debug.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-accessibility-debug.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-accessibility-debug.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-debug.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-debug.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-debug.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-demo.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-demo.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-demo.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-demo-debug.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-demo-debug.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-demo-debug.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-devel.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-devel-debug.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-devel-debug.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-devel-debug.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-headless.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-headless-debug.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-headless-debug.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-headless-debug.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-javadoc-zip-debug.noarch 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-javadoc-zip-debug.noarch 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-javadoc-zip-debug.noarch 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-src.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-src.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-src.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-src.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-src-debug.i686 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.222.b03-1.el7 base
java-1.8.0-openjdk-src-debug.i686 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.222.b10-1.el7_7 updates
java-1.8.0-openjdk-src-debug.i686 1:1.8.0.232.b09-0.el7_7 updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.232.b09-0.el7_7 updates
开始安装Java jdk
[root@gitlab home]# yum install -y java-1.8.0-openjdk.x86_64
[root@gitlab home]# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
0x1 yum安装Jenkins
Step1 下载依赖
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
Step2 导入秘钥
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Step3. 安装
yum install -y jenkins
如果网速不给力用清华源安装(下面这一行)
#yum install -y https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.219-1.1.noarch.rpm
[root@gitlab home]# yum install -y jenkins
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.neusoft.edu.cn
* extras: mirrors.neusoft.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
jenkins | 2.9 kB 00:00:00
jenkins/primary_db | 30 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package jenkins.noarch 0:2.204.1-1.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================
Installing:
jenkins noarch 2.204.1-1.1 jenkins 60 M
Transaction Summary
==========================================================================================================================
Install 1 Package
Total download size: 60 M
Installed size: 61 M
Downloading packages:
^Cnkins-2.204.1-1.1.noarch.rpm 5% [== ] 12 kB/s | 3.6 MB 01:17:46 ETA
Exiting on user cancel
[root@gitlab home]# vim /etc/profiel
[root@gitlab home]# vim /etc/profie
[root@gitlab home]# vim /etc/profile
[root@gitlab home]# source /etc/profile
[root@gitlab home]# yum install -y jenkins
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.neusoft.edu.cn
* extras: mirrors.neusoft.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
runner_gitlab-ci-multi-runner/x86_64/signature | 836 B 00:00:00
runner_gitlab-ci-multi-runner/x86_64/signature | 1.0 kB 00:00:00 !!!
runner_gitlab-ci-multi-runner-source/signature | 836 B 00:00:00
runner_gitlab-ci-multi-runner-source/signature | 951 B 00:00:00 !!!
Resolving Dependencies
--> Running transaction check
---> Package jenkins.noarch 0:2.204.1-1.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================
Installing:
jenkins noarch 2.204.1-1.1 jenkins 60 M
Transaction Summary
==========================================================================================================================
Install 1 Package
Total download size: 60 M
Installed size: 61 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
jenkins-2.204.1-1.1.noarch.rpm | 60 MB 00:03:24
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : jenkins-2.204.1-1.1.noarch 1/1
Verifying : jenkins-2.204.1-1.1.noarch 1/1
Installed:
jenkins.noarch 0:2.204.1-1.1
Complete!
0x2 简单配置
- 查看安装目录信息
[root@gitlab home]# 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
/var/lib/jenkins
/var/log/jenkins
- jenkins相关目录释义:
1. /usr/lib/jenkins/:jenkins安装目录,war包会放在这里。
2. /etc/sysconfig/jenkins:jenkins配置文件,“端口”,“JENKINS_HOME”等都可以在这里配置。
3. /var/lib/jenkins/:默认的JENKINS_HOME。
4. /var/log/jenkins/jenkins.log:jenkins日志文件。
- 修改jenkins端口号,默认8080容易冲突
vi /etc/sysconfig/jenkins
默认端口号是8080,为了防止端口冲突,我们需要修改端口号。此处我修改为9099
- 设置开机自启动
[root@gitlab home]# systemctl restartjenkins
[root@gitlab home]# systemctl status jenkins
● jenkins.service - LSB: Jenkins Automation Server
Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
Active: active (exited) since Sat 2020-01-18 23:25:24 EST; 3min 41s ago
Docs: man:systemd-sysv-generator(8)
Process: 20244 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
Jan 18 23:25:23 gitlab systemd[1]: Starting LSB: Jenkins Automation Server...
Jan 18 23:25:23 gitlab runuser[20249]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Jan 18 23:25:24 gitlab jenkins[20244]: Starting Jenkins [ OK ]
Jan 18 23:25:24 gitlab systemd[1]: Started LSB: Jenkins Automation Server.
[root@gitlab home]# systemctl enable jenkins
jenkins.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig jenkins on
- 启动jenkins并配置防火墙
[root@gitlab home]# firewall-cmd --zone=public --add-port=9099/tcp --permanent
success
[root@gitlab home]# firewall-cmd --reload
success
firewall-cmd --reload
firewall-cmd --list-all
5.浏览器输入http://10.0.0.158:9099
【注意】这里登陆密码[root@gitlab updates]# cat /var/lib/jenkins/secrets/initialAdminPassword
显示的信息就是登陆密码
-
安装推荐插件
-
等待安装即可
【注意】这个过程可能会很慢,时间会比较长。我们可以使用国内源进行插件的加速。
[root@gitlab updates]# pwd
/var/lib/jenkins/updates
#执行命令替换源中的内容
[root@gitlab updates]# sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
#替换完毕重新jenkins
[root@gitlab updates]# systemctl restart jenkins
#这时候安装插件是不是瞬间进度条跑满