news 2026/9/3 7:59:42

今天我们继续DevOps内容Jenkins自动化部署PHP项目

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
今天我们继续DevOps内容Jenkins自动化部署PHP项目

1、实验环境

需要准备三台服务器充当:git、jenkins、web

2、准备git仓库

[root@git ~]# useradd git [root@git ~]# echo "123" | passwd --stdin git [root@git ~]# su - git 上一次登录:三 8月 23 20:41:53 CST 2023pts/0 上 [git@git ~]$ mkdir php.git [git@git ~]$ cd php.git #--bare:创建一个裸仓库。裸仓库是一种特殊的Git仓库,它不包含工作目录(没有文件的检出和编辑空间),主要用于共享,是作为远程仓#库被其他仓库推送(push)和拉取(pull)的中心存储库。 [git@git php.git]$ git --bare init #初始化空的 Git 版本库于 /home/git/php.git/ [git@git php.git]$ exit #登出

3、上传代码到仓库

[root@git ~]# git clone git@192.168.166.9:/home/git/php.git 正克隆到 'php'... git@192.168.200.111'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(根提交) 4ec0ba3] all 1 file changed, 3 insertions(+) create mode 100644 index.php [root@git php]# git push origin master git@192.168.166.9'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 git@192.168.166.9:/home/git/php.git * [new branch] master -> master

4、部署web主机环境

yum install -y nginx php php-mysqlnd mysql-server php-fpm cd /etc/nginx/ mv nginx.conf nginx.conf.back cp nginx.conf.default nginx.conf vim nginx.conf http { ... include conf.d/*.conf; ... server { ... location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; root html; fastcgi_pass php-fpm; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; } ... } } systemctl start php-fpm mysqld nginx

6、基于rsync部署

创建一个Freestyle project

7、 基于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.166.6

修改jenkins运行用户

[root@jenkins ~]# vim /usr/lib/systemd/system/jenkins.service User=root Group=root [root@jenkins ~]# systemctl daemon-reload [root@jenkins ~]# systemctl restart jenkins ###设置SSH的免密登录 [root@jenkins ~]# ssh-keygen -N '' -f ~/.ssh/id_rsa [root@jenkins ~]# ssh-copy-id root@192.168.158.5 [root@jenkins ~]# ssh-copy-id git@192.168.158.4

添加Ansible插件

[root@web ~]# cat /etc/nginx/nginx.conf server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html/php-ansible; index index.html index.php; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; ..... [root@web ~]# systemctl restart nginx
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/2 14:22:02

跨平台任务管理新选择:3个真实场景告诉你My-TODOs为何值得拥有

你是否曾在多设备间反复切换&#xff0c;只为同步一个简单的待办清单&#xff1f;&#x1f629; 面对市面上复杂的任务管理软件&#xff0c;是否渴望找到一款真正安全、轻量且跨平台同步的桌面应用&#xff1f;在这个追求高效工作的时代&#xff0c;本地化存储的跨平台桌面任务…

作者头像 李华
网站建设 2026/9/3 1:37:45

MathQuill终极指南:网页数学公式编辑器的完整使用教程

MathQuill终极指南&#xff1a;网页数学公式编辑器的完整使用教程 【免费下载链接】mathquill Easily type math in your webapp 项目地址: https://gitcode.com/gh_mirrors/ma/mathquill MathQuill是一个强大的JavaScript数学公式编辑器库&#xff0c;专为在网页应用中…

作者头像 李华
网站建设 2026/9/2 23:47:45

Cesium风场可视化完整指南:快速实现3D大气动态效果

Cesium风场可视化完整指南&#xff1a;快速实现3D大气动态效果 【免费下载链接】cesium-wind wind layer of cesium 项目地址: https://gitcode.com/gh_mirrors/ce/cesium-wind 风场可视化是现代气象数据展示的核心技术之一&#xff0c;通过cesium-wind这个专为Cesium.j…

作者头像 李华
网站建设 2026/9/2 23:31:26

终极解决方案:轻松实现IDM无限试用,告别30天限制烦恼

还在为IDM试用期结束而苦恼吗&#xff1f;每次下载到一半弹出注册提示的尴尬场景是否让你头疼不已&#xff1f;现在&#xff0c;一款简单易用的IDM试用重置工具将彻底解决你的困扰&#xff0c;让你无需特殊处理即可持续享受高速下载体验。&#x1f60a; 【免费下载链接】idm-tr…

作者头像 李华
网站建设 2026/9/2 23:30:52

如何永久重置IDM试用期:简单三步解决下载软件过期问题

如何永久重置IDM试用期&#xff1a;简单三步解决下载软件过期问题 【免费下载链接】idm-trial-reset Use IDM forever without cracking 项目地址: https://gitcode.com/gh_mirrors/id/idm-trial-reset 还在为IDM试用期结束而烦恼吗&#xff1f;这款专业的IDM试用重置工…

作者头像 李华
网站建设 2026/9/3 1:22:55

AMD Ryzen处理器SMUDebugTool实战全解析

AMD Ryzen处理器SMUDebugTool实战全解析 【免费下载链接】SMUDebugTool A dedicated tool to help write/read various parameters of Ryzen-based systems, such as manual overclock, SMU, PCI, CPUID, MSR and Power Table. 项目地址: https://gitcode.com/gh_mirrors/smu…

作者头像 李华