ansible +外壳脚本搭建wordpress论坛

  

ansibler +外壳脚本搭建wordpress论坛

ansible作为自动化运维工具,功能模块很多,配合壳脚本可以更好的进行自动化的部署。

环境:

192.168.0.9 #需要部署的LNMP + wordpress的机器

192.168.0.11 # ansible


ansible配置

[root@localhost ansible] # egrep”^ ^ #”/etc/ansible/hosts

[LNMP] 192.168.0.9


php配置文件

lnmp_install文件


软件版本:

1.81 nginx mysql 5.5(百胜安装)

7.31 php wordpress 4.7


ansible yaml文件代码:

-主机:LNMP   remote_user:根   任务:   名称:“创建安装目录”   文件:   路径:/opt/lnmp   状态:目录   名称:“复制nginx_tar.gz”   复制:   src:/opt/lnmp/nginx-1.8.1.tar.gz   桌子:/opt/lnmp   名称:“开始安装nginx”   脚本:/opt/lnmp/nginx_install.sh   名称:“删除mariadb”   百胜:name=mariadb mariadb-server状态=缺席   名称:“安装mariadb”   百胜:name=mariadb mariadb-server=最新状态   名称:“”字段添加到my . cnf中所做   脚本:/opt/lnmp/mysql_admin.sh   名称:“重新启动mysql”   服务:name==mariadb状态重新启动   名称:“创建测试数据库”   命令:mysql -uroot -p123123 - e”滴wordpress数据库,创建数据库wordpress;所有特权授予> # !/bin/bash   # #这是安装nginx bash   nginx_tar=/opt/lnmp/nginx * . gz和   ng_path=/opt/lnmp   如果(nginx_tar美元- e),然后   焦油zxvf nginx_tar - c ng_path美元   其他的   “nginx.tar回响。广州不存在”   fi   #百胜   yum安装- y gcc gcc-c + + autoconf gd-devel automake zlib zlib-devel openssl openssl-devel pcre *   如果[!$ ?情商0];然后   回声“错误yum安装”   出口1   fi   睡5   #配置   cd/opt/lnmp/nginx *   ./configure \   ——prefix=/usr/地方/nginx \   ——用户=nginx \   ——组=nginx \   ——with-http_ssl_module \   ——with-http_gzip_static_module \   ——with-http_image_filter_module \   ——with-http_stub_status_module   如果[$ ?情商0];然后   使,,制作安装   fi   #创建nginx的用户   id nginx   如果[!$ ?情商0];然后   useradd - m - s/sbin/nologin nginx   其他的   userdel - r nginx   useradd - m - s/sbin/nologin nginx   fi   #修改配置文件   nginx_conf_path=/usr/地方/nginx/conf/nginx.conf   猫在$ {nginx_conf_path} & lt; & lt; EOF   worker_processes汽车;   事件{   worker_connections 1024;   }   http {   包括mime.types;   default_type应用程序/八进制;   sendfile> # !/bin/bash   # # PHP安装脚本   #焦油php.tgz   php_tar=/opt/lnmp/php * . gz和   configure_path=/opt/lnmp   如果(php_tar美元- e),然后   焦油zxvf php_tar - c configure_path美元   其他的   “php * . tar回响。广州不存在....”   出口1   fi   #创建php用户   id php   如果[!$ ?情商0];然后   useradd - m - s/sbin/nologin php   其他的   userdel - r php   useradd - m - s/sbin/nologin php   fi   #百胜   yum安装libxml2 libxml2-devel - y   #配置   cd/opt/lnmp/php *   ./configure \   ——prefix=/usr/地方/php7 \   ——with-pdo-mysql=/opt/mysql \   ——enable-mysqlnd \   ——with-pdo-mysql=mysqlnd \   -with-mysqli=mysqlnd \   ——with-mysql-sock=/tmp/mysql。袜子\   ——with-config-file-path=/usr/地方/php7 \   ——enable-fpm \   ——with-jpeg-dir \   ——with-png-dir \   ——with-zlib-dir \   ——与gd   #制作安装   如果[!$ ?情商0];然后   回声“安装错误,请检查配置”   其他的   使,,制作安装   fi

php_restart。sh代码

# !/bin/bash   php_pid=' pgrep php-fpm | wc - l '   如果[$ php_pid eq 0];然后/usr/local/php7/sbin/php-fpm   其他的   killall php-fpm/usr/local/php7/sbin/php-fpm   fi


mysql_admin。sh代码

# !/bin/bash   sed ri/etc/my.cnf“1 a skip-grant-tables”   systemctl重启mariadb   睡眠3   mysql -uroot - e”使用mysql;更新用户设置密码=密码(“123123”),用户=案?冲洗特权;“   sed ri“二维”/etc/my.cnf


安装完成后访问http://192.168.0.9/wordpress/wp-admin配置wordpress

填写完数据库用户名密码之后(数据库主机主机不好使,就使用IP地址),安装完成,以下为登陆界面

ansible +外壳脚本搭建wordpress论坛