基於 Jenkins 自動化部署 PHP 環境


1、准備 git 倉庫

[root@git ~]# su - git
上一次登錄:五 5月 8 17:33:05 CST 2020從 192.168.200.117pts/0 上
[git@git ~]$ mkdir php.git
[git@git ~]$ cd php.git
[git@git php.git]$ git --bare init
初始化空的 Git 版本庫於 /home/git/php.git/
[git@git php.git]$ exit
登出

2、上傳代碼到倉庫

[root@git ~]# git clone git@192.168.200.127:/home/git/php.git
正克隆到 'php'...
The authenticity of host '192.168.200.127 (192.168.200.127)' can't be established.
ECDSA key fingerprint is SHA256:HIdLjuU1wd017CkzkNL+Llz+agZ5zOCMVGbwbHPfmes.
ECDSA key fingerprint is MD5:6c:eb:89:cf:b3:52:d6:f5:50:46:56:30:23:09:7b:59.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.200.127' (ECDSA) to the list of known hosts.
git@192.168.200.127's password:
warning: 您似乎克隆了一個空版本庫。
[root@git ~]# cd php

[root@git php]# cat << EOF > index.php
<?php
phpinfo();
?>
EOF

[root@git php]# git add .
[root@git php]# git commit -m "all"
[master(根提交) ae1aa93] all
1 file changed, 3 insertions(+)
create mode 100644 index.php
[root@git php]# git push origin master
git@192.168.200.127's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 219 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.200.127:/home/git/php.git
* [new branch] master -> master

3、部署 web 主機環境

[root@tomcat ~]# yum -y install httpd mariadb-server mariadb mariadb-devel php php-mbstring php-mysql php-bcmath php-gd php-xmlrpc php-ldap php-xml libevent libevent-devel net-snmp net-snmp-devel libxml2 libxml2-devel ntpdate

[root@tomcat ~]# systemctl start httpd
[root@tomcat ~]# systemctl start mariadb

 

 Jenkins 主機將密鑰發布到 web 主機

[root@jenkins ~]# su -s /bin/bash jenkins

bash-4.2$ ssh-keygen

bash-4.2$ ssh-copy-id root@192.168.200.128

基於 rsync 部署

創建一個 Freestyle project

 

 

rsync -avz  --delete * root@192.168.200.128:/var/www/html/

 

 

 

[root@tomcat ~]# ls /var/www/html/

index.php
[root@tomcat ~]# cat /var/www/html/index.php
<?php
phpinfo();
?>

 

 

 基於 ansible 部署

[root@jenkins ~]# rpm -ivh epel-release-latest-7.noarch.rpm

[root@jenkins ~]# yum -y install ansible

[root@jenkins ~]# vim /etc/ansible/hosts

[webserver]
192.168.200.128

修改 Jenkins 運行用戶

[root@jenkins ~]# vim /etc/sysconfig/jenkins

JENKINS_USER="root"

[root@jenkins ~]# /etc/init.d/jenkins restart
Restarting jenkins (via systemctl): [ 確定 ]

添加 Ansible 插件

 

[root@jenkins ~]# ssh-keygen

[root@jenkins ~]# ssh-copy-id git@192.168.200.127

[root@jenkins ~]# ssh-copy-id root@192.168.200.128

 

 

 

 

 

 

 

[root@tomcat ~]# ls /var/www/html/

index.php php-ansible

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM