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: db
tasks:
- name: Installed Redis Server
yum:
name: redis
state: present
- name: Configure Redis Server
copy:
src: ./conf/redis.conf.j2
dest: /etc/redis.conf
notify: Restart Redis Server
- name: Started Redis Server
systemd:
name: redis
state: started
enabled: yes
handlers:
- name: Restart Redis Server
systemd:
name: redis
state: restarted
vim yum.yml
- name: Installed PHP7.1
yum:
name: "{{ packages }}"
state: present
vars:
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: webservers
tasks:
#1.安装Nginx php
- name: Installed Nginx PHP7.1
include: ./yum.yml
#2.复制nginx,php配置文件
- name: Configure Nginx Php conf
copy:
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 WWW
group:
name: www
gid: 666
- name: Create User WWW
user:
name: www
uid: 666
group: www
shell: /sbin/nologin
create_home: no
#3.根据配置文件初始化
- name: Init Nginx Virtual Host
file:
path: /ansible_code
state: directory
owner: www
group: www
recurse: yes
#4.拷贝代码
- name: Copy Code
unarchive:
src: ./phpMyAdmin-5.0.2-all-languages.zip
dest: /ansible_code/
owner: www
group: www
#5.启动服务
- name: Started Nginx Server
systemd:
name: "{{ item }}"
state: started
enabled: yes
loop:
- nginx
- php-fpm
#6.只要配置变更则触发重启
handlers:
- name: Restart Nginx PHP Server
systemd:
name: "{{ item }}"
state: restarted
loop:
- nginx
- php-fpm
m lb.yml
- hosts: lb
tasks:
#1.安装
- name: Installed Nginx Server
yum:
name: nginx
state: present
#2.配置
- name: Configure Nginx.conf
copy:
src: ./conf/nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify: Restart Nginx Server
- name: Init Nginx Group
group:
name: www
gid: 666
- name: Init Nginx User
user:
name: www
uid: 666
group: www
shell: /sbin/nologin
create_home: no
#3.负载均衡的虚拟主机
- name: Configure Nginx Load file
copy:
src: ./conf/proxy_phpadmin.com.conf.j2
dest: /etc/nginx/conf.d/proxy_phpadmin.com.conf
notify: Restart Nginx Server
#4.启动nginx
- name: Systemd Nginx Server
systemd:
name: nginx
state: started
enabled: yes
handlers:
- name: Restart Nginx Server
systemd:
name: nginx
state: restarted