Ansible-完成php服务部署

0.基础环境搭建

1. roles/php/tasks/main.yml

# 安装php及扩展
yum -y install php72w \
php72w-cli \
php72w-fpm \
php72w-common \
php72w-devel \
php72w-embedded \
php72w-gd \
php72w-mbstring \
php72w-mysqlnd \
php72w-opcache \
php72w-pdo  \
php72w-xml  \
php72w-mysqlnd  \
php72w-pecl-memcached \
php72w-pecl-mongodb   \
php72w-pecl-redis     \
php72w-pecl-zip       \
php72w-bcmath

# 修改配置文件
sed -i '/^user =/cuser = www' /etc/php-fpm.d/www.conf
sed -i '/^group =/cgroup = www' /etc/php-fpm.d/www.conf

# 启动服务并加入开机自启
systemctl start php-fpm
systemctl enable php-fpm
- name: Install php and depend
  yum:
    name: "{{ item }}"
    state: installed
  loop:
    - php72w
    - php72w-cli
    - php72w-fpm
    - php72w-common
    - php72w-devel
    - php72w-embedded
    - php72w-gd
    - php72w-mbstring
    - php72w-mysqlnd
    - php72w-opcache
    - php72w-pdo
    - php72w-xml
    - php72w-mysqlnd
    - php72w-pecl-memcached
    - php72w-pecl-mongodb
    - php72w-pecl-redis
    - php72w-pecl-zip
    - php72w-bcmath

- name: Modify www.conf
  copy:
    src: www.conf
    dest: /etc/php-fpm.d/www.conf
  notify: Restart php

- name: Modify php.ini
  copy:
    src: php.ini
    dest: /etc/php.ini
  notify: Restart php

- name: Start php
  systemd:
    name: php-fpm
    state: started
    enabled: yes

2.roles/php/handlers/main.yml

# 重启php使配置文件生效
systemctl restart php-fpm
- name: Restart php
  systemd:
    name: php-fpm
    state: restarted

3.roles/php/files/php.ini

...
..
.
[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
session.save_handler = redis
session.save_path = 'tcp://172.16.1.51:6379?weight=1&timeout=2.5'
.
..
...

4.roles/php/files/www.conf

[www]
user = www
group = www
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

你可能感兴趣的:(Ansible-完成php服务部署)