DevOps(英文Development(開發)和Operations(技術運營)的組合)是一組過程、方法與系統的統稱,用於促進開發(應用程序/軟件工程)、技術運營和質量保障(QA)部門之間的溝通、協作與整合。它的出現是由於軟件行業日益清晰地認識到:爲了按時交付軟件產品和服務,開發和運營工作必須緊密合作
持續集成概念:
持續集成Continuous Integration 持續交付Continuous Delivery 持續部署Continuous Deployment
1.1 什麼是持續集成:
持續集成是指開發者在代碼的開發過程中,可以頻繁的將代碼部署集成到主幹,並進程自動化測試
1.3 什麼是持續交付:
持續交付指的是在持續集成的環境基礎之上,將代碼部署到預生產環境
1.4 持續部署:
在持續交付的基礎上,把部署到生產環境的過程自動化,持續部署和持續交付的區別就是最終部署到生產環境是自動化的。
1.5 部署代碼上線流程
1.代碼獲取(直接了拉取) 2.編譯 (可選) 3.配置文件放進去 4.打包 5.scp到目標服務器 6.將目標服務器移除集羣 7.解壓並放置到Webroot 8.Scp 差異文件 9.重啓 (可選) 10.測試 11.加入集羣
運維必知OWASP
Jenkins上OWASP 插件介紹: 它是開放式Web應用程序安全項目
[OWASP,Open Web Application Secunity Project
]
它每年會出一個top10的安全漏洞,我們需要知道當前top10的漏洞有哪些
https://www.owasp.org/images/5/57/OWASP_Proactive_Controls_2.pdf
https://www.owasp.org/index.php/Top_10_2013-Top_10
Gitlab介紹
GitLab是一個利用 Ruby on Rails
開發的開源應用程序,實現一個自託管的Git項目倉庫,可通過Web界面進行訪問公開的或者私人項目。
GitLab擁有與Github類似的功能,能夠瀏覽源代碼,管理缺陷和註釋。可以管理團隊對倉庫的訪問,它非常易於瀏覽提交過的版本並提供一個文件歷史庫。它還提供一個代碼片段收集功能可以輕鬆實現代碼複用,便於日後有需要的時候進行查找。
環境準備
[root@linux-node1 ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@linux-node1 ~]# uname -r 3.10.0-514.2.2.el7.x86_64
下載epel源
[root@linux-node1 ~]# wget http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm [root@linux-node1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
關閉 NetworkManager 和防火牆 [root@linux-node1 ~]#systemctl stop firewalld.service systemctl disable firewalld systemctl disable NetworkManager
關閉SELinux並確認處於關閉狀態 sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config grep SELINUX=disabled /etc/selinux/config setenforce 0
更新系統並重啓
[root@linux-node1 ~]# yum update -y && reboot
我們一共有2臺:192.168.56.11
和192.168.56.12
我們安裝在192.168.56.11上
[root@linux-node1 /]# yum install curl policycoreutils openssh-server openssh-clients postfix -y [root@linux-node1 /]# systemctl start postfix [root@linux-node1 /]# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash [root@linux-node1 /]# yum install -y gitlab-ce
#由於網絡問題,國內用戶,建議使用清華大學的鏡像源進行安裝
[root@linux-node1 ~]# cat /etc/yum.repos.d/gitlab-ce.repo [gitlab-ce] name=gitlab-ce baseurl= repo_gpgcheck=0 gpgcheck=0 enabled=1 gpgkey= [root@linux-node1 ~]# yum makecache [root@linux-node1 /]# yum install -y gitlab-ce
在安裝一個git客戶端
[root@linux-node1 /]# yum install -y git
配置並啓動gitlab-ce
[root@linux-node1 ~]# gitlab-ctl reconfigure #時間可能比較長,耐心你等待即可!---- gitlab常用命令: 關閉gitlab:[root@linux-node2 ~]# gitlab-ctl stop 啓動gitlab:[root@linux-node2 ~]# gitlab-ctl start 重啓gitlab:[root@linux-node2 ~]# gitlab-ctl restart
可以使用gitlab-ctl
管理gitlab,例如查看gitlab狀態:
[root@linux-node1 /]# gitlab-ctl status run: gitlab-workhorse: (pid 7437) 324s; run: log: (pid 7436) 324s run: logrotate: (pid 7452) 316s; run: log: (pid 7451) 316s run: nginx: (pid 8168) 2s; run: log: (pid 7442) 318s run: postgresql: (pid 7293) 363s; run: log: (pid 7292) 363s run: redis: (pid 7210) 369s; run: log: (pid 7209) 369s run: sidekiq: (pid 7479) 265s; run: log: (pid 7426) 326s run: unicorn: (pid 7396) 327s; run: log: (pid 7395) 327s
提示: 我們要保證80
端口不被佔用
我們可以查看一下端口
[root@linux-node1 /]# gitlab-ctl restart ok: run: gitlab-workhorse: (pid 8353) 0s ok: run: logrotate: (pid 8360) 1s ok: run: nginx: (pid 8367) 0s timeout: down: postgresql: 0s, normally up, want up ok: run: redis: (pid 8437) 0s ok: run: sidekiq: (pid 8445) 0s ok: run: unicorn: (pid 8450) 0s [root@linux-node1 /]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 8367 root 7u IPv4 54972 0t0 TCP *:http (LISTEN) nginx 8368 gitlab-www 7u IPv4 54972 0t0 TCP *:http (LISTEN)
提示:啓動gitlab需要時間!
Web
頁面提示我們需要設置一個賬號密碼(我們要設置最少8
位數的一個賬號密碼)我們設置密碼爲:12345678
第一步:我們關閉自動註冊,因爲我們內部使用不需要用戶自己註冊,由運維分配用戶即可
提示:Save
在頁面最下放!!!!!! 記得點保存!!!!!!!!!!!!
現在在查看首頁就沒有註冊頁面了
第二步:我們創建一個用戶,在創建一個項目
**提示:**gitlab上面有一個項目跟組的概念,我們要創建一個組,纔可以在創建一個項目。因爲gitlab的路徑上首先是ip地址,其次是組
點擊下方Create group
然後我們在組裏面創建項目
創建完成之後它提示我們可以創建一個key對它進行管理
我們點擊上面的README
然後我們隨便在裏面寫點東西
填寫完成我們點擊前面進行查看
我們要做免密驗證,現在去192.168.56.11複製下面的.ssh/id_rsa.pub
[www@linux-node1 ~]$ cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8wfTSQcSyhlsGYDSUtuxZNb1Gl3VU56nAPuxAEF2wP2ZW Z2yva354ZdKOOb6rZx2yZxqy5XIj7opBJPbhraXap+NtCH5qWyktR7dH19RBmCS7vUGgvk/5RQC0mVFrC8cz tBp0M/5HxMuhVir6mD1rhbDvvaLL6S5y4gljzC1Gr2VRHIb4Et9go/38c2tqMjYCike7WWbFRyL9wTal6/14 6+9uREZ/r69TBTKrGuRqF44fROQP8/ly02XFjlXyl6J5NnGTk6AU855pwasX0W9aNPce3Ynrpe1TBTubmfQh rH1BwteEmg+ZXNRupxjumA+tPWfBUX+u51r/w7W/d4PD www@linux-node1#提示:需要提前做祕鑰認證
添加完之後我們就可以使用www用戶,就可以拉了
點擊Projects 選擇SSH
,我們要將代碼拉去下來
[www@linux-node1 ~]$ cd /deploy/code/ [www@linux-node1 code]$ ls web-demo [www@linux-node1 code]$ rm -rf web-demo/ [www@linux-node1 ~]$ git clone git@linux-node1:web/web-demo.git Cloning into 'web-demo'... The authenticity of host 'linux-node1 (192.168.56.11)' can't be established. ECDSA key fingerprint is b5:74:8f:f1:03:2d:cb:7d:01:28:30:12:34:9c:35:8c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'linux-node1' (ECDSA) to the list of known hosts. remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. [www@linux-node1 ~]$ ls web-demo/ README.md #git clone是克隆的意思
我們來模擬開發繼續寫代碼提交
[www@linux-node1 ~]$ mkdir -p /web-demo [www@linux-node1 ~]$ vim web-demo/index.html [www@linux-node1 ~]$ cd web-demo/ [www@linux-node1 web-demo]$ [www@linux-node1 web-demo]$ ls index.html README.md [www@linux-node1 web-demo]$ git add * [www@linux-node1 web-demo]$ git commit -m "add index.html" *** Please tell me who you are. Run git config --global user.email "[email protected]" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: empty ident name (for <www@linux-node1.(none)>) not allowed
需要身份驗證:
[www@linux-node1 web-demo]$ git config --global user.email "[email protected]" [www@linux-node1 web-demo]$ git config --global user.name "Your Name" [www@linux-node1 web-demo]$ git commit -m "add index.html" [master be8a547] add index.html 1 file changed, 169 insertions(+) create mode 100644 index.html
git push命令用於將本地分支的更新,推送到遠程主機。它的格式與git pull命令相仿。
[www@linux-node1 web-demo]$ git push warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 7.66 KiB | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@linux-node1:web/web-demo.git 0c1d357..be8a547 master -> master
我們的gitlab
安裝在opt/gitlab
gitlab配置文件存放在etc/gitlab/gitlab.rb
#現在git 需要加上主機名,我們可以修改配置文件,讓它使用IP進行訪問
編輯配置文件
[root@linux-node1 ~]# vim /etc/gitlab/gitlab.rb external_url ' [root@linux-node1 ~]# gitlab-ctl reconfigure #提示:修改完需要從新配置纔會生效
我們從新登陸進行查看
咦! 爲啥還沒改呢! 我們從新創建一個項目在試一下
友情提示:
關於Git可以查看徐布斯博客 or 廖雪峯Git
自動化運維之DevOps
DevOps(英文Development(開發
)和Operations(技術運營
)的組合)是一組過程、方法與系統的統稱,用於促進開發(應用程序/軟件工程)、技術運營和質量保障(QA)部門之間的溝通、協作與整合。
它的出現是由於軟件行業日益清晰地認識到:爲了按時交付軟件產品和服務,開發和運營工作必須緊密合作
簡單的來說DevOps是一種文化,是讓開發開發、運維、測試能夠之間溝通和交流
自動化運維工具:saltstack、jenkins、等。因爲他們的目標一樣,爲了我們的軟件、構建、測試、發佈更加的敏捷、頻繁、可靠
如果運維對git不熟,是無法做自動化部署。因爲所有的項目都受制於開發
Jenkins 介紹
Jenkins
只是一個平臺,真正運作的都是插件。這就是jenkins流行的原因,因爲jenkins什麼插件都有 Hudson
是Jenkins的前身,是基於Java開發的一種持續集成工具,用於監控程序重複的工作,Hudson後來被收購,成爲商業版。後來創始人又寫了一個jenkins
,jenkins在功能上遠遠超過hudson
Jenkins官網:https://jenkins.io/
安裝
安裝JDK
Jenkins是Java編寫的,所以需要先安裝JDK,這裏採用yum安裝,如果對版本有需求,可以直接在Oracle官網下載JDK。
[root@linux-node1 ~]# yum install -y java-1.8.0
安裝jenkins
[root@linux-node1 ~]# cd /etc/yum.repos.d/ [root@linux-node1 yum.repos.d]# wget http://pkg.jenkins.io/redhat/jenkins.repo [root@linux-node1 ~]# rpm --import http://pkg.jenkins.io/redhat/jenkins.io.key [root@linux-node1 ~]# yum install -y jenkins [root@linux-node1 ~]# systemctl start jenkins #本文使用yum進行安裝,大家也可以使用編譯安裝。
新版本的jenkins爲了保證安全,在安裝之後有一個鎖,需要設置密碼之後纔可以解鎖
Jenkins Web
訪問地址:192.168.56.11:8080
友情提示:jenkins如果跟gitlab在一臺服務器需要將jenkins的端口進行修改,需要將jenkins的8080
修改爲8081
[root@linux-node1 ~]# cat /var/lib/jenkins/secrets/initialAdminPassword 490a2f35a2df49b6b8787ecb27122a3a
複製這個文件下面的ID,否則不可以進行安裝。
我們選擇推薦安裝即可
我們先來介紹一下jenkins基礎功能
這裏就是構建一個項目
可以看到當前登陸用戶及用戶權限等
任務歷史:可以查看到所有構建過的項目的歷史
#之所以叫構建,是因爲都是java,因爲如果不是java程序就沒有構建這個詞。但是我們也可以把一些工作稱之爲構建
系統管理:-系統設置
設置Jenkins全局設置&路徑
Jenkins系統管理比較重要的就是插件管理
了
#因爲jenkins所有的東西都需要靠插件來完成,
我們想安裝什麼插件,我們可以選擇可選插件
查看還可以去jenkins官網下載,然後上傳插件
因爲很多插件需要***纔可以繼續下載,jenkins還提供了代理的設置
還是在服務器目錄下進行上傳插件 目錄路徑= /var/lib/jenkins/plugins/ 這個目錄下是我們安裝所有的插件