千家信息网

ansible+shell脚本搭建wordpress论坛

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,ansibler+shell脚本搭建wordpress论坛ansible作为自动化运维工具,功能模块很多,配合shell脚本可以更好的进行自动化的部署。环境:192.168.0.9 #需要部署的LNM
千家信息网最后更新 2026年11月02日ansible+shell脚本搭建wordpress论坛

ansibler+shell脚本搭建wordpress论坛

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

环境:

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文件


软件版本:

nginx 1.81

mysql 5.5 (yum 安装)

php 7.31

wordpress 4.7


ansible yaml文件代码:

- hosts: lnmp  remote_user: root  tasks:  - name: "create install directory"    file:      path: /opt/lnmp      state: directory  - name: "copy nginx_tar.gz"    copy:      src: /opt/lnmp/nginx-1.8.1.tar.gz      dest: /opt/lnmp  - name: "start install nginx"    script: /opt/lnmp/nginx_install.sh  - name: "remove mariadb"    yum: name=mariadb,mariadb-server state=absent  - name: "install mariadb"    yum: name=mariadb,mariadb-server  state=latest  - name: "Adding fields to my.cnf"    script: /opt/lnmp/mysql_admin.sh  - name: "restart mysql"    service: name=mariadb state=restarted  - name: "create test databases"    command: mysql -uroot -p123123 -e "drop database wordpress;create database wordpress;grant all privileges on wordpress.* to 'root'@'192.168.0.9' identified by '123123';flush privileges;"  - name: "copy php tgz"    copy:      src: /opt/lnmp/php-7.3.1.tar.gz      dest: /opt/lnmp  - name: "script php install bash"    script: /opt/lnmp/php_install.sh  - name: "copy php-fpm.conf"    template:      src: /opt/lnmp/php_conf/php-fpm.conf      dest: /usr/local/php7/etc/  - name: "copy php.ini"    template:      src: /opt/lnmp/php_conf/php.ini      dest: /usr/local/php7/  - name: "copy wwww.conf"    copy:      src: /opt/lnmp/php_conf/www.conf      dest: /usr/local/php7/etc/php-fpm.d/  - name: "start php"    script: /opt/lnmp/php_restart.sh  - name: "wordpress.tar.gz copy"    unarchive:      src: /opt/lnmp/wordpress-4.7.4-zh_CN.tar.gz      dest: /var/www/php      mode: 0777      owner: nobody      group: nfsnobody

nginx_install.sh代码

#!/bin/bash##this is nginx install bashnginx_tar=/opt/lnmp/nginx*.gzng_path=/opt/lnmpif [ -e $nginx_tar ];thentar zxvf $nginx_tar -C $ng_pathelseecho "nginx.tar.gz does not exist"fi#yumyum install -y gcc gcc-c++ autoconf gd-devel automake zlib zlib-devel openssl openssl-devel pcre*if [ ! $? -eq 0 ];then     echo "error yum install"     exit 1fisleep 5#configurecd /opt/lnmp/nginx* ./configure \--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-http_ssl_module \--with-http_gzip_static_module \--with-http_image_filter_module \--with-http_stub_status_moduleif [ $? -eq 0 ];thenmake && make installfi#create nginx userid nginxif [ ! $? -eq 0 ];then   useradd -M -s /sbin/nologin nginxelse   userdel -r nginx   useradd -M -s /sbin/nologin nginxfi#Modify configuration filesnginx_conf_path=/usr/local/nginx/conf/nginx.confcat >${nginx_conf_path} < ${www_path}/test.html#check nginx pidnginx_pid=`pgrep nginx | wc -l`if [ $nginx_pid -eq 0 ];then  /usr/local/nginx/sbin/nginx  echo "nginx has started...."else  killall nginx  /usr/local/nginx/sbin/nginx  echo "nginx has restart..."fi

php_install.sh代码

#!/bin/bash##PHP install script#Tar php.tgzphp_tar=/opt/lnmp/php*.gzconfigure_path=/opt/lnmpif [ -e $php_tar ];then   tar zxvf  $php_tar -C $configure_pathelse  echo "php*.tar.gz does not exist...."  exit 1fi#create php userid phpif [ ! $? -eq 0 ];then  useradd -M -s /sbin/nologin phpelse  userdel -r php  useradd -M -s /sbin/nologin phpfi#yumyum install libxml2 libxml2-devel -y#configurecd /opt/lnmp/php*./configure \--prefix=/usr/local/php7 \--with-pdo-mysql=/opt/mysql \--enable-mysqlnd \--with-pdo-mysql=mysqlnd \-with-mysqli=mysqlnd \--with-mysql-sock=/tmp/mysql.sock \--with-config-file-path=/usr/local/php7 \--enable-fpm \--with-jpeg-dir \--with-png-dir \--with-zlib-dir \--with-gd#make installif [ ! $? -eq 0 ];then   echo "make install error,please check configure"else  make && make installfi

php_restart.sh 代码

#!/bin/bashphp_pid=`pgrep php-fpm | wc -l`if [ $php_pid -eq 0 ];then   /usr/local/php7/sbin/php-fpmelse  killall php-fpm   /usr/local/php7/sbin/php-fpmfi


mysql_admin.sh 代码

#!/bin/bashsed -ri "1a skip-grant-tables" /etc/my.cnfsystemctl restart mariadbsleep 3mysql -uroot -e "use mysql;update user set password=password('123123') where user='root'; flush privileges;"sed -ri "2d" /etc/my.cnf


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

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

代码 文件 配置 脚本 数据 数据库 自动化 论坛 不好 主机 功能 功能模块 地址 密码 工具 机器 模块 版本 环境 用户 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网科技的发展 平安科技 互联网 朗涯互联网科技 上海喔噻互联网科技 有木互联网科技 赫美联合互联网科技 互联网 科技服务平台 中国互联网金融科技基金 四个字互联网科技公司取名 隆华科技工业互联网 广州优美互联网科技 昭通云南众福互联网科技有限公司 威龙国际互联网科技公司 国大互联网教育科技有限公司薪资 从那以后互联网科技有限公司 卡尔迅互联网科技有限公司 互联网时代科技型公司的机会 利用互联网等科技手段 山东亿川互联网科技有限责任公司 如何强化互联网金融科技 互联网是不是新科技 极限挑战互联网科技 融势互联网科技 丰台科技园 互联网公司 科技大学互联网专业好不好 互联网科技扶贫时间 雨阳互联网卡科技有限公司 昆明中奇联合互联网科技 北京天晋互联网科技有限公司 上海旺乐尼互联网科技有限公司
0