Use Ansible to install the deployment Nginx+php+mysql

Source: Internet
Author: User

Premise:

1. The Hosts file has been configured and password-free login

2. The required Yaml file has been uploaded to the main control side

First, using Ansible installation Nginx

1. nginx.yaml file

1 ---2 -Hosts:clong3 Remote_user:root4 Gather_facts:no5 tasks:6 # Install Epel source7 -Name:install epel-release repo8 yum:name=epel-release state=present9 # Install Libselinux-pythonTen -Name:install Libselinux-python One Yum:name=libselinux-python state=present A # Configure the latest stable version of Nginx source - -Name:copy Nginx.repo - Copy:src=nginx.repo Dest=/etc/yum.repos.d/nginx.repo the # update Yum Cache - -name:update Yum cache-1 - Command:yum Clean All - -name:update Yum cache-2 + Command:yum Makecache - # Install Nginx + -Name:install Nginx A Yum:name=nginx state=present at # Open Nginx - -Name:start Nginx - Service:name=nginx state=started Enabled=yes - # Copy nginx configuration file - -name:copy Nginx conf - copy:src=nginx.conf dest=/etc/nginx/nginx.conf backup=yes force=yes in # Verify the configuration file - -Name:check nginx.conf to Shell:/usr/sbin/nginx-t-c/etc/nginx/nginx.conf + # Delete the default default.conf file - -Name:delete default.conf the file:path=/etc/nginx/conf.d/default.conf state=absent * # Copy www site file $ -name:copy www confPanax Notoginseng copy:src=www.conf dest=/etc/nginx/conf.d/www.conf backup=yes force=yes - Notify:restart Nginx the # restart Nginx + Handlers: A -Name:restart Nginx the Service:name=nginx state=restarted +#--syntax-check

2. nginx.conf file

1 user Nginx Nginx;2 worker_processes Auto;3 worker_cpu_affinity Auto;4 5 Error_log/var/log/nginx/error.log warn;6 Pid/var/run/nginx.pid;7 8 Events {9 Use epoll;Ten multi_accept off; One Accept_mutex off; A worker_connections 65535; - } -  the http { - include 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"; A  at Access_log/var/log/nginx/access.log main; -  - server_names_hash_bucket_size; - client_body_timeout; - send_timeout; - large_client_header_buffers 4 32k; in client_max_body_size 8m; - client_header_buffer_size 128k;  to Client_header_timeout 15;  +  - CharSet UTF-8; the server_tokens off; *  $ sendfile on;Panax Notoginseng Sendfile_max_chunk 512k; -  the Tcp_nopush on; + tcp_nodelay on; A   the keepalive_timeout; + keepalive_requests 100000; - reset_timedout_connection on; $   $ fastcgi_connect_timeout; - fastcgi_send_timeout; - fastcgi_read_timeout; the fastcgi_buffer_size 64k; - fastcgi_buffers 4 64k;Wuyi fastcgi_busy_buffers_size 128k; the fastcgi_temp_file_write_size 128k; -  Wu gzip on; - gzip_min_length 10240; About gzip_buffers 4 16k; $ Gzip_http_version 1.1; - gzip_proxied expired No-cache no-store private auth; - gzip_disable "MSIE [1-6]."; - Gzip_comp_level 2; A gzip_types text/plain text/css text/xml text/javascript application/json application/x-javascript application/x ML Application/xml+rss; + gzip_vary on; the      - open_file_cache max=102400 inactive=20s; $ open_file_cache_valid 30s; the open_file_cache_min_uses 1; the open_file_cache_errors on; the      the include/etc/nginx/conf.d/*.conf; -  in}

3. www.conf file

1 server {2 Listen;3 server_name localhost;4     5 Location /{6 root/usr/share/nginx/html;7 index index.php index.html index.htm;8     }9 Ten Location ~ \.php { One root/usr/share/nginx/html; A Fastcgi_pass 127.0.0.1:9000; - Fastcgi_index index.php; - Fastcgi_param script_filename $document _root$fastcgi_script_name; the include Fastcgi_params; -     } - Access_log/var/log/nginx/host.access.log main; -}

4. Nginx.repo file

1 [Nginx] 2 Name=nginx Repo 3 baseurl=http://nginx.org/packages/centos/7/$basearch/ 4 gpgcheck=0 5 enabled=1

Use Ansible to install the deployment Nginx+php+mysql

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.