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: lnmpremote_user: roottasks:- name: "create install directory"file:path: /opt/lnmpstate: directory- name: "copy nginx_tar.gz"copy:src: /opt/lnmp/nginx-1.8.1.tar.gzdest: /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.gzdest: /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.confdest: /usr/local/php7/etc/- name: "copy php.ini"template:src: /opt/lnmp/php_conf/php.inidest: /usr/local/php7/- name: "copy wwww.conf"copy:src: /opt/lnmp/php_conf/www.confdest: /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.gzdest: /var/www/phpmode: 0777owner: nobodygroup: nfsnobody

nginx_install.sh代码

#!/bin/bash
##this is nginx install bash
nginx_tar=/opt/lnmp/nginx*.gz
ng_path=/opt/lnmp
if [ -e $nginx_tar ];then
tar zxvf $nginx_tar -C $ng_path
else
echo "nginx.tar.gz does not exist"
fi
#yum
yum install -y gcc gcc-c++ autoconf gd-devel automake zlib zlib-devel openssl openssl-devel pcre*
if [ ! $? -eq 0 ];thenecho "error yum install"exit 1
fi
sleep 5
#configure
cd /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_module
if [ $? -eq 0 ];then
make && make install
fi
#create nginx user
id nginx
if [ ! $? -eq 0 ];thenuseradd -M -s /sbin/nologin nginx
elseuserdel -r nginxuseradd -M -s /sbin/nologin nginx
fi
#Modify configuration files
nginx_conf_path=/usr/local/nginx/conf/nginx.conf
cat >${nginx_conf_path} <<EOF
worker_processes  auto;
events {worker_connections  1024;
}
http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;location / {root   /var/www/php;index  index.html index.htm index.php;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location ~ \.php$ {root           /var/www/php;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;include        fastcgi_params;}}
}
EOF
#create root document
www_path=/var/www/php
if [ ! -d "$wwww_path" ];thenmkdir -p ${www_path}
fi
#create test index html
echo "this is nginx test html" > ${www_path}/test.html
#check nginx pid
nginx_pid=`pgrep nginx | wc -l`
if [ $nginx_pid -eq 0 ];then/usr/local/nginx/sbin/nginxecho "nginx has started...."
elsekillall nginx/usr/local/nginx/sbin/nginxecho "nginx has restart..."
fi

php_install.sh代码

#!/bin/bash
##PHP install script
#Tar php.tgz
php_tar=/opt/lnmp/php*.gz
configure_path=/opt/lnmp
if [ -e $php_tar ];thentar zxvf  $php_tar -C $configure_path
elseecho "php*.tar.gz does not exist...."exit 1
fi
#create php user
id php
if [ ! $? -eq 0 ];thenuseradd -M -s /sbin/nologin php
elseuserdel -r phpuseradd -M -s /sbin/nologin php
fi
#yum
yum install libxml2 libxml2-devel -y
#configure
cd /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 install
if [ ! $? -eq 0 ];thenecho "make install error,please check configure"
elsemake && make install
fi

php_restart.sh 代码

#!/bin/bash
php_pid=`pgrep php-fpm | wc -l`
if [ $php_pid -eq 0 ];then/usr/local/php7/sbin/php-fpm
elsekillall php-fpm/usr/local/php7/sbin/php-fpm
fi

mysql_admin.sh 代码

#!/bin/bash
sed -ri "1a skip-grant-tables" /etc/my.cnf
systemctl restart mariadb
sleep 3
mysql -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地址),安装完成,以下为登陆界面

ansible+shell脚本搭建wordpress论坛相关推荐

  1. 部署LNMP并利用LNMP搭建wordpress论坛

    1.LNMP是什么? LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写.L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指 ...

  2. 使用LAMP环境搭建wordpress论坛

    1.      搭建LAMP架构 (1)      rpm搭建LAMP环境 [root@HK36 ~]# yum install httpd mysql-server mysql php php-my ...

  3. 《Linux7通过LAMP环境构搭建WordPress论坛 》

    WordPress是什么? WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站.也可以把 WordPress当作一个内容管理系统(CM ...

  4. 基于lamp框架搭建wordpress论坛

    手动操作完成 1.安装服务 [root@workstation mnt]# dnf install httpd mariadb-server php php-mysqlnd -y [root@work ...

  5. wordpress mysql 5.7_CentOS7 运维 - 搭建WordPress论坛 | 超详细 | MySQL安装使用

    准备环境 服务器操作系统:CentOS7 部署服务器:Apache HTTP 数据库:MySQL 框架:WordPress 一.安装Apache HTTP sudo yum install httpd ...

  6. Dockerfile搭建wordpress论坛

    目录 环境部署 一.系统部署 二 .Dockerfile编写 三.对数据库授权 环境部署 一.系统部署 安装docker yum install -y yum-utils device-mapper- ...

  7. 一次shell脚本小事故,从中学习排错过程-软件测试

    一次shell脚本小事故,从中学习排错过程 事出,童鞋使用shell脚本搭建测试环境的过称中..... 配置环境变量文件:/etc/profile(用于升级JDK或其他) 手动编辑方法:vi /etc ...

  8. 一起来了解Shell脚本

    目录 一.Shell脚本概述 1.1.Shell脚本的概念 1.2.Shell脚本应用场景 1.3.Shell的作用--命令解释器,"翻译官" 1.4.用户的登录Shell 二.S ...

  9. python编写自动化脚本 与shell_脚本安装Discuz论坛(shell + Python 实现自动化安装)...

    实验环境 1.shell 脚本:linux centos 7 系统 2.Python shell 脚本:window 系统 3.其他:python selenium 模块,谷歌浏览器, 谷歌浏览器驱动 ...

最新文章

  1. 2018热点总结:BERT最热,GANs最活跃,每20分钟就有一篇论文...
  2. 老大,你为什么在代码中要求我们使用LocalDateTime而不是Date?
  3. Windows 技术篇 - windows日期和时间设置里没有Internet 时间页签原因和解决方法
  4. SLAM:SLAM相机简介、SLAM五步流程简介(VO+BEO+LCD+M)之详细攻略
  5. Java例外:java lang NoSuchMethodError
  6. 【CentOS 7笔记11】,目录权限,所有者与所有组,隐藏权限#171022
  7. 【算法】CRC 循环冗余校验
  8. 【App 支付】交易查询接口
  9. 怎么打钩_如何在excel中打钩
  10. python函数调用的例子_Python案例|混用C函数
  11. 黄山学院计算机作业管理系统,在线作业管理系统
  12. 第三次作业——K米评测
  13. 【css】让img图片居中显示
  14. MP4视频转换器怎么样将FLV转MP4
  15. 阿里云服务器受攻击总结
  16. C语言函数操作大全----(超详细)
  17. python3文件的编码类型是_Python3.x环境创建Python脚本文件时,需要将文件编码格式设置为...
  18. bzoj 5285: [Hnoi2018]寻宝游戏
  19. 用python画简单雪花剪纸步骤图解_Python+Selenium+Beautiful Soap抓取贝贝拼团爆款
  20. 【学习笔记】PHP进阶

热门文章

  1. 国外最好的人工智能媒体和技术博客TOP5
  2. 石头机器人红灯快闪_机器人演绎科技快闪 人机“舞林大会”燃动西安高新区...
  3. 仓储管理之计价方法——先进先出法
  4. 全相位算法c语言表达,基于DSP的全相位FFT频率计设计.pdf
  5. 计蒜客 15499 阿里的新游戏 题解
  6. terminatethread导致内存泄露
  7. 【经典买点】MACD指标的八种买入形态图解
  8. chroma8000使用_chroma 8000电源供应器自动测试系统|chroma8000使用说明
  9. 计算机技能大赛比赛新闻稿,第六届技能竞赛系列报道——PS绘制青春
  10. 怎么计算机械表的正负时差,机械表居然有这么多隐藏功能!直接倒时差?