Ansible部署nginx-mysql-rsync-nfs-keepalived

第1章 ansible安装
1.1 创建密钥对

ssh-keygen -t dsa  -P

1.2 把生成的锁头发送给想要控制的服务器

ssh-copy-id -i /root/.ssh/id_dsa.pub 172.16.1.41

1.3 安装epel源

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install ansible

1.4 ansible的配置文件

/etc/ansible/ansible.cfg        ansible主配置文件
Invertory: /etc/ansible/hosts   ansible的hosts文件,放置管理主机的ip地址

第2章 一键部署期中架构
2.1 一键安装rsync服务

cat /etc/ansible/ansible-playbook/rsync.yml
#install rsync_server
- hosts: 172.16.1.41                            服务端配置
  tasks: 
    - name: rsync_server
      copy: src=/etc/ansible/rsync_conf/rsyncd.conf dest=/etc/   
将rsync的配置文件从本地拷贝到rsync服务器
    - name: create user
      shell: useradd -s /sbin/nologin -M rsync    创建用于管理备份目录的用户
    - name: create dir backyp
      file: dest=/backup state=directory owner=rsync group=rsync   
创建备份目录并修改目录的所有者和所属组为rsync
    - name: create authentication
      shell: echo "rsync_backup:123456" >/etc/rsync.password    创建认证文件
    - name: to grant authorization
      shell: chmod 600 /etc/rsync.password      修改认证文件的权限为600
    - name: start rsync
      shell: /usr/bin/rsync –daemon            以daemon的方式启动rsync服务
- hosts: 172.16.1.31                            客户端配置
  tasks:
    - name: create password file
      shell: echo 123456 >/etc/rsync.password    创建存放密码的文件
    - name: shouquan
      shell: chmod 600 /etc/rsync.password       修改密码文件的权限为600
    - name: create data                          创建测试目录/data
      file: dest=/data state=directory

2.1.1 rsync配置文件

[root@m01 rsync_conf]# cat rsyncd.conf 
uid = rsync             指定用户为rsync
gid = rsync            指定所属组为rsync
use chroot = no
max connections = 200  指定最大连接数
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24   指定那些主机可以访问
auth users = rsync_backup     用于认证的虚拟用户
secrets file = /etc/rsync.password   用户认证的虚拟用户的密码文件
[backup] 
path = /backup/                      用于备份的目录

2.2 一键安装nfs服务

#install nfs_server
- hosts: 172.16.1.31                 服务端配置
  tasks:
    - name: install nfs-utils rpcbind
      yum: name=nfs-utils,rpcbind       安装nfs和rpc
    - name: copy configuration file
      copy: src=/etc/ansible/nfs_conf/exports dest=/etc/exports  
从本地将nfs的配置文件拷贝到nfs服务端
    - name: create user_www
      user: name=www createhome=no shell=/sbin/nologin uid=888    创建管理共享目录的指定用户www
    - name: create dir data
      file: dest=/data state=directory owner=www group=www  创建共享的目录并修改所有者和所属组为www
    - name: start rpc_server
      shell: /etc/init.d/rpcbind start         启动rpc服务
    - name: start nfs_server
      shell: /etc/init.d/nfs start             启动nfs服务
- hosts: 172.16.1.41                           客户端配置
  tasks:
    - name: install nfs rpc
      yum: name=nfs-utils,rpcbind     安装nfs和rpc服务,不安装不能挂载不能使用showmount
    - name: create user_www
      user: name=www createhome=no shell=/sbin/nologin uid=888   创建用户,和服务端的用于一样
    - name: mount data_dir
      mount: name=/mnt src=172.16.1.31:/data fstype=nfs state=mounted   
将共享目录/data挂载到客户端的/mnt目录中

2.2.1 nfs配置文件

[root@m01 nfs_conf]# cat exports 
/data 172.16.1.0/24(rw,sync,anonuid=888,anongid=888)

2.3 一键安装sersync服务

#sersync_server install
- hosts: 172.16.1.31               服务端配置
  tasks:
    - name: create /home/tools
      file: dest=/home/tools state=directory   创建用于存放软件的目录
    - name: download sersync
      shell: cd /home/tools/ && wget https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz  下载sersync软件
    - name: decompression sersync
      shell: cd /home/tools/ && /bin/tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/    解压下载好的软件
    - name: move sersync
      shell: mv /usr/local/GNU-Linux-x86 /usr/local/sersync  修改GNU-Linux-x86目录为sersync目录
    - name: move confxml
      shell: mv /usr/local/sersync/confxml.xml /usr/local/sersync/confxml.xml.bak 
备份sersync的原配置文件
    - name: copy confxml.xml
      copy: src=/etc/ansible/sersync_conf/sersync/confxml.xml dest=/usr/local/sersync/ mode=755
拷贝本地已修改好的sersync的配置文件到sersync服务端
    - name: start sersync
      shell: /usr/local/sersync/sersync2 -rdo /usr/local/sersync/confxml.xml  启动sersync服务
#-r  启动时先和远端同步一下
#-d  以daemon的方式启动sersync服务
#-o  指定sersync的配置文件

2.3.1 sersync主要配置文件如下

<localpath watch="/data/">       #监控目录
    <remote ip="172.16.1.41" name="backup"/>   #备份服务器地址及备份目录
    <!--<remote ip="192.168.8.39" name="tongbu"/>-->
    <!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
    <commonParams params="-artuz"/>    #备份参数
    <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>   #备份用户及密码
    <userDefinedPort start="false" port="874"/><!-- port=874 -->
    <timeout start="false" time="100"/><!-- timeout=100 -->
    <ssh start="false"/>
</rsync>

2.4 一键安装mysql服务

#mysql_server install
- hosts: 172.16.1.51
  tasks:
    - name: create useradd mysql             创建管理数据库的用户mysql
      user: name=mysql createhome=no shell=/sbin/nologin
    - name: create /home/tools
      file: dest=/home/tools state=directory  创建存放软件的目录
    - name: download mysql
      shell: cd /home/tools && wget https://downloads.mysql.com/archives/get/file/mysql-5.6.32-linux-glibc2.5-x86_64.tar.gz        下载mysql软件
    - name: decompression nginx
      shell: cd /home/tools && tar -xf mysql-5.6.32-linux-glibc2.5-x86_64.tar.gz   解压mysql软件
    - name: create application
      file: dest=/application/ state=directory  创建application目录
    - name: move mysql
      shell: cd /home/tools && mv mysql-5.6.32-linux-glibc2.5-x86_64 /application/mysql-5.6.32
移动mysql软件到/application/目录下
    - name: Soft connection
      file: src=/application/mysql-5.6.32/ dest=/application/mysql state=link 创建软连接,方便管理
    - name: copy conf
      shell: cp /application/mysql/support-files/my-default.cnf /etc/my.cnf  复制mysql的主配置文件
    - name: create /application/mysql/data
      file: dest=/application/mysql/data state=directory owner=mysql group=mysql 
创建mysql的数据目录
    - name: Initialization mysql     初始化mysql数据库
      shell: /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql
    - name: copy start_file          复制mysql的启动文件
      shell: cd /application/mysql && cp support-files/mysql.server /etc/init.d/mysqld
    - name: Add execute authority
      shell: chmod +x /etc/init.d/mysqld   给启动文件执行权限
    - name: replace configure_file
      shell: sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld   修改mysql原配置文件的路径
    - name: start mysql
      shell: /etc/init.d/mysqld start  启动mysql服务
    - name: Set the MySQL password     为mysql设置密码
      shell: /application/mysql/bin/mysqladmin -uroot password '123456’
    - name: Creating WordPress databases and WordPress users
      shell: /application/mysql/bin/mysql -uroot -p123456 -e "create database wordpress;grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456'"
创建wordpress数据库和wordpress用户
    - name: set environment variable
      shell: echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile  将mysql加入环境变量
    - name: source /etc/profile
      shell: source /etc/profile   使变量生效

2.5 一键安装nginx服务

#nginx_server install
- hosts: 172.16.1.8
  tasks:
    - name: yum pcre-devel,pcre,openssl-devel,openssl    安装nginx依赖包
      yum: name=pcre-devel,pcre,openssl-devel,openssl
    - name: create /home/tools/                           创建安装目录
      file: dest=/home/tools/ state=directory
    - name: create useradd ningx                          创建运行nginx 的用户
      user: name=nginx createhome=no shell=/sbin/nologin
    - name: download nginx
      shell: cd /home/tools/ && wget http://nginx.org/download/nginx-1.10.3.tar.gz  下载nginx软件
    - name: decompression nginx
      shell: cd /home/tools/ && tar -xf nginx-1.10.3.tar.gz        解压nginx软件
    - name: To configure nginx
      shell: cd /home/tools/nginx-1.10.3 && ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.10.3/ --with-http_stub_status_module --with-http_ssl_module && make && make install   #配置并安装nginx
    - name: Soft connection
      file: src=/application/nginx-1.10.3/ dest=/application/nginx state=link 创建软连接,方便管理
    - name: start nginx
      shell: /application/nginx/sbin/nginx   启动nginx服务

2.6 一键安装php服务

#php_server install
- hosts: 172.16.1.8
  tasks:
    - name: yum rely on        yum安装php依赖包
      yum: name=zlib-devel,libxml2-devel,libjpeg-devel,libjpeg-turbo-devel,freetype-devel,libpng-devel,gd-devel,libcurl-devel,libxslt-devel
    - name: install libiconv   安装php依赖包
      shell: cd /home/tools && wget https://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz
    - name: decompression libiconv
      shell: cd /home/tools && tar -xf libiconv-1.14.tar.gz
    - name: To configure libiconv
      shell: cd /home/tools/libiconv-1.14 && ./configure --prefix=/usr/local/libiconv && make && make install
    - name: install epel source     安装epel源
      shell: wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
    - name: yum libmcrypt-devel
      yum: name=libmcrypt-devel,mhash,mcrypt
    - name: download php-5.5.32    下载php软件
      shell: cd /home/tools/ && wget http://ftp.ntu.edu.tw/php/distributions/php-5.5.32.tar.gz
    - name: install php
      shell: cd /home/tools/ && tar -xf php-5.5.32.tar.gz   解压php软件
    - name: Soft connection
      shell: ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
    - name: create phar.phar
      shell: touch /home/tools/php-5.5.32/ext/phar/phar.phar
    - name: get into php-5.5.32 && To configure   #配置并安装php软件
       shell: cd /home/tools/php-5.5.32 && ./configure --prefix=/application/php-5.5.32 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp --enable-opcache=no && make && make install
    - name: Soft connection php5.5.32     创建软连接,方便管理
      file: src=/application/php-5.5.32 dest=/application/php state=link
    - name: copy php.ini-production       复制php配置文件
      shell: cp /home/tools/php-5.5.32/php.ini-production /application/php/lib/php.ini
    - name: copy php-fpm.conf.default to php-fpm.conf     复制php配置文件
      shell: cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf
    - name: copy init.d/php-fpm to php-fpm     复制php启动文件
      shell: cp /home/tools/php-5.5.32/sapi/fpm/init.d/php-fpm /etc/init.d/php-fpm
    - name: Add execute authority
      shell: chmod +x /etc/init.d/php-fpm   给启动文件执行权限
    - name: start php-fpm
      shell: /etc/init.d/php-fpm start      启动php服务

2.7 一键安装lb负载均衡

#lb_server install
- hosts: 172.16.1.5
  tasks:
    - name: yum pcre-devel,pcre,openssl,openssl-devel
      yum: name=pcre-devel,pcre,openssl,openssl-devel
    - name: create /home/tools/
      file: dest=/home/tools/ state=directory
    - name: create useradd ningx
      user: name=nginx createhome=no shell=/sbin/nologin
    - name: download nginx
      shell: cd /home/tools/ && wget http://nginx.org/download/nginx-1.10.3.tar.gz
    - name: decompression nginx
      shell: cd /home/tools/ && tar -xf nginx-1.10.3.tar.gz
    - name: To configure nginx
      shell: cd /home/tools/nginx-1.10.3 && ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.10.3/ --with-http_stub_status_module --with-http_ssl_module && make && make install
    - name: Soft connection
      file: src=/application/nginx-1.10.3/ dest=/application/nginx state=link
    - name: move nginx_conf
      shell: mv /application/nginx/conf/nginx.conf /application/nginx/conf/nginx.conf.bak
    - name: copy nginx_conf
      shell: cp /etc/ansible/lb_conf/nginx.conf /application/nginx/conf/
    - name: start nginx
      shell: /application/nginx/sbin/nginx
#lb_server install
- hosts: 172.16.1.6
  tasks:
    - name: yum pcre-devel,pcre,openssl,openssl-devel
      yum: name=pcre-devel,pcre,openssl,openssl-devel
    - name: create /home/tools/
      file: dest=/home/tools/ state=directory
    - name: create useradd ningx
      user: name=nginx createhome=no shell=/sbin/nologin
    - name: download nginx
      shell: cd /home/tools/ && wget http://nginx.org/download/nginx-1.10.3.tar.gz
    - name: decompression nginx
      shell: cd /home/tools/ && tar -xf nginx-1.10.3.tar.gz
    - name: To configure nginx
      shell: cd /home/tools/nginx-1.10.3 && ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.10.3/ --with-http_stub_status_module --with-http_ssl_module && make && make install
    - name: Soft connection
      file: src=/application/nginx-1.10.3/ dest=/application/nginx state=link
    - name: move nginx_conf
      shell: mv /application/nginx/conf/nginx.conf /application/nginx/conf/nginx.conf.bak
    - name: copy nginx_conf
      shell: cp /etc/ansible/lb_conf/nginx.conf /application/nginx/conf/
    - name: start nginx
      shell: /application/nginx/sbin/nginx

2.7.1 lb配置文件

cat /application/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream www_server_pools {
              server 10.0.0.8:80 weight=1;
              server 10.0.0.7:80 weight=1;
              server 10.0.0.9:80 weight=1;
   }
    server {
        listen       80;
        server_name  www.tiandi.com;
        location / {
        proxy_pass http://www_server_pools;
        }
     }
}

2.8 一键安装keepalived高可用

- hosts: 172.16.1.5
  tasks:
    - name: yum keepalived
      yum: name=keepalived
    - name: copy conf_keepalived
      copy: src=/etc/ansible/keepalived_conf/keepalived.conf dest=/etc/keepalived/
    - name: start keepalived
      shell: /etc/init.d/keepalived start
- hosts: 172.16.1.6
  tasks:
    - name: yum keepalived
      yum: name=keepalived
    - name: copy conf_keepalived
      copy: src=/etc/ansible/keepalived_bak_conf/keepalived.conf dest=/etc/keepalived/
    - name: start keepalived
      shell: /etc/init.d/keepalived start

2.8.1 主keepalived配置文件

cat /etc/ansible/keepalived_conf/keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id lb01
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
virtual_router_id 55
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.88/24 dev eth0 label eth0:1
    }
}

2.8.2 备keepalived配置文件

cat /etc/ansible/ keepalived_bak_conf /keepalived.conf
! Configuration: command not found
bal_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id lb02
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 55
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.88/24 dev eth0 label eth0:1
    }
}

2.9 一键安装pptp_vpn服务

#pptp_vpn_server install
- hosts: 172.16.1.62
  tasks:
    - name: Set kernel forwarding
      shell: sed -i 's#net.ipv4.ip_forward = 0#net.ipv4.ip_forward = 1#g' /etc/sysctl.conf
    - name: Configuration effective
      shell: sysctl -p
    - name: install epel_source
      shell: wget -O /etc/yum.repos.d/epel.repo  http://mirrors.aliyun.com/repo/epel-6.repo
    - name: Install PPTP
      shell: yum -y install pptpd
    - name: Modify configuration file
      shell: sed -i '$a localip 10.0.0.62\nremoteip 172.16.1.100-200' /etc/pptpd.conf
    - name: start pptp
      shell: /etc/init.d/pptpd start
    - name: Add user
      shell: echo -e 'test * 123456 *' >>/etc/ppp/chap-secrets
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
为了减轻多服务器配置和操作工作量以及安全性,特研究此课题,理论上可以同步所有想同步的文件,并且做到一键操作,不需要切换用户,不需要多次操作脚本,中途不需要输入任何字。 1, hosts文件 2, play.yml文件 剧本文件,按标准放到tasks文件夹内,因后面脚本写了路径,如果不愿意放tasks文件夹,需要改后面sh脚本路径参数 3, rsync_notice.py文件 钉钉机器人发送消息文件,此文件放在tools文件夹内,会调用备份日志进行分析,过滤后,发送到钉钉群内。各位同事可修改文件里的Webhoo为自己的机器人key 4, deploy.sh 文件 调用py钉钉文件发消息,并且处理备份日志,删除近期日志等后续事宜,请放在tools文件夹内 1.3.3. 功能基本介绍 1, 在对应脚本里基本都有注释,这里简单介绍下 2, 剧本文件需要在主控机器(备份机器),root用户下运行,运行一次即可,后续sh及py脚本会自动处理。一键搞定所有事情,中途无需手动干预; 3, 自行修改host文件为自己项目地址,bak为备份文件服务器,为安全起见,hosts文件进行了vault加密,密码123456,运行剧本文件,请加—ask-vault-pass 4, 再次提醒,在脚本运行完成后,为保险起见,可将hosts文件中的root密码删除,或修改复杂密码,不会影响后续同步功能。 5, 剧本流程介绍: 1) 主控被控端安装rsync及相关依赖软件; 2) 主控与被控端添加备份用户,rsync; 3) 主控端即备份服务器建立备份文件夹,设置归属用户; 4) 主控及被控端自动切换rsync用户,使用rsync用户配置免密访问所有被控端,即便服务器被黑,rsync用户访问也做不了什么; 5) 主控端即备份服务器使用rsync用户增加同步、日志记录、钉钉发送消息等定时任务; 6) 定时任务里各个需要同步的源地址及项目名称,请自行修改; 7) 日志为叠加记录,钉钉消息发完后,会按日期进行备份,同时删除原日志,因为钉钉消息每天都发,避免冗余数据; 6, 钉钉消息脚本介绍: 1) 访问实时备份日志,考虑到钉钉消息,只需要知道同步是否成功,其余数据不关心,所以读取后,进行数据处理,取出服务器地址、成功标识,或未成功标识; 2) 调用钉钉机器人接口,采取markdown形式,此形式可以定义一个固定的标题,比如:rsync同步情况汇总,这样在钉钉机器人安全设置里,只需要将标题设为关键字即可,具体发送内容千奇百怪也没关系。另外两种方式各有弊端,未研究。
非常感谢您的提问,我将为您详细描述 ansible-varnish-nginx-php-fpm-ftp-mysql部署流程。 前置条件: - 安装 Ansible 工具 - 所有主机都配置好 SSH 免密登录 - 所有主机都已安装 Python 2.x 或 Python 3.x 步骤: 1. 编写 Ansible 配置文件 创建一个名为 inventory 的文件,并在其中定义要部署的主机列表和相关变量: ``` [web] webserver ansible_host=192.168.1.10 ansible_user=<your_user> ansible_ssh_private_key_file=<your_ssh_key> dbserver ansible_host=192.168.1.11 ansible_user=<your_user> ansible_ssh_private_key_file=<your_ssh_key> [web:vars] nginx_version=1.14.1 php_version=7.2 mysql_version=5.7 ``` 2. 编写 Ansible Playbook 创建一个名为 playbook.yml 的文件,并编写 Ansible Playbook。以下是一个示例 Playbook,包含安装和配置 varnish、nginx、PHP-FPM、FTP 和 MySQL。 ``` - hosts: web become: true vars_files: - vars.yml tasks: # 安装 Varnish - name: Install Varnish yum: name: varnish state: present # 安装 Nginx - name: Install Nginx yum: name: nginx state: present notify: - Restart Nginx # 配置 Nginx - name: Configure Nginx template: src: templates/nginx.conf.j2 dest: /etc/nginx/nginx.conf notify: - Restart Nginx # 安装 PHP-FPM - name: Install PHP-FPM yum: name: php-fpm state: present notify: - Restart PHP-FPM # 配置 PHP-FPM - name: Configure PHP-FPM template: src: templates/php-fpm.conf.j2 dest: /etc/php-fpm.conf notify: - Restart PHP-FPM # 安装 FTP - name: Install FTP yum: name: vsftpd state: present notify: - Restart FTP # 配置 FTP - name: Configure FTP template: src: templates/vsftpd.conf.j2 dest: /etc/vsftpd/vsftpd.conf notify: - Restart FTP # 安装 MySQL - name: Install MySQL yum: name: mysql-community-server state: present notify: - Start MySQL # 配置 MySQL - name: Configure MySQL template: src: templates/my.cnf.j2 dest: /etc/my.cnf notify: - Start MySQL handlers: # 重启 Nginx - name: Restart Nginx systemd: name: nginx state: restarted # 重启 PHP-FPM - name: Restart PHP-FPM systemd: name: php-fpm state: restarted # 重启 FTP - name: Restart FTP systemd: name: vsftpd state: restarted # 启动 MySQL - name: Start MySQL systemd: name: mysqld state: started ``` 3. 准备模板文件 创建模板文件,用于生成配置文件。以下是模板文件示例代码: nginx.conf.j2 ``` user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; use epoll; } 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; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } include /etc/nginx/conf.d/*.conf; } ``` php-fpm.conf.j2 ``` [global] pid = /var/run/php-fpm/php-fpm.pid error_log = /var/log/php-fpm/error.log emergency_restart_threshold = 5 emergency_restart_interval = 1m process_control_timeout = 10 daemonize = no [www] user = nginx group = nginx listen = 127.0.0.1:9000 listen.owner = nginx listen.group = nginx listen.mode = 0660 pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 pm.max_requests = 500 ``` vsftpd.conf.j2 ``` anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES xferlog_file=/var/log/xferlog xferlog_std_format=YES chroot_local_user=YES allow_writeable_chroot=YES local_root=/var/www/html/ listen=YES listen_ipv6=NO pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES ``` my.cnf.j2 ``` [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql symbolic-links=0 skip-external-locking key_buffer_size = 16M max_allowed_packet = 256M table_open_cache = 16384 sort_buffer_size = 512K net_buffer_length = 16K myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size = 16M query_cache_limit = 1M log-bin=mysql-bin binlog_format=ROW server-id=1 innodb_buffer_pool_size = 256M innodb_log_file_size = 64M default-storage-engine=innodb character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci [client] socket=/var/lib/mysql/mysql.sock [mysql] socket=/var/lib/mysql/mysql.sock ``` 4. 运行 Ansible Playbook 运行以下命令来运行 Ansible Playbook: ``` $ ansible-playbook -i inventory playbook.yml ``` 此命令将在指定主机上按顺序执行 Playbook 中的每个任务,安装和配置所有必需的软件包和服务,最终实现 ansible-varnish-nginx-php-fpm-ftp-mysql部署。 感谢您提供的问题,希望可以帮到您!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维那些事~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值