![image-20221027223538878](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210272235022.png)

![image-20221027223559494](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210272235542.png)

playbook脚本

```
---
- hosts all
  tasks:
    - name: install lnmp
      yum:
        name: 
          - httpd
          - mariadb-server
          - php
          - php-fpm
          - php-mysql
          - php-pdo
        state: present
    - name: start httpd server
      systemd:
        name: httpd
        state: started
        enabled: yes 
    - name: start mariadb-server server
      systemd:
        name: mariadb
        state: started
        enabled: yes
    - name: start php-fpm server
      systemd:
        name: php-fpm
        state: started
        enabled: yes 
    - name: get index.php
      copy:
        src: /opt/index.php
        dest: /var/www/html/index.php
      notify:
        - restart httpd       
  handlers:                                        
    - name: restart httpd
      systemd:
        name: httpd
        state: restarted
      
```

```
echo This is web1! > /opt/index.html

```

```
vim /opt/1/nginx.conf
worker_processes  1;                                                          events {                                                                     
    worker_connections  1024;
}
http {                                                                       
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {                                                                 
        listen       810;
        server_name  localhost;
        location / {                                                         
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
```

```
vim /opt/2/nginx.conf
worker_processes  1;                                                          events {                                                                     
    worker_connections  1024;
}
http {                                                                       
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {                                                                 
        listen       820;
        server_name  localhost;
        location / {                                                         
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
```



```
web1


---
- hosts: 192.168.110.182
  tasks:
     - name: "创建用户"
      shell: useradd -r nginx -s /bin/false
     - name: "推送Nginx源码包"
       unarchive: src=/opt/nginx-1.20.1.tar.gz dest=/opt/ copy=yes
     - name: "安装依赖环境库"
       yum: name=gcc,gcc-c++,automake,openssl,openssl-devel,make,pcre-devel,gd-devel,glibc-devel state=latest
     - name: "安装Nginx"
       shell: cd /opt/nginx-1.20.1 && ./configure --prefix=/usr/local/nginx --user=nginx  --group=nginx --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/nginx.log --http-log-path=/var/log/nginx/access.log --modules-path=/usr/local/nginx/modules --with-select_module --with-poll_module --with-threads  --with-http_ssl_module --with-http_v2_module  --with-http_realip_module --with-http_image_filter_module --with-http_sub_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module  --with-http_stub_status_module --with-stream && make && make install
     - name: "推送配置文件"
       copy: src=/opt/1/nginx.conf dest=/usr/local/nginx/conf/nginx.conf
     - name: "推送测试页面"
       copy: src=/opt/index.html dest=/usr/local/nginx/html/index.html
     - name: "启动Nginx服务"
       shell: 'ln -s /usr/local/nginx/nginx /usr/sbin/nginx'
     - name: "启动"
       shell: nginx
     - name: "检查Nginx服务"
       shell: ps -ef |grep nginx
```



```
web2

- hosts: 192.168.110.183
  tasks:
    - name: "创建用户"
      shell: useradd -r nginx -s /bin/false
    - name: "推送Nginx源码包"
      unarchive: src=/opt/nginx-1.20.1.tar.gz dest=/opt/ copy=yes
    - name: "安装依赖环境库"
      yum: name=gcc,gcc-c++,automake,openssl,openssl-devel,make,pcre-devel,gd-devel,glibc-devel state=latest
    - name: "安装Nginx"
      shell: cd /opt/nginx-1.20.1 && ./configure --prefix=/usr/local/nginx --user=nginx  --group=nginx --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/nginx.log --http-log-path=/var/log/nginx/access.log --modules-path=/usr/local/nginx/modules --with-select_module --with-poll_module --with-threads  --with-http_ssl_module --with-http_v2_module  --with-http_realip_module --with-http_image_filter_module --with-http_sub_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module  --with-http_stub_status_module --with-stream && make && make install
    - name: "推送配置文件"
      copy: src=/opt/2/nginx.conf dest=/usr/local/nginx/conf/nginx.conf
    - name: "推送测试页面"
      copy: src=/opt/index.html dest=/usr/local/nginx/html/index.html
    - name: "启动Nginx服务"
      shell: 'ln -s /usr/local/nginx/nginx /usr/sbin/nginx'
    - name: "启动"
      shell: nginx
    - name: "检查Nginx服务"
      shell: ps -ef |grep nginx

```

![image-20221027225659640](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210272256705.png)

![image-20221027231041984](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210272310043.png)

![image-20221028100442716](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210281004789.png)

![image-20221028100457871](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210281004911.png)

将网页代码传上去web机上

```
#!/bin/bash
echo "ddddd"
ssh  root@192.168.110.37 "rm -rf /usr/local/nginx/html/*"
scp -r /var/lib/jenkins/workspace/test1/*   root@192.168.110.37:/usr/local/nginx/html
ssh  root@192.168.110.37 "nginx -s reload"
```

![image-20221029221610523](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210292216801.png)

![image-20221029221634105](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210292216168.png)

![image-20221029223040181](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210292230228.png)

![image-20221029223101854](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210292231921.png)

```
上传提交 自动更新

git add .
git status
git commit -m "这是web2"
git pull
git push -u origin 
```

![image-20221030162017645](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210301620705.png)

![image-20221030162125368](https://ye5201314-1312898079.cos.ap-guangzhou.myqcloud.com/202210301621423.png)
