GitLab是一個(gè)代碼倉庫年栓,用來管理代碼。Jenkins是一個(gè)自動(dòng)化服務(wù)器糜烹,可以運(yùn)行各種自動(dòng)化構(gòu)建违诗、測試或部署任務(wù)。所以這兩者結(jié)合起來疮蹦,就可以實(shí)現(xiàn)開發(fā)者提交代碼到GitLab诸迟,Jenkins以一定頻率自動(dòng)運(yùn)行測試、構(gòu)建和部署的任務(wù)愕乎,幫組開發(fā)團(tuán)隊(duì)更高效的集成和發(fā)布代碼阵苇。
下面是我最近安裝GitLab+Jenkins環(huán)境的一個(gè)過程,記錄下來妆毕,以備日后參考慎玖。
一、環(huán)境準(zhǔn)備
1笛粘、操作系統(tǒng)
[root@jenkins tmp]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@jenkins tmp]# uname -a
Linux jenkins 3.10.0-862.2.3.el7.x86_64 #1 SMP Wed May 9 18:05:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
安裝所需軟件
[root@jenkins src]#yum install patch git wget -y
gitlab版本:gitlab-ce-10.7.3-ce.0.el7.x86_64.rpm
jenkins版本:jenkins-2.122-1.1.noarch.rpm
二趁怔、安裝 Gitlab
1.下載鏡像:
[root@jenkins src]#wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.7.3-ce.0.el7.x86_64.rpm
2.安裝Gitlab
[root@jenkins src]#yum localinstall gitlab-ce-10.7.3-ce.0.el7.x86_64.rpm
[root@jenkins src]#yum install postfix
[root@jenkins src]#systemctl enable postfix
[root@jenkins src]#systemctl start postfix
3.修改配置文件gitlab.rb
GitLab默認(rèn)會(huì)占用80、8080和9090端口薪前,Jenkins默認(rèn)也會(huì)使用8080端口润努,所以,這一步操作將會(huì)修改GitLab的默認(rèn)端口為81示括、8081和9091铺浇,如果你還是希望使用默認(rèn)端口的話,可以跳過這一步垛膝。
1.將 external_url 'http://127.0.0.1' 改為 external_url 'http://<你的服務(wù)器地址或域名>:81'
2.將 # unicorn['port'] = 8080 改為 unicorn['port'] = 8081
3.將 #prometheus['listen_address'] = 'localhost:9090' 改為 prometheus['listen_address'] = 'localhost:9091'
配置文件如下:
[root@jenkins ~]# egrep -v "^#|^$" /etc/gitlab/gitlab.rb
external_url 'http://172.20.42.209:81'
unicorn['port'] = 8081
prometheus['listen_address'] = 'localhost:9091'
4.生效配置文件及啟動(dòng)Gitlab
使用reconfigure命令重新配置
[root@jenkins ~]#gitlab-ctl reconfigure
其他說明:
平時(shí)可使用如下命令關(guān)閉或啟動(dòng)gitlab
[root@jenkins ~]#gitlab-ctl start
[root@jenkins ~]#gitlab-ctl stop
GitLab安裝完畢鳍侣。
三丁稀、漢化Gitlab
停止gitlab
[root@jenkins ~]#gitlab-ctl stop
一、下載漢化包
查看版本
[root@jenkins src]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
10.7.3
下載gitlab版本對應(yīng)的漢化包:gitlab中文社區(qū)
[root@jenkins src]# git clone https://gitlab.com/xhang/gitlab.git -b v10.7.3-zh
[root@jenkins src]# ll -h
總用量 389M
drwxr-xr-x 29 root root 4.0K 5月 21 21:26 gitlab
-rw-r--r-- 1 root root 389M 5月 4 04:19 gitlab-ce-10.7.3-ce.0.el7.x86_64.rpm
[root@jenkins src]#cd gitlab
[root@jenkins gitlab]# cat VERSION
10.7.3
Git使用方法見:廖雪峰Git教程
二倚聚、更新漢化補(bǔ)丁
導(dǎo)出patch用的diff文件(patch使用方法)
[root@jenkins gitlab]#git diff v10.7.3 v10.7.3-zh > /tmp/v10.7.3-zh.diff
備份源文件:
[root@jenkins gitlab]#cp /opt/gitlab/embedded/service/gitlab-rails /opt/gitlab/embedded/service/gitlab-rails.bak.$(date +%F)
打漢化補(bǔ)断呱馈:
[root@jenkins gitlab]#patch -d /opt/gitlab/embedded/service/gitlab-rails/ -p1 < /tmp/v10.7.3-zh.diff
更新gitlab配置
[root@jenkins ~]#gitlab-ctl reconfigure
啟動(dòng)Gitlab
[root@jenkins gitlab]# gitlab-ctl start
ok: run: gitaly: (pid 24620) 1s
ok: run: gitlab-monitor: (pid 24631) 0s
ok: run: gitlab-workhorse: (pid 24642) 1s
ok: run: logrotate: (pid 24650) 0s
ok: run: nginx: (pid 24657) 1s
ok: run: node-exporter: (pid 24663) 0s
ok: run: postgres-exporter: (pid 24668) 0s
ok: run: postgresql: (pid 24675) 1s
ok: run: prometheus: (pid 24605) 10s
ok: run: redis: (pid 24758) 0s
ok: run: redis-exporter: (pid 24762) 1s
ok: run: sidekiq: (pid 24767) 0s
ok: run: unicorn: (pid 24774) 1s
[root@jenkins gitlab]# netstat -antlp | grep LISTEN
tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 25629/nginx: master
tcp 0 0 127.0.0.1:9121 0.0.0.0:* LISTEN 25740/redis_exporte
tcp 0 0 127.0.0.1:9091 0.0.0.0:* LISTEN 25727/prometheus
tcp 0 0 127.0.0.1:9187 0.0.0.0:* LISTEN 25677/postgres_expo
tcp 0 0 127.0.0.1:9100 0.0.0.0:* LISTEN 25635/node_exporter
tcp 0 0 127.0.0.1:9229 0.0.0.0:* LISTEN 25614/gitlab-workho
tcp 0 0 127.0.0.1:9168 0.0.0.0:* LISTEN 25602/ruby
tcp 0 0 127.0.0.1:8081 0.0.0.0:* LISTEN 25771/unicorn maste
tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 25629/nginx: master
tcp 0 0 127.0.0.1:8082 0.0.0.0:* LISTEN 25745/sidekiq 5.0.5
tcp 0 0 127.0.0.1:9236 0.0.0.0:* LISTEN 25591/gitaly
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1046/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1408/master
tcp6 0 0 ::1:9168 :::* LISTEN 25602/ruby
tcp6 0 0 :::8080 :::* LISTEN 28285/java
tcp6 0 0 :::22 :::* LISTEN 1046/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1408/master
四、訪問gitlab
瀏覽器訪問gitlab所在的ip:81
首次會(huì)要求設(shè)置root用戶的密碼
修改后就可以登錄系統(tǒng)了
五惑折、安裝及配置 jenkins
1授账、安裝JDK
[root@jenkins src]# yum install java-1.8.0 java-devel-1.8.0
[root@jenkins src]# java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-b10)
OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)
2、安裝jenkins
[root@jenkins src]#sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
[root@jenkins src]#sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
[root@jenkins src]# yum install jenkins -y
3惨驶、配置jenkins
啟動(dòng)jenkins
[root@jenkins src]# systemctl start jenkins
[root@jenkins src]# systemctl enable jenkins
[root@jenkins src]#[root@jenkins src]# netstat -antlp | grep java
tcp6 0 0 :::8080 :::* LISTEN 28285/java
tcp6 0 0 172.20.42.209:8080 10.10.0.6:57868 ESTABLISHED 28285/java
在瀏覽器打開 http://172.20.42.209:8080 訪問jenkins
首次訪問需要解鎖jenkins,把/var/lib/jenkins/secrets/initialAdminPassword文件內(nèi)容復(fù)制到administrator password下方即可白热。
[root@jenkins src]# cat /var/lib/jenkins/secrets/initialAdminPassword
xxxxxxxxxxxxxxxxxxxxxxxxxx
接著會(huì)提示安裝插件,可以選擇建議插件粗卜,也可以選擇自定義要安裝插件屋确,進(jìn)入jenkins后也可以進(jìn)行插件安裝的。這里可以先默認(rèn):
安裝完成后進(jìn)入主頁
4休建、安裝git乍恐、gitlab插件
用瀏覽器打開Jenkins,點(diǎn)擊“系統(tǒng)設(shè)置”-->“管理插件”测砂。
安裝以下插件:
Gitlab Plugin
安裝之后才可以在系統(tǒng)配置中指定gitlab的IP地址
Git Plugin
Git Client Plugin
用于jenkins在gitlab中拉取源碼
Publish Over SSH
用于通過ssh部署應(yīng)用
Maven Integration plugin
用于新建maven項(xiàng)目
勾選安裝完成后重啟jenkins 重啟Jenkins生效
參考
1.https://blog.csdn.net/xiegh2014/article/details/78802591
2.https://blog.csdn.net/chenhaifeng2016/article/details/78603216
3.https://blog.csdn.net/xiegh2014/article/details/78803342
4.https://blog.csdn.net/Linjingke32/article/details/77799878
5.http://www.reibang.com/p/q81RER