Role of ansible
Note that all three need to be connected to the Internet.
Mine is 80.100, 80.101, 80.102
I operate on 80.100 as long as the other two are on. No need to operate.
Yum install-y epel-release / / install ansible source yum install ansible-yansible-- version / / View ansible version yum install tree-ycd / etc/ansiblevi hosts / / add [web] 192.168.80.10 [1:2] ansible all-- list-hosts shows all defined hosts ssh-keygen-t rsassh-copy-id root@192.168.80.101ssh-copy-id root@ on the last line of the configuration host list 192.168.80.102ansible all-a 'systemctl stop firewalld'ansible all-a' setenforce 0'mkdir-p / opt/roles/nginx/ {tasks Templates} cd / opt/roles/nginx/tasks/vi epel.yml- name: copy epel copy: src=/etc/yum.repos.d/ dest=/etc/yum.repos.d/vi user.yml- name: create user user: name=nginx group=nginx system=yes shell=/sbin/nologinvi group.yml- name: create group group: name=nginx system=yesvi yum.yml- name: install package yum: name=nginxvi start.yml- name: start service service: name=nginx state=restarted enabled=truevi restart.yml- name: restart service service: name=nginx state=restartedcd.. / templates/yum install-y Nginxcp / etc/nginx/nginx.conf nginx.conf.j2vi nginx.conf.j2worker_processes {{ansible_processor_vcpus}} Cd.. / tasks/vi temp.yml- name: copy conf file template: src=nginx.conf.j2 dest=/etc/nginx/nginx.confvi main.yml- include: epel.yml- include: group.yml- include: user.yml- include: yum.yml- include: temp.yml- include: start.ymlcd / etc/ansible/vi nginx_role.yml- hosts: web remote_user: root roles:-role: nginxtree roles/mkdir-p / etc/ansible/group_vars/touch / etc/ansible/group _ vars/allmkdir-p / etc/ansible/roles/commonmkdir-p / etc/ansible/roles/httpd/ {files Templates,tasks,handlers,vars,defaults,meta} mkdir-p / etc/ansible/roles/mysql/ {files,templates,tasks,handlers,vars,defaults,meta} mkdir-p / etc/ansible/roles/php/ {files,templates,tasks,handlers,vars,defaults,meta} touch / etc/ansible/roles/httpd/ {defaults,vars,tasks,meta,handlers} / main.ymltouch / etc/ansible/roles/mysql/ {defaults,vars,tasks,meta,handlers} / main.ymltouch / etc/ansible/roles/php/ {defaults,vars,tasks Meta,handlers} / main.ymlvi / etc/ansible/site.yml- hosts: web remote_user: root roles:-httpd-mysqlcd / opt/vi nginx.yml- hosts: web remote_user: root roles:-role: nginxansible web-a "rpm-Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm"ansible-playbook nginx.yml"