溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Jenkins+GitLab+Ansible playbook安裝與基本使用

發(fā)布時間:2020-04-10 17:00:02 來源:網(wǎng)絡(luò) 閱讀:692 作者:元嬰期 欄目:系統(tǒng)運(yùn)維

Jenkins+GitLab+Ansible playbook安裝與基本使用

GitLab

什么是GitLab?

GitLab是一個開源分布式版本控制系統(tǒng),開發(fā)語言為Ruby,功能為管理項(xiàng)目源代碼、版本控制、代碼復(fù)用與查找

GitLab與GitHub的不同

github分布式在線代碼托管倉庫,個人版本可直接在線免費(fèi)使用,企業(yè)版本收費(fèi)且需要服務(wù)器安裝
gitlab分布式在線代碼倉庫托管軟件,分社區(qū)免費(fèi)版本與企業(yè)收費(fèi)版本,都需要服務(wù)器安裝

GitLab的優(yōu)勢和應(yīng)用場景

? 開源免費(fèi),適合中小型公司將代碼放置在該系統(tǒng)中
? 差異化版本管理,離線同步y(tǒng)以及強(qiáng)大分支管理功能
? 便捷的GUI操作界面以及強(qiáng)大賬戶權(quán)限管理功能
? 集成度很高,能夠集成絕大多數(shù)的開發(fā)工具
? 支持內(nèi)置HA,保證在高并發(fā)下仍舊實(shí)現(xiàn)高可用性

GitLab主要服務(wù)構(gòu)成

1. Nginx靜態(tài)Web服務(wù)器
2. Gitlab-workhorse輕量級的反向代理服務(wù)器
3. Gitlab-shell用于處理git命令和修改authorized keys列表
4. Logrotate 日志文件管理工具
5. Postgresql 數(shù)據(jù)庫
6. Redis 緩存服務(wù)器

GitLab的工作流程

1. 創(chuàng)建并克隆項(xiàng)目
2. 創(chuàng)建項(xiàng)目某feature分支
3. 編寫代碼并提交至該分支
4. 推送該項(xiàng)目分支至遠(yuǎn)程gitlab服務(wù)器
5. 進(jìn)行代碼檢查并提交master主分支合并申請
6. 項(xiàng)目領(lǐng)導(dǎo)審查代碼并確認(rèn)合并申請

GitLab安裝配置管理

1. 安裝前配置

    a. 關(guān)閉防火墻
    b. 關(guān)閉SELINUX并重啟系統(tǒng)

2. 安裝Omnibus Gitlab-ce package

    a. 安裝gitlab依賴包
    yum -y install curl policycoreutils openssh-server openssh-clients postfix
    b. 配置yum倉庫
    wget http://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh 
    chmod +x script.rpm.sh
    ./script.rpm.sh
    c. 啟動postfix郵件服務(wù)
    systemctl start postfix
    d. 安裝gitlab-ce社區(qū)版本
    yum -y install gitlab-ce

3. 創(chuàng)建本地證書

生成私鑰(key文件):key是服務(wù)器上的私鑰文件,用于對發(fā)送給客戶端數(shù)據(jù)的加密,以及對從客戶端接收到數(shù)據(jù)的解密
openssl genrsa -out "/etc/gitlab/ssl/gitlab.example.com.key" 2048
生成csr文件:csr是證書簽名請求文件,用于提交給證書頒發(fā)機(jī)構(gòu)(CA)對證書簽名
openssl req -new -key "/etc/gitlab/ssl/gitlab.example.com.key" -out  "/etc/gitlab/ssl/gitlab.example.com.csr"
生成crt文件:crt是由證書頒發(fā)機(jī)構(gòu)(CA)簽名后的證書,或者是開發(fā)者自簽名的證書,包含證書持有人的信息,持有人的公鑰,以及簽署者的簽名等信息
openssl x509 -req -days 365 -in "/etc/gitlab/ssl/gitlab.example.com.csr" -signkey "/etc/gitlab/ssl/gitlab.example.com.key" -out "/etc/gitlab/ssl/gitlab.example.com.crt"

生成dh密鑰:openssl dhparam用于生成和管理dh的文件。dh(Diffie-Hellman)是著名的密鑰交換協(xié)議,或稱為密鑰協(xié)商協(xié)議,它可以保證通信雙方安全地交換密鑰。但注意,它不是加密算法,所以不提供加密功能,僅僅只是保護(hù)密鑰交換的過程。
openssl dhparam -out /etc/gitlab/ssl/dhparams.pem 2048

修改以上文件權(quán)限為600
chmod 600 /etc/gitlab/ssl/*

4. 配置加載證書

備份
cp gitlab.rb gitlab.rb.backup
修改
vim /etc/gitlab/gitlab.rb
external_url 'https://gitlab.example.com'
nginx['redirect_http_to_https'] = true
# nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
# nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
# nginx['ssl_dhparam'] = /etc/gitlab/ssl/dhparams.pem

5. gitlab初始化

gitlab-ctl reconfigure

6. 配置nginx

備份
cp /var/opt/gitlab/nginx/conf/gitlab-http.conf{,.backup} 
server區(qū)段添加
vim /var/opt/gitlab/nginx/conf/gitlab-http.conf 
rewrite ^(.*)$ https://$host$1 permanent;

7. 重新加載并啟動gitlab

gitlab-ctl restart

8. 客戶端添加一條dns記錄

在/etc/hosts中添加 192.168.143.130 gitlab.example.com

9. 客戶端通過瀏覽器訪問gitlab.example.com

默認(rèn)管理員root,為root設(shè)置密碼并登陸

Jenkins+GitLab+Ansible playbook安裝與基本使用
Jenkins+GitLab+Ansible playbook安裝與基本使用

GitLab基本使用

1、新建倉庫

Jenkins+GitLab+Ansible playbook安裝與基本使用
Jenkins+GitLab+Ansible playbook安裝與基本使用

2、在客戶端克隆倉庫到本地 -c http.sslVerify:跳過本地ssl檢查

git -c http.sslVerify=false  clone https://gitlab.example.com/root/test.git

3、輸入賬號密碼

[root@node1 devops]# git -c http.sslVerify=false  clone https://gitlab.example.com/root/test.git
Cloning into 'test'...
Username for 'https://gitlab.example.com': root
Password for 'https://root@gitlab.example.com': 
warning: You appear to have cloned an empty repository.

4、切換到test目錄,并創(chuàng)建測試文件

[root@node1 devops]# cd test/
[root@node1 test]# vim test.py

5、添加測試文件到本地倉庫

[root@node1 test]# git add .

6、配置全局郵件與用戶

[root@node1 test]# git config --global user.email "admin@example.com"
[root@node1 test]# git config --global user.name "jym"

7、提交測試文件到本地mast分支

[root@node1 test]# git commit -m "First commit"
[master (root-commit) b6581b9] First commit
 1 file changed, 3 insertions(+)
 create mode 100644 test.py

8、push本地master到倉庫

[root@node1 test]# git -c http.sslVerify=false push origin master

9、查看

Jenkins+GitLab+Ansible playbook安裝與基本使用

Ansible

模塊化,調(diào)用特定的模塊,完成特定的任務(wù);基于python語言研發(fā),由Paramiko、PyYAML和Jinja2三個關(guān)鍵模塊;部署簡單,主從模式,支持自定義模塊;支持playbook;冪等性

架構(gòu)圖

Jenkins+GitLab+Ansible playbook安裝與基本使用

Ansible安裝

1. 安裝前配置

關(guān)閉防火墻
關(guān)閉selinux
各節(jié)點(diǎn)時間同步
各節(jié)點(diǎn)主機(jī)名不一致
各節(jié)點(diǎn)間ssh免密

2. Ansible2.5+python3.6安裝步驟(centos7)

2.1、預(yù)先安裝python3.6

wget http://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
tar xf Python-3.6.5.tar.xz && cd Python-3.6.5/
./configure --prefix=/usr/local --with-ensurepip=install --enable-shared
 LDFLAGS="-wl , -rpath /usr/local/lib"
make && make altinstall

2.2、安裝virtualenv

pip3.6 install virtualenv

2.3、創(chuàng)建ansible用戶并安裝python3.6版本virtualenv實(shí)例

useradd deploy && su - deploy
virtualenv -p python3.6 .py3-a2.10-env

2.4、Git源代碼安裝ansible2.10

cd /home/deploy/.py3-a2.10-env
git clone https://github.com/ansible/ansible.git
cd ansible && git checkout stable-2.10

2.5、加載python3.6 virtualenv環(huán)境

source /home/deploy/.py3-a2.10-env/bin/activate

2.6、安裝ansible依賴包

pip3.6 install paramiko PyYAML jinja2

2.7、在python3.6虛擬環(huán)境下加載ansible2.10

source /home/deploy/.py3-a2.10-env/ansible/hacking/env-setup -q

2.8、驗(yàn)證ansible2.5安裝

ansible --version

Jenkins

Jenkins簡介

Jenkins是一款開源 CI&CD 軟件,用于自動化各種任務(wù),包括構(gòu)建、測試和部署軟件。
Jenkins 支持各種運(yùn)行方式,可通過系統(tǒng)包、Docker 或者通過一個獨(dú)立的 Java 程序方式部署。
Jenkins 是一個主流的運(yùn)維開發(fā)平臺,兼容所有主流開發(fā)環(huán)境;通過插件可與海量業(yè)內(nèi)主流開發(fā)工具實(shí)現(xiàn)集成;通過job配置單位與日志管理,使開發(fā)與運(yùn)維人員能協(xié)同工作;通過權(quán)限管理劃分不同job不同角色;強(qiáng)大的負(fù)載均衡功能,保證項(xiàng)目的可靠性。

Jenkins安裝

1、安裝java8.0或8.0以上版本

yum install java

2、安裝docker

yum install docker-ce

3、安裝jenkins

下載地址:https://pkg.jenkins.io/redhat-stable/
yum install jenkins-2.199-1.1.noarch.rpm

4、啟動jenkins

systemctl start jenkins

查看啟動情況

systemctl status jenkins.service -l

5、初次訪問解鎖jenkins

瀏覽器訪問jenkins地址 http:<ip或域名>:8080
第一次訪問新的jenkins實(shí)例時,系統(tǒng)要求使用自動生成的密碼進(jìn)行解鎖
Jenkins+GitLab+Ansible playbook安裝與基本使用
查看初始密碼
[root@node1 jenkins]# cat /var/lib/jenkins/secrets/initialAdminPassword
acd7e8eef641433b87e3358d8d6d1e34

6、安裝插件

Jenkins+GitLab+Ansible playbook安裝與基本使用
兩個選項(xiàng)可以設(shè)置:
? 安裝建議的插件 - 安裝推薦的一組插件,這些插件基于最常見的用例.
? 選擇要安裝的插件 - 選擇安裝的插件集。當(dāng)你第一次訪問插件選擇頁面時,默認(rèn)選擇建議的插件。
Note:可以通過Jenkins中的Manage Jenkins > Manage Plugins 頁面在稍后的時間點(diǎn)安裝(或刪除)其他Jenkins插件

7、創(chuàng)建管理員用戶

Jenkins+GitLab+Ansible playbook安裝與基本使用
Jenkins+GitLab+Ansible playbook安裝與基本使用

參考文章:
https://jenkins.io/zh/
https://www.bilibili.com/video/av71123251/?p=1

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI