溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

ansible+shell腳本搭建wordpress論壇

發(fā)布時(shí)間:2020-10-17 20:51:00 來源:網(wǎng)絡(luò) 閱讀:726 作者:丁香花下 欄目:系統(tǒng)運(yùn)維

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ansibler+shell腳本搭建wordpress論壇

ansible作為自動(dòng)化運(yùn)維工具,功能模塊很多,配合shell腳本可以更好的進(jìn)行自動(dòng)化的部署。

環(huán)境:

192.168.0.9? ?#需要部署的LNMP+wordpress的機(jī)器

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?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?];then
?????echo?"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?];then
???useradd?-M?-s?/sbin/nologin?nginx
else
???userdel?-r?nginx
???useradd?-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"?];then
??mkdir?-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/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.tgz
php_tar=/opt/lnmp/php*.gz
configure_path=/opt/lnmp
if?[?-e?$php_tar?];then
???tar?zxvf??$php_tar?-C?$configure_path
else
??echo?"php*.tar.gz?does?not?exist...."
??exit?1
fi
#create?php?user
id?php
if?[?!?$??-eq?0?];then
??useradd?-M?-s?/sbin/nologin?php
else
??userdel?-r?php
??useradd?-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?];then
???echo?"make?install?error,please?check?configure"
else
??make?&&?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
else
??killall?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

填寫完數(shù)據(jù)庫(kù)用戶名密碼之后(數(shù)據(jù)庫(kù)主機(jī)localhost不好使,就使用IP地址),安裝完成,以下為登陸界面

ansible+shell腳本搭建wordpress論壇

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI