gitlab和jenkins
阿新 • • 發佈:2018-12-28
[root@server1 ~]# yum install -y policycoreutils-python openssh-server
[root@server1 ~]# yum install -y net-tools
2.啟動postfix 和sshd 服務
[root@server1 ~]# systemctl start sshd
[root@server1 ~]# systemctl start postfix
3.安裝gitlab
[root@server1 ~]# rpm -ivh gitlab-ce-11.2.0-ce.0.el7.x86_64.rpm
4.配置GitLab
[root@server1 ~]# vim /etc/gitlab/gitlab.rb
5.重置並啟動操作
[root@server1 ~]# gitlab-ctl reconfigure
[root@server1 ~]# gitlab-ctl restart #重啟
訪問Gitab頁面輸入:http://172.25.40.11
建立專案
新增公鑰
[root@foundation40 ~]# cd .ssh
[root@foundation40 .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
[root@foundation40 .ssh]# cat id_rsa.pub
[root@foundation40 ~]# git clone [email protected]:root/demo.git
搭建Jenkins
1.安裝JDK
[root@server1 ~]# rpm -ivh jdk-8u171-linux-x64.rpm
2.安裝jenkins
[root@server2 ~]# rpm -ivh jenkins-2.121.3-1.1.noarch.rpm
3.開啟jenkins,檢視埠
[root@server2 ~]# /etc/init.d/jenkins start
[root@server2 ~]# netstat -antlp |grep :8080
tcp6 0 0 :::8080 :::* LISTEN 2213/java
4.設定網路(讓虛擬機器聯網)
在物理機上新增網段
[root@foundation40 ~]# iptables -t nat -I POSTROUTING -s 172.25.40.0/24 -j MASQUERADE
[root@server2 ~]# route add default gw 172.25.40.250
[root@server2 ~]# vim /etc/resolv.conf
nameserver 114.114.114.114
[root@server2 ~]# ping baidu.com
#ping一下百度,看網通不通
5.獲得解鎖 Jenkins密碼
[root@server2 ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
372f6c9313f3472db55f19c81f85252a
將密碼複製到網頁,解鎖Jenkins
整合
檢視私鑰
[root@server2 ~]# yun install -y git
[root@foundation40 ~]# cd .ssh
[root@foundation40 .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
[root@foundation40 .ssh]# cat id_rsa
測試:
[root@foundation40 .ssh]# cd
[root@foundation40 ~]# cd demo/
[root@foundation40 demo]# ls
README.md
[root@foundation40 demo]# vim test.txt
[root@foundation40 demo]# cat test.txt
hello world
[root@foundation40 demo]# git add test.txt
[root@foundation40 demo]# git commit -m "add test.txt"
[root@foundation40 demo]# git push origin master
在jenkins下載外掛
在Jenkins
在gitlab
生成token
修改gitlab引數
[[email protected] ~]# curl -X PUT --header "PRIVATE-TOKEN:Gkji7zJ_AxbZYxU6CQ_G" 'http://172.25.40.11/api/v4/application/settings?allow_local_requests_from_hooks_and_services=true'
在gitlab上
[root@foundation40 demo]# vim hello.txt
[root@foundation40 demo]# cat hello.txt
hello world
hello world
[root@foundation40 demo]# git add hello.txt
[root@foundation40 demo]# git status -s
A hello.txt
[root@foundation40 demo]# git commit -m "add hello.txt"
[root@foundation40 demo]# git push origin master