2026/2/13 6:11:40
网站建设
项目流程
做网站jijianjianzhan,浙江嘉兴发现2例新冠阳性,网站外链购买平台,网站内容批量替换1. 准备实验环境搭建包含 Git 仓库主机、Jenkins 主机和 Web 主机的环境。2. 准备 Git 仓库在 Git 主机上创建 git 用户并设置密码#xff1a;[rootgit ~]# useradd git
[rootgit ~]# echo 123 | passwd --stdin git切换到 git 用户#xff0c;创建并初始化裸仓库…1. 准备实验环境搭建包含 Git 仓库主机、Jenkins 主机和 Web 主机的环境。2. 准备 Git 仓库在 Git 主机上创建 git 用户并设置密码[rootgit ~]# useradd git [rootgit ~]# echo 123 | passwd --stdin git切换到 git 用户创建并初始化裸仓库[rootgit ~]# su - git [gitgit ~]$ mkdir php.git [gitgit ~]$ cd php.git [gitgit php.git]$ git --bare init [gitgit php.git]$ exit3. 上传代码到仓库克隆仓库到本地[rootgit ~]# git clone git192.168.166.9:/home/git/php.git创建 PHP 测试文件并提交推送[rootgit ~]# cd php/ [rootgit php]# cat EOF index.php ?php phpinfo(); ? EOF [rootgit php]# git add . [rootgit php]# git commit -m all [rootgit php]# git push origin master4. 部署 Web 主机环境nginx安装相关软件yum install -y nginx php php-mysqlnd mysql-server php-fpm配置 nginx.conf 文件添加 PHP 解析相关配置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; include fastcgi.conf; } ... } }启动服务systemctl start php-fpm mysqld nginx5. Jenkins 主机配置密钥认证切换到 jenkins 用户生成密钥并分发到 Web 主机和 Git 仓库主机[rootjenkins ~]# su -s /bin/bash jenkins bash-4.2$ ssh-keygen bash-4.2$ ssh-copy-id root192.168.158.5 bash-4.2$ ssh-copy-id git192.168.158.46. 基于 rsync 部署在 Jenkins 中创建一个 Freestyle project。进行相关配置具体配置参考相关图示。点击 “build Now” 执行部署。7. 基于 ansible 部署在 Jenkins 主机上安装 ansible[rootjenkins ~]# rpm -ivh epel-release-latest-7.noarch.rpm [rootjenkins ~]# yum -y install ansible配置 ansible 主机清单[rootjenkins ~]# vim /etc/ansible/hosts [webserver] 192.168.166.6修改 Jenkins 运行用户[rootjenkins ~]# vim /usr/lib/systemd/system/jenkins.service Userroot Grouproot [rootjenkins ~]# systemctl daemon-reload [rootjenkins ~]# systemctl restart jenkins设置 SSH 免密登录[rootjenkins ~]# ssh-keygen -N -f ~/.ssh/id_rsa [rootjenkins ~]# ssh-copy-id root192.168.158.5 [rootjenkins ~]# ssh-copy-id git192.168.158.4在 Jenkins 中添加 Ansible 插件。配置 Web 主机的 nginx.conf 文件设置网站根目录等信息并重启 nginx[rootweb ~]# cat /etc/nginx/nginx.conf server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html/php-ansible; index index.html index.php; include /etc/nginx/default.d/*.conf; ..... [rootweb ~]# systemctl restart nginx8. 使用 pipeline 部署创建 Pipeline 项目编写 Pipeline 脚本pipeline { agent any stages { stage(Checkout Code) { steps { // 使用 SSH 方式拉取 Git 代码 git branch: master, // 替换为你的分支名称 url: git192.168.158.4:/home/git/discuz.git // 替换为你的 Git 仓库地址 } } stage(Deploy to Server) { steps { sh scp -r ** root192.168.158.5:/usr/share/nginx/html/ ; } } } post { success { echo Deployment successful! } failure { echo Deployment failed! } } }执行部署。9. Discuz 论坛部署1. Git 主机准备 Discuz 代码克隆 Discuz 代码到本地以官方仓库为例或上传本地 Discuz 源码[rootgit ~]# cd /home/git/ [rootgit git]# git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git discuz [rootgit git]# cd discuz初始化并推送到私有 Git 仓库[rootgit discuz]# git init [rootgit discuz]# git add . [rootgit discuz]# git commit -m initial discuz code [rootgit discuz]# git remote add origin git192.168.166.9:/home/git/discuz.git # 关联私有仓库 [rootgit discuz]# git push -u origin master # 推送代码2. Web 主机环境配置创建网站根目录并授权以 Nginx 为例[rootweb ~]# mkdir -p /usr/share/nginx/html/discuz [rootweb ~]# chown -R nginx:nginx /usr/share/nginx/html/discuz # 确保 Web 服务有权限访问配置数据库创建 Discuz 专用数据库和用户[rootweb ~]# mysql -u root -p Enter password: # 输入数据库密码 mysql CREATE DATABASE discuz_db CHARACTER SET utf8mb4; # 创建数据库 mysql CREATE USER discuz_userlocalhost IDENTIFIED BY 123456; # 创建用户 mysql GRANT ALL PRIVILEGES ON discuz_db.* TO discuz_userlocalhost; # 授权 mysql FLUSH PRIVILEGES; mysql exit调整 PHP 配置确保满足 Discuz 需求[rootweb ~]# vim /etc/php.ini # 修改以下参数根据实际环境调整 upload_max_filesize 20M post_max_size 20M max_execution_time 300 [rootweb ~]# systemctl restart php-fpm # 重启 PHP 服务3. Jenkins 部署配置基于 Pipeline修改 Pipeline 脚本适配 Discuz 部署pipeline { agent any stages { stage(Checkout Code) { steps { // 拉取 Discuz 代码 git branch: master, url: git192.168.158.4:/home/git/discuz.git # 私有仓库地址 } } stage(Deploy to Web Server) { steps { // 同步代码到 Web 主机目录 sh scp -r ./* root192.168.158.5:/usr/share/nginx/html/discuz/ // 远程授权确保文件权限正确 sh ssh root192.168.158.5 chown -R nginx:nginx /usr/share/nginx/html/discuz } } } post { success { echo Discuz deployment successful! Please complete installation via browser. } failure { echo Discuz deployment failed! } } }执行部署在 Jenkins 中运行 Pipeline 项目等待代码同步完成。4. 浏览器完成 Discuz 安装访问 Web 主机地址如http://192.168.158.5/discuz进入 Discuz 安装向导。按照提示完成以下步骤同意许可协议点击 “下一步”。检查环境确保所有项均为 “符合”点击 “下一步”。选择 “全新安装”输入数据库信息数据库名discuz_db数据库用户discuz_user数据库密码123456设置管理员账号和密码完成安装。5. 验证部署安装完成后访问论坛首页确认正常显示。登录管理员账号检查功能是否正常如发帖、上传附件等。后续代码更新可直接提交到 Git 仓库Jenkins 会自动触发部署需配置 Git 钩子或定时构建。