nginx+proxy+nginx+php+redis
[root@61 ansible_admin]# tree
├── ansible.cfg ├── conf │ ├── memcached.j2 │ ├── nginx.conf.j2 │ ├── phpadmin.com.conf.j2 │ ├── php.ini.j2 │ ├── php_www.conf.j2 │ ├── proxy_phpadmin.com.conf.j2 │ └── redis.conf.j2 ├── hosts ├── host_vars ├── lb.yml ├── nginx.conf.j2 ├── nginx.yml ├── phpMyAdmin-5.0.2-all-languages.zip ├── redis.yml └── web.yml
vim redis.yml
- hosts: dbtasks:- name: Installed Redis Serveryum:name: redisstate: present- name: Configure Redis Servercopy:src: ./conf/redis.conf.j2dest: /etc/redis.confnotify: Restart Redis Server- name: Started Redis Serversystemd:name: redisstate: startedenabled: yeshandlers:- name: Restart Redis Serversystemd:name: redisstate: restarted
vim yum.yml
- name: Installed PHP7.1yum:name: "{{ packages }}"state: presentvars:packages:- php71w- php71w-cli- php71w-common- php71w-devel- php71w-embedded- php71w-gd- php71w-mcrypt- php71w-mbstring- php71w-pdo- php71w-xml- php71w-fpm- php71w-mysqlnd- php71w-opcache- php71w-pecl-memcached- php71w-pecl-redis- php71w-pecl-mongodb
vim web.yml
- hosts: webserverstasks:#1.安装Nginx php- name: Installed Nginx PHP7.1include: ./yum.yml#2.复制nginx,php配置文件- name: Configure Nginx Php confcopy:src: "{{ item.src }}"dest: "{{ item.dest }}"loop:- { src: ./conf/nginx.conf.j2, dest: /etc/nginx/nginx.conf }- { src: ./conf/php.ini.j2, dest: /etc/php.ini }- { src: ./conf/php_www.conf.j2, dest: /etc/php-fpm.d/www.conf }- { src: ./conf/phpadmin.com.conf.j2, dest: /etc/nginx/conf.d/phpadmin.com.conf }notify:- Restart Nginx Server- Restart PHP Server- name: Create Group WWWgroup:name: wwwgid: 666- name: Create User WWWuser:name: wwwuid: 666group: wwwshell: /sbin/nologincreate_home: no#3.根据配置文件初始化- name: Init Nginx Virtual Hostfile:path: /ansible_codestate: directoryowner: wwwgroup: wwwrecurse: yes#4.拷贝代码- name: Copy Codeunarchive:src: ./phpMyAdmin-5.0.2-all-languages.zipdest: /ansible_code/owner: wwwgroup: www#5.启动服务- name: Started Nginx Serversystemd:name: "{{ item }}"state: startedenabled: yesloop:- nginx- php-fpm#6.只要配置变更则触发重启handlers:- name: Restart Nginx PHP Serversystemd:name: "{{ item }}"state: restartedloop:- nginx- php-fpmm lb.yml- hosts: lbtasks:#1.安装- name: Installed Nginx Serveryum:name: nginxstate: present#2.配置- name: Configure Nginx.confcopy:src: ./conf/nginx.conf.j2dest: /etc/nginx/nginx.confnotify: Restart Nginx Server- name: Init Nginx Groupgroup:name: wwwgid: 666- name: Init Nginx Useruser:name: wwwuid: 666group: wwwshell: /sbin/nologincreate_home: no#3.负载均衡的虚拟主机- name: Configure Nginx Load filecopy:src: ./conf/proxy_phpadmin.com.conf.j2dest: /etc/nginx/conf.d/proxy_phpadmin.com.confnotify: Restart Nginx Server#4.启动nginx- name: Systemd Nginx Serversystemd:name: nginxstate: startedenabled: yeshandlers:- name: Restart Nginx Serversystemd:name: nginxstate: restarted
