zoukankan      html  css  js  c++  java
  • 基于 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

     

  • 相关阅读:
    Nginx练习练习玩玩
    MySQL Lock--MySQL加锁规则
    MySQL Transaction--RR事务隔离级别下加锁测试
    MySQL Transaction--RC事务隔离级别下加锁测试
    MySQL Transaction--事务隔离级别基础
    MySQL Transaction--快照读和当前读
    MySQL Transaction--RC和RR区别
    MySQL Disk--NAND Flash原理
    MySQL Disk--SSD与RAID
    MySQL Disk--SSD磁盘性能抖动问题
  • 原文地址:https://www.cnblogs.com/2567xl/p/12855284.html
Copyright © 2011-2022 走看看