1.group_vars/all
#php packages
packages:
- nginx
- php71w
- php71w-cli
- php71w-common
- php71w-devel
- php71w-embedded
- php71w-gd
- php71w-mbstring
- php71w-pdo
- php71w-xml
- php71w-fpm
- php71w-mysqlnd
- php71w-opcache
- php71w-mcrypt
- php71w-pecl-memcached
- php71w-pecl-mongodb
- php71w-pecl-redis
- php71w-pecl-zip
- php71w-bcmath
#web
redis_server_ip: 172.16.1.51
redis_server_port: 6379
web_process_user: www
web_process_group: www
cloud_server_name: ansible.oldxu.com
cloud_server_port: 80
cloud_code_path: /code/ansible
#proxy
cloud_proxy_port: 80
2.kodcloud-proxy
(1)handlers
main.yml
- name: Restart Nginx Server
systemd:
name: nginx
state: restarted
(2)mets
main.yml
dependencies:
- nginx-web
(3)tasks
main.yml
- name: Create Nginx Proxy VirtHost Configure
template:
src: “{{ item.src }}”
dest: “{{ item.dest }}”
loop:- { src: proxy_params.j2 , dest: /etc/nginx/proxy_params }
- { src: proxy_ansible.oldxu.com.conf.j2 , dest: /etc/nginx/conf.d/proxy_ansible.oldxu.com.conf }
notify: Restart Nginx Server
(4)templates
proxy_ansible.xxx.com.comf.j2
upstream {{ cloud_server_name }} {
{% for host in groups[‘web’] %}
server {{ host }}:{{ cloud_server_port }};
{% endfor %}
}
server {
listen {{ cloud_proxy_port }};
server_name {{ cloud_server_name }};
location / {
proxy_pass http://{{ cloud_server_name }};
include proxy_params;
}
}
proxy_param.j2
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;
3.kodcloud-web
(1)files
解压包
(2)handles
main.yml
- name: Restart Nginx Server
systemd:
name: nginx
state: restarted
(3)meta
main.yml
dependencies:
- nginx-web
- php
(4)tasks
main.yml
- name: Create Nginx VirtHost Configure
template:
src: ansible.oldxu.com.conf.j2
dest: /etc/nginx/conf.d/ansible.oldxu.com.conf
notify: Restart Nginx Server - name: Create Cloud Directory
file:
path: “{{ cloud_code_path }}”
state: directory
owner: “{{ web_process_user }}”
group: “{{ web_process_group }}”
recurse: yes - name: Copy Cloud Code
unarchive:
src: kodexplorer4.40.zip
dest: “{{ cloud_code_path }}”
copy: yes
owner: “{{ web_process_user }}”
group: “{{ web_process_group }}”
creates: “{{ cloud_code_path }}/index.php”
(5)templates
ansible.olx.com.conf.j2
server {
listen {{ cloud_server_port }};
server_name {{ cloud_server_name }};
root {{ cloud_code_path }};
location / {
index index.php;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME documentrootdocument_rootdocumentrootfastcgi_script_name;
include fastcgi_params;
}
}
4.nginx-proxy
(1)
5.nginx-web
(1)handlers
main.yml
- name: Restart Nginx Server
systemd:
name: nginx
state: restarted
(2)tasks
main.yml
- name: Installed Nginx Server
yum:
name: nginx
state: present - name: Configure Nginx Server
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
owner: root
group: root
mode: ‘0644’
notify: Restart Nginx Server - name: Systemd Nginx Server
systemd:
name: nginx
state: started
enabled: yes
(3)templates
nginx.conf.j2
user www;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
6.php
(1)handlers
main.yml
- name: Restart PHP Server
systemd:
name: php-fpm
state: restarted
(2)tasks
main.yml
- name: Installed PHP Server
yum:
name: “{{ packages }}”
state: present - name: Configure PHP Server
template:
src: “{{ item.src }}”
dest: “{{ item.dest }}”
mode: “{{ item.mode }}”
owner: root
group: root
loop:- { src: php.ini.j2 , dest: /etc/php.ini , mode: ‘0644’ }
- { src: php_www.conf.j2 , dest: /etc/php-fpm.d/www.conf , mode: ‘0644’ }
notify: Restart PHP Server
- name: Systemd PHP Server
systemd:
name: php-fpm
state: started
enabled: yes
(3)templates
php.ini.j2
php_www.conf.j2
[www]
user = {{ web_process_user }}
group = {{ web_process_group }}
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
;php_value[session.save_handler] = files
;php_value[session.save_path] = /var/lib/php/session
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
7.redis
(1)handkers
main.yml
- name: Restart Redis Server
systemd:
name: redis
state: restarted
(2)tasks
main.yml
- name: Installed Redis Server
yum:
name: redis
state: present - name: Configure Redis Server
template:
src: redis.conf.j2
dest: /etc/redis.conf
owner: redis
group: root
mode: ‘0640’
notify: Restart Redis Server - name: Systemd Redis Server
systemd:
name: redis
state: started
enabled: yes
(3)templates
redis.conf.j2
8.hosts
[web]
172.16.1.7
172.16.1.8
[nfs]
172.16.1.31
[backup]
172.16.1.41
[db]
172.16.1.51
[lb]
172.16.1.5
9.top.yml
- hosts: db
roles:- { role: redis , tags: redis }
- hosts: web
roles:- role: kodcloud-web
tags: kod
- role: kodcloud-web
- hosts: lb
roles:- role: kodcloud-proxy