03-调试与优化篇-AI应用的性能直觉前端工程师其实最敏锐
2026/6/15 12:58:57
搭建包含 Git 仓库主机、Jenkins 主机和 Web 主机的环境。
[root@git ~]# useradd git [root@git ~]# echo "123" | passwd --stdin git[root@git ~]# su - git [git@git ~]$ mkdir php.git [git@git ~]$ cd php.git [git@git php.git]$ git --bare init [git@git php.git]$ exit[root@git ~]# git clone git@192.168.166.9:/home/git/php.git[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" [root@git php]# git push origin masteryum install -y nginx php php-mysqlnd mysql-server php-fpmcd /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 nginx[root@jenkins ~]# su -s /bin/bash jenkins bash-4.2$ ssh-keygen bash-4.2$ ssh-copy-id root@192.168.158.5 bash-4.2$ ssh-copy-id git@192.168.158.4[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[root@jenkins ~]# vim /usr/lib/systemd/system/jenkins.service User=root Group=root [root@jenkins ~]# systemctl daemon-reload [root@jenkins ~]# systemctl restart jenkins[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[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; include /etc/nginx/default.d/*.conf; ..... [root@web ~]# systemctl restart nginxpipeline { agent any stages { stage('Checkout Code') { steps { // 使用 SSH 方式拉取 Git 代码 git branch: 'master', // 替换为你的分支名称 url: 'git@192.168.158.4:/home/git/discuz.git' // 替换为你的 Git 仓库地址 } } stage('Deploy to Server') { steps { sh 'scp -r ** root@192.168.158.5:/usr/share/nginx/html/ ;' } } } post { success { echo 'Deployment successful!' } failure { echo 'Deployment failed!' } } }克隆 Discuz 代码到本地(以官方仓库为例,或上传本地 Discuz 源码):
[root@git ~]# cd /home/git/ [root@git git]# git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git discuz [root@git git]# cd discuz初始化并推送到私有 Git 仓库:
[root@git discuz]# git init [root@git discuz]# git add . [root@git discuz]# git commit -m "initial discuz code" [root@git discuz]# git remote add origin git@192.168.166.9:/home/git/discuz.git # 关联私有仓库 [root@git discuz]# git push -u origin master # 推送代码创建网站根目录并授权(以 Nginx 为例):
[root@web ~]# mkdir -p /usr/share/nginx/html/discuz [root@web ~]# chown -R nginx:nginx /usr/share/nginx/html/discuz # 确保 Web 服务有权限访问配置数据库(创建 Discuz 专用数据库和用户):
[root@web ~]# mysql -u root -p Enter password: # 输入数据库密码 mysql> CREATE DATABASE discuz_db CHARACTER SET utf8mb4; # 创建数据库 mysql> CREATE USER 'discuz_user'@'localhost' IDENTIFIED BY '123456'; # 创建用户 mysql> GRANT ALL PRIVILEGES ON discuz_db.* TO 'discuz_user'@'localhost'; # 授权 mysql> FLUSH PRIVILEGES; mysql> exit调整 PHP 配置(确保满足 Discuz 需求):
[root@web ~]# vim /etc/php.ini # 修改以下参数(根据实际环境调整) upload_max_filesize = 20M post_max_size = 20M max_execution_time = 300 [root@web ~]# systemctl restart php-fpm # 重启 PHP 服务修改 Pipeline 脚本(适配 Discuz 部署):
pipeline { agent any stages { stage('Checkout Code') { steps { // 拉取 Discuz 代码 git branch: 'master', url: 'git@192.168.158.4:/home/git/discuz.git' # 私有仓库地址 } } stage('Deploy to Web Server') { steps { // 同步代码到 Web 主机目录 sh 'scp -r ./* root@192.168.158.5:/usr/share/nginx/html/discuz/' // 远程授权(确保文件权限正确) sh 'ssh root@192.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 项目,等待代码同步完成。
http://192.168.158.5/discuz),进入 Discuz 安装向导。discuz_dbdiscuz_user123456