基于Jenkins自动化部署PHP环境---基于rsync部署

基于基于Jenkins自动打包并部署Tomcat环境_学习新鲜事物的博客-CSDN博客环境

准备git仓库

root@git \~\]# su - git 上一次登录:五 8月 25 15:09:12 CST 2023从 192.168.50.53pts/2 上 \[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 登出

上传代码到仓库

root@git \~\]# git clone [email protected]:/home/git/php.git/ 正克隆到 'php'... [email protected]'s password: warning: 您似乎克隆了一个空版本库。 \[root@git \~\]# cd php/ \[root@git php\]# cat \<\< EOF \> index.php \> \ phpinfo(); \> ?\> \> EOF \[root@git php\]# git add . \[root@git php\]# git commit -m "all" \[master(根提交) a251610\] all 1 file changed, 3 insertions(+) create mode 100644 index.php \[root@git php\]# git push origin master [email protected]'s password: Counting objects: 3, done. Writing objects: 100% (3/3), 218 bytes \| 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To [email protected]:/home/git/php.git/ \* \[new branch\] master -\> master

部署web主机环境

root@tomcat \~\]# yum install -y 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 \~\]# yum -y install rsync \[root@tomcat \~\]# systemctl start httpd \[root@tomcat \~\]# systemctl start mariadb ![](https://file.jishuzhan.net/article/1696548567486828546/1da0cc93c4334190b257029a9cbaa1aa.png)

Jenkins主机将密钥发布到web主机

root@jenkins \~\]# su -s /bin/bash jenkins bash-4.2$ ssh-keygen bash-4.2$ ssh-copy-id [email protected] \[root@jemkins \~\]# su -s /bin/bash jenkins bash-4.2$ ssh-copy-id [email protected] /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/var/lib/jenkins/.ssh/id_rsa.pub" The authenticity of host '192.168.50.54 (192.168.50.54)' can't be established. ECDSA key fingerprint is SHA256:QTpNCUOIFG1aAs7OSxPHKn0MlNEnLbS7SP/V1xdN8Cg. ECDSA key fingerprint is MD5:f8:df:e8:5f:ae:af:56:a8:e9:0c:76:13:8b:0e:07:4c. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys [email protected]'s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh '[email protected]'" and check to make sure that only the key(s) you wanted were added.

基于rsync部署

创建一个Freestyle project

[email protected]:/home/git/php.git

rsync -avz --delete * [email protected]:/var/www/html/

root@tomcat \~\]# ls /var/www/html/ index.php \[root@tomcat \~\]# cat /var/www/html/index.php \ ![](https://file.jishuzhan.net/article/1696548567486828546/fe1eb024b68c4a18b21cc148812e5c29.png) ******基于ansible部署****** \[root@jemkins \~\]# yum -y install ansible > \[root@jemkins \~\]# vim /etc/ansible/hosts > > \[webservers

192.168.50.54

修改jenkins运行用户

root@jemkins \~\]# vim /usr/lib/systemd/system/jenkins.service 34 User=root 35 Group=root 一般在/etc/init.d/jenkins或/usr/lib/systemd/system/jenkins.service。根据不同的Linux发行版可能略有不同,请根据实际情况进行查找。

添加Ansible插件

创建php-ansible

做好ssh密钥通联

src=${WORKSPACE} dest=/var/www/html rsync_opts=--exclude=.git

访问http://192.168.50.54/php-ansbile/

再见

相关推荐
b***251119 分钟前
电池自动点焊机:多领域电池制造的核心设备
自动化·制造
邪恶的贝利亚2 小时前
《ffplay 读线程与解码线程分析:从初始化到 seek 操作,对比视频与音频解码的差异》
ffmpeg·php·音视频
廖圣平2 小时前
美团核销 第三方接口供应商 (含接口文档)
开发语言·数据库·php
sunsineq3 小时前
[超级简单]讲解如何用PHP实现LINE Pay API!
开发语言·php·linepay
乐言3613 小时前
如何用Jmeter实现自动化测试?
运维·jmeter·自动化
新老农3 小时前
php数据导出pdf,然后pdf转图片,再推送钉钉群
pdf·php·钉钉
上海合宙LuatOS3 小时前
全栈工程师实战手册:LuatOS日志系统开发指南!
java·开发语言·单片机·嵌入式硬件·物联网·php·硬件工程
我喜欢山,也喜欢海4 小时前
Jenkins Maven 带权限 搭建方案2025
java·jenkins·maven
kaikaile19954 小时前
Jenkins集成Maven
servlet·jenkins·maven
文人sec5 小时前
接口自动化测试设计思路--设计实战
python·https·单元测试·自动化·pytest