Step1:構建一個自由風格的php-deploy
Step2:Gernal配置,丟棄舊的構建,防止jenkins構建較多以後變臃腫
Step3:源碼管理:這裏使用git插件,也可使用svn插件
將git路徑存在這裏還須要權限認證,不然會出現error 。
jenkins服務器上生成SSH-Key
[root@linux-node2 ~]# yum install -y git
[root@linux-node2 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:00FQjn5P6qAtok4BuE42TyfuNJnblzZ389XwKBhmHjY root@linux-node2
The key's randomart image is:
+---[RSA 2048]----+
| .oo |
|. + |
|o . o |
| o . . . |
|.+.o . S E . . |
|+ =.= B O +.|
| ..B o + o ..o|
| .o = .B + o .. |
| .o+ o+.+ o o. |
+----[SHA256]-----+
[root@linux-node2 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+/XyUMNP5Wm63hhcACosVyRtmJxTSnT46HSKZ2PhduTHPIJcfhVTmeCk1zwO0fP8PmwXFf0+G9ki8CupE/+xcOy14TCqxNgvP8o514IjXOFV7SO1lnHKH3t0RfaFEloRZHnrgIcWiZrFvYRT/TFznWO86sfHPzlW6WF9elTqRURNR60bwv9C6iw4PpYjGVIST/SeGl75axtUjJr544jB5pEWtNZ09ktCKpPeFBvgCc9exdzOQuzaCXQrroNU0p6MB6KkoIOmpkN92cDPdg4EgBYDjwcl38FbXOq3N0QL8PT+IZpHBWFVEAZU2alI02H5NNUy9p2K/Br4NY3UvYZiP root@linux-node2
命令行測試添加ssh-key後可否正常拉取
[root@linux-node2 ~]# git clone git@192.168.56.11:java/app1.git
Cloning into 'app1'...
The authenticity of host '192.168.56.11 (192.168.56.11)' can't be established.
ECDSA key fingerprint is SHA256:p2lhKmsPQ6K+dWHHvbJg0GV+Ni9VM7vlViKrYsZLP1s.
ECDSA key fingerprint is MD5:22:14:1c:37:de:47:1c:4a:2f:88:b1:dc:e2:d0:02:17.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.11' (ECDSA) to the list of known hosts.
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Receiving objects: 100% (11/11), done.
[root@linux-node2 ~]# ll
total 68048
-rw-------. 1 root root 948 Dec 3 01:26 anaconda-ks.cfg
drwxr-xr-x 3 root root 62 Dec 21 15:53 app1
-rw-r--r-- 1 root root 69675984 Mar 2 2017 jenkins-2.32.3-1.1.noarch.rpm
而後保存,當即構建一次,會拉取master的代碼庫
點開能夠看到控制檯的輸出,如圖:
/var/lib/jenkins/workspace/php-deploy目錄用於存放代碼信息
[root@linux-node2 php-deploy]# ll
total 12
-rw-r--r-- 1 root root 28 Dec 21 16:11 index.html
-rw-r--r-- 1 root root 12 Dec 21 16:11 new.html
-rw-r--r-- 1 root root 19 Dec 21 16:11 readme
[root@linux-node2 php-deploy]# pwd
/var/lib/jenkins/workspace/php-deploy
這裏咱們拉取的代碼須要推送到遠程代碼目錄,須要以下操做:
架設linux-node1爲web服務,目錄爲/data/www/php-deploy
[root@linux-node1 ~]# mkdir /data/www/php-deploy -p
添加node2的免祕鑰登錄
[root@linux-node1 ~]# vim .ssh/authorized_keys
[root@linux-node1 ~]# chmod 600 .ssh/authorized_keys
[root@linux-node2 ~]# ssh 192.168.56.11
Last login: Mon Dec 4 17:41:56 2017 from 192.168.56.1
[root@linux-node1 ~]#
修改項目設置,配置構建:Execute shell,至關於將代碼自動發佈到linux-node1的代碼目錄中。
接下來,咱們從新構建一次,並查看控制檯輸出:
在node1上查看目錄,也會有相應的代碼信息
[root@linux-node1 ~]# ll /data/www/php-deploy/
total 12
-rw-r--r-- 1 root root 28 Dec 21 16:11 index.html
-rw-r--r-- 1 root root 12 Dec 21 16:11 new.html
-rw-r--r-- 1 root root 19 Dec 21 16:11 readme
[root@linux-node1 ~]#
#########################################################################
Jenkins的遠程管理方式包含:
Shell ssh
SSH Plugin
ansible、saltstack
(1)Shell ssh
在項目構建時,jenkins使用了Execute Shell直接對遠程主機操做,同步了代碼到主機192.168.56.11上,而且能夠增長對遠程機器進行操做。例如執行某個腳本:ssh root@192.168.53.11 "/bin/sh /data/scripts/****.sh "
如圖:
(2)SSH plugin
除了以上方法以外,還可使用SSH 的插件--SSH plugin
系統管理-->系統配置-->SSH remote hosts,配置好遠程主機
在項目中配置,如圖:
這樣就完成了對遠程主機的管理
此外,還可使用自動化工具,如ansible,saltstack,模式一致,只是用的是ansible或者是saltstack的命令行工具的不一樣。
當業務量變大時,單臺的jenkins進行自動化構建部署,就顯得沒那麼靈活,下面介紹jenkins的集羣功能。
jenkins的集羣並不是像web服務器,mysql集羣,jenkins的集羣無需在額外的主機安裝jenkins,可是用於java項目來講,要使用集羣功能,額外的主機就必需要安裝maven。
(1)在jenkins的web界面:系統管理-->Configure Global Security-->TCP port for JNLP agent配置端口30000
(2)系統管理-->管理節點-->新建節點
(3)分配任務到節點
在項目中配置:
General-->Restrict where this project can be run-->Label Expression:node-01
此時,在對項目進行構建,將會分配到node-01節點上進行構建,如圖:
當一個公司的開發分爲多個組別,或者是多個項目等等。用於公司內部測試,讓開發人員自行構建測試,此時不可能讓全部的開發都在公用一個構建,這樣變得很混亂,爲了解決這一問題,jenkins也提供了角色受權的機制。每一個開發有着對應的帳號和權限,能夠自行新建,構建,測試,發佈等。角色受權須要安裝的插件:Role-based Authorization Strategy
(1)系統配置
系統管理-->Configure Global Security-->訪問控制-->受權策略-->Role-Base Strategy
(2)新建用戶
系統管理-->管理用戶-->新建用戶
這裏建立一個java用戶和php用戶,用於區分php和java項目的構建
(3)用戶關聯本身相關job,沒法查看其餘的job
創建項目角色,並對該用戶進行項目的受權(包括Job的構建,取消,配置,建立,刪除等等)
注意此處的添加,一個是Role是隨意填寫,最好規範點。Pattern是正則匹配,好比此處匹配的是全部包含Java開頭的項目和php開頭的項目
系統管理-->Manage and Assign Roles --> Manage Roles-->Project roles
配置好項目的權限,使用java用戶或php用戶登陸是沒有新建項目的權限,如需新增這樣的權限,須要在Global roles中進行配置,新增一個角色(好比新增一個能夠建立新項目的權限角色:new job,可登陸查看的角色read):
而後系統管理-->Manage and Assign Roles -->Assign Roles進行添加對應的權限
使用php登陸查看,能夠看到php用戶能夠看到對應php開頭的項目,可是沒有新建項目的權限:
-
2、Jenkins的Pipeline(代碼流水線管理)
Pipeline(代碼流水線管理)
Pipeline名詞顧名思義就是流水線的意思,由於公司可能會有不少項目。若是使用jenkins構建完成後,開發構建項目須要一項一項點擊,比較麻煩。因此出現pipeline名詞。
(1)下載pipeline。這樣只須要構建一個項目,就會幫咱們完成全部相關項目
搜索插件pipeline
等待安裝完成
(2)新建一個pipeline的項目
配置pipeline項目,使用Pipeline script腳本:
node {
stage 'build php-deploy'
build 'php-deploy'
stage 'build java'
build 'java'
}
爲了解決各個項目的依賴關係關係,使用pipeline的腳本進行控制。
第一步構建php項目,第二步構建java項目。Pipeline的腳本語法在Pipeline Syntax中有展現
Pipeline Syntax的使用,如圖:
當即構建p1的項目,如圖:
代碼流水線的功能就介紹到此!
思路圖:
jenkins-->系統管理-->管理插件-->下載並安裝gitlab plugin
路徑:Jenkins-->Credentials-->System-->Global credentials(unrestricted)-->Add Credentials
一、Kind選擇Gitlab API token
二、其中API token填寫gitlab中有庫權限的帳號
三、ID填寫用戶帳號
gitlab生成Api token,將生成的token填入上面的證書內。
路徑:系統管理-->系統設置
一、填寫鏈接名
二、填寫gitlab訪問URL
三、選擇gitlab認證
三、測試鏈接
-
4、配置任務在job配置中選擇gitlab connection:gitlab
在job配置界面
一、勾選 Build when a change is pushed to GitLab. GitLab CI Service URL: http://192.168.56.12:8080/project/php-deploy
二、選擇push events 時間觸發構建
三、選擇分支過濾(此處能夠根據不一樣的需求來使用過濾功能)
四、secret token須要填入gitlab項目中的webhook
在gitlab中找到項目-->setting-->Integrations配置
填寫在上圖生成的連接:
URL:http://192.168.56.12:8080/project/php-deploy
Secret Token:3f199086a22c54957579966e34ad120a
點擊Add webhook
測試是否生效:點擊test-->選擇push event會跳轉到Hook excuted successfully:HTTP 200
在linux-node1上安裝nginx,初始同步了線上代碼,寫入一個index.html。如圖:
[root@linux-node1 ~]# ll /data/www/php-deploy/
total 12
-rw-r--r-- 1 root root 28 Dec 23 15:45 index.html
-rw-r--r-- 1 root root 12 Dec 21 16:11 new.html
-rw-r--r-- 1 root root 19 Dec 21 16:11 readme
[root@linux-node1 ~]# cat /data/www/php-deploy/index.html
<h1>welcome to beijing</h1>
模擬程序員在linux-node2上進行修改代碼,並提交到gitlab的master分支上
[root@linux-node2 app1]# pwd
/root/php/app1
[root@linux-node2 app1]# echo "Welcome to use Jenkins and Gitlab" > index.html
[root@linux-node2 app1]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
#modified: index.html
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@linux-node2 app1]# git add .
[root@linux-node2 app1]# git commit -m "jenkins + gitlab"
[master 7313bdd] jenkins + gitlab
1 file changed, 1 insertion(+), 1 deletion(-)
[root@linux-node2 app1]# git push origin master
Counting objects: 5, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 334 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.56.11:java/app1.git
dd37af6..7313bdd master -> master
到此,自動觸發和發佈就完成了!這只是一個簡單的構建發佈,做爲內部測試使用仍是能夠的!生產使用,有待優化!
1、環境說明和準備
一、環境說明
deploy-server |
192.168.56.12 |
發佈 |
Centos 7.4 |
web |
192.168.56.13 |
web服務器,nfs服務器 |
Centos 7.4 |
二、服務器準備工做
(1)發佈機前期準備
a.增長普通用戶並配置密碼
[root@deploy-server ~]
[root@deploy-server ~]
uid=1000(www) gid=1000(www) groups=1000(www)
[root@deploy-server ~]
[root@deploy-server ~]
b.建立部署須要的目錄並初始化git目錄
[root@deploy-server ~]
[root@deploy-server ~]
[www@deploy-server ~]$ tree /deploy
/deploy
├── code
│ ├── glzx
│ ├── gys
│ ├── jxs
│ ├── wap
│ ├── www
│ └── yyzx
├── config
├── tar
└── tmp
[www@deploy-server ~]$ cd /deploy/code/www && git init
c.建立配置文件config.php
[www@deploy-server ~]$ vim /deploy/config/config.php
this is config.php
[www@deploy-server ~]$ tree /deploy
/deploy
├── code
│ ├── glzx
│ ├── gys
│ ├── jxs
│ ├── wap
│ ├── www
│ └── yyzx
├── config
│ └── config.php
├── tar
└── tmp
d.配置發佈機和目標機的ssh通訊
[www@deploy-server deploy]$ cat /home/www/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDzM3AW6/X+djvKJTsdFbY3ik+mlradxpD3COoTP5h6x509unksuCdduV7awPjEGHvK2GVjJmvckxdvLkMc23p7bsctHlturPN2VozJTrYwXMAbmxf97cKE/fpKhjPXG8HlWBLpEaTM8PITgvdcyaeAUaIN+/h5VrA8TZKFAgbxDLxtgwqPzYIG9nqCO7MMCgzhJxI6PDQ6KVU9rHal/p4XKTIy4Rq4FzZTav2tS4zNJ7kX9+e6EO0JTooPanJXBTltLOJJsKxnlA7tc20rq6+0XVqbUBKYahL/8ZzkxZozNrNq7wtIuuJo0WTDFzDdPcJyAGlRWLuwct7y4p4UApVz www@deploy-server
[www@deploy-server ~]$ ssh-copy-id www@192.168.56.13
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/www/.ssh/id_rsa.pub"
The authenticity of host
ECDSA key fingerprint is SHA256:ahG6dBy/Z1nUIUWhQQrylsiwBlnDKC/jz8rnaPU2eF0.
ECDSA key fingerprint is MD5:6e:58:0b:02:1c:a4:41:51:e8:7d:33:4d:46:bb:a0:68.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
www@192.168.56.13
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'www@192.168.56.13'"
and check to make sure that only the key(s) you wanted were added.
[www@deploy-server ~]$ ssh 192.168.56.13
Last login: Fri Nov 2 18:01:02 2018
[www@web ~]$
e.將ssh公鑰複製到github或gitlab
(2)web服務器準備
a.部署NFS服務器
[root@web ~]# yum install -y nfs-utils rpcbind
[root@web ~]# vim /etc/exports
/nas/www 192.168.56.0/24(rw,sync,no_root_squash)
/nas/jxs 192.168.56.0/24(rw,sync,no_root_squash)
/nas/wap 192.168.56.0/24(rw,sync,no_root_squash)
/nas/glzx 192.168.56.0/24(rw,sync,no_root_squash)
/nas/yyzx 192.168.56.0/24(rw,sync,no_root_squash)
/nas/gys 192.168.56.0/24(rw,sync,no_root_squash)
[root@web ~]# systemctl start rpcbind
[root@web ~]# systemctl start nfs
[root@web ~]# showmount -e
Export list for web:
/nas/gys 192.168.56.0/24
/nas/yyzx 192.168.56.0/24
/nas/glzx 192.168.56.0/24
/nas/wap 192.168.56.0/24
/nas/jxs 192.168.56.0/24
/nas/www 192.168.56.0/24
b.掛載共享目錄
[root@web ~]
[root@web ~]
[root@web ~]
[root@web ~]
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 1.7G 16G 10% /
devtmpfs 482M 0 482M 0% /dev
tmpfs 493M 0 493M 0% /dev/shm
tmpfs 493M 6.8M 486M 2% /run
tmpfs 493M 0 493M 0% /sys/fs/cgroup
/dev/sda1 497M 171M 326M 35% /boot
tmpfs 99M 0 99M 0% /run/user/0
192.168.56.13:/nas/www 18G 1.7G 16G 10% /webroot/www
c.部署nginx+php
[root@web ~]
[root@web ~]
[root@web ~]
[root@web ~]
user www;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
[root@web ~]
[root@web ~]
server {
listen 80;
server_name localhost;
root /data/web/www;
index index.php index.htm index.html;
client_max_body_size 20m;
location / {
proxy_read_timeout 150;
try_files $uri $uri/ /index.php; } location ~* .*\.php$ { #try_files $uri =404; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
[root@web ~]
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web ~]
[root@web ~]
user www
group www
....
[root@web ~]
[03-Nov-2018 10:16:18] NOTICE: configuration file /etc/php-fpm.conf test is successful
[root@web ~]
[root@web ~]
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sat, 03 Nov 2018 02:16:36 GMT
Content-Type: text/html
Content-Length: 35
Last-Modified: Sat, 03 Nov 2018 02:07:00 GMT
Connection: keep-alive
ETag: "5bdd02c4-23"
Accept-Ranges: bytes
2、發佈腳本編寫
一、自動化部署流程設計
- 發佈機獲取代碼(直接拉取),從svn或git倉庫進行拉取
- 發佈機編譯代碼(可選,java語言須要編譯,PHP無需編譯)
- 將配置文件拷貝到代碼文件(因爲配置文件有數據庫等機密信息,須要獨立處理)
- 代碼打包(將代碼進行壓縮打包)
- SCP到目標服務器目錄
- 將目標服務器移除集羣
- 在目標服務器上進行解壓傳過來的代碼
- 解壓後,對代碼根目錄進行軟連接到剛纔的目錄文件,實現版本連接
- 重啓(可選,tomcat須要重啓)
- 測試
- 加入集羣
二、自動化部署腳本編寫
#!/bin/bash
NODE="192.168.56.13"
SHELL_NAME="deploy.sh"
SHELL_DIR="/home/www"
SHELL_LOG="${SHELL_DIR}/${SHELL_NAME}.log"
PRO_NAME="www"
CODE_DIR="/deploy/code/www"
CONFIG_DIR="/deploy/config"
TMP_DIR="/deploy/tmp"
TAR_DIR="deploy/tar"
LOCK_FILE="/tmp/deploy.lock"
LOG_DATE='date "+%Y-%m-%d"'
LOG_TIME='date "+%H-%M-%S"'
CDATE=$(date "+%Y-%m-%d")
CTIME=$(date "+%H-%M-%S")
useage(){
echo $"Useage: $0 { deploy |rollback [ list | version ] }"
}
url_test(){
URL=$1
curl -s --head $URL |grep '200 OK'
if [ $? -ne 0 ];then
shell_unlock;
writelog "test error" && exit;
fi
}
writelog(){
LOGINFO=$1
echo "${CDATE} ${CTIME}: ${SHELL_NAME} : ${LOGINFO} " >> ${SHELL_LOG}
}
code_get(){
writelog "code_get";
cd ${CODE_DIR} && git pull git@github.com:kin08200/learngit.git
cp -r ${CODE_DIR} ${TMP_DIR}
API_VERL=$(git show |grep commit |cut -d ' ' -f2 )
API_VER=$(echo ${API_VERL:0:6})
echo $API_VER
}
code_config(){
writelog "code_config"
/bin/cp -r ${CONFIG_DIR}/* ${TMP_DIR}/${PRO_NAME}
PKG_NAME=${PRO_NAME}_"${API_VER}"_"${CDATE}-${CTIME}"
cd ${TMP_DIR} && mv ${PRO_NAME} ${PKG_NAME}
}
code_tar(){
writelog "code_tar"
cd ${TMP_DIR} && tar -czf ${PKG_NAME}.tar.gz ${PKG_NAME}
writelog "${PKG_NAME}.tar.gz"
}
code_scp(){
writelog "code_scp"
scp ${TMP_DIR}/${PKG_NAME}.tar.gz $NODE:/webroot/www
}
code_deploy(){
writelog "code_deploy"
ssh $NODE "cd /webroot/www && tar -zxf ${PKG_NAME}.tar.gz"
ssh $NODE "rm -rf /data/web/www && ln -s /webroot/www/${PKG_NAME} /data/web/www"
}
code_test(){
url_test "http://192.168.56.13"
}
rollback_fun(){
ssh $NODE "rm -rf /data/web/www && ln -s /webroot/www/$1 /data/web/www"
}
rollback(){
if [ -z $1 ];then
shell_unlock;
echo "Please input rollback version." && exit;
fi
case $1 in
list)
ls -l /deploy/tmp/*.tar.gz
;;
*)
rollback_fun $1
;;
esac
}
shell_lock(){
touch ${LOCK_FILE}
}
shell_unlock(){
rm -f ${LOCK_FILE}
}
main(){
if [ -f ${LOCK_FILE} ];then
echo "Deploy is running" && exit
fi
DEPLOY_METHOD=$1
ROLLBACK_VER=$2
case $DEPLOY_METHOD in
deploy)
shell_lock;
code_get;
code_config;
code_tar;
code_scp;
code_deploy;
code_test;
shell_unlock;
;;
rollback)
shell_lock;
rollback $ROLLBACK_VER;
shell_unlock;
;;
*)
useage;
;;
esac
}
main $1 $2
3、發佈測試
一、開發機和github添加ssh信任
[www@localhost ~]$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+ta7tkljnIgqvgEugQvIfVxH/a+geX250ZhOpe+14Q8EBQSI+qGyXCeihln+0aQpzIERvNBZ7JjWCg5XeQlgPBgCmqoQKNTWl/NUBT+uY/NY9fIGdRCVBvVcDC554Be48zB57mtapKQEkqm/8kmq7sPRQDv98l5wvFvYOPxocmjnioDZr3GeYmgdFPNJ5WGg6yY29IHXgh2v3eCXLwX2Z2eUdKCpV1LS42wdAN8TqHFCEmthREIq2r86ZKPOovD6Micq7wa2yJqtA/hkv+DvEhRzOIVznfW5EptOyKYcittGu63JGMSbCr1uCdW7PLUQ8aIWDDlip+/EcIt0KkuJJ www@localhost.localdomain
二、克隆項目到開發機進行開發測試
[www@localhost ~]$ mkdir dev && cd dev
[www@localhost dev]$ git clone git@github.com:kin08200/learngit.git
[www@localhost dev]$ ll
total 4
drwxrwxr-x 3 www www 4096 Nov 2 22:02 learngit
[www@localhost dev]$ cd learngit
三、修改index.html文件
[www@localhost learngit]$ ll
total 8
-rw-rw-r-- 1 www www 0 Nov 2 04:31 123
-rw-rw-r-- 1 www www 35 Nov 2 22:02 index.html
-rw-rw-r-- 1 www www 80 Nov 2 04:31 readme.txt
[www@localhost learngit]$ echo "<h1> welcome to Beijing </h1>" > index.html
四、提交代碼
[www@localhost learngit]$ git add .
[www@localhost learngit]$ git commit -m "modify index.html"
[www@localhost learngit]$ git push origin master
五、發佈代碼
[www@deploy-server ~]$ ./deploy.sh deploy
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:kin08200/learngit
* branch HEAD -> FETCH_HEAD
Updating 9a781b2..683a440
Fast-forward
index.html | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
683a44
www_683a44_2018-11-03-10-06-56.tar.gz 100% 22KB 9.3MB/s 00:00
HTTP/1.1 200 OK
六、測試訪問
[www@deploy-server ~]$ curl 192.168.56.13
<h1>
welcome to Beijing!!!!
</h1>
七、回滾測試
[root@web ~]# ll /data/web/
total 0
lrwxrwxrwx 1 www www 43 Nov 3 10:46 www -> /webroot/www/www_683a44_2018-11-03-10-06-56
測試訪問以下,下面進行查看版本列表,並選擇回滾到www_9a781b_2018-11-03-09-59-44版本
[www@deploy-server ~]$ ./deploy.sh rollback list
-rw-rw-r
-rw-rw-r
-rw-rw-r
-rw-rw-r
-rw-rw-r
-rw-rw-r
[www@deploy-server ~]$ ./deploy.sh rollback www_9a781b_2018-11-03-09-59-44
[root@web ~]# ll /data/web/
total 0
lrwxrwxrwx 1 www www 43 Nov 3 10:48 www -> /webroot/www/www_9a781b_2018-11-03-09-59-44
再進行訪問測試: