单台主机一键编译部署LAMP+wordpress+discuz系统的shell脚本

单台主机一键编译部署LAMP+wordpress+discuz系统的shell脚本

?

说明:

1、shell脚本与应用程序包在同一个目录中;
2、虚拟机尽量加大CPU核数,以提高编译速度;
3、根据需要修改相应的变量,主要是安装目录、用户名、密码;
4、Mariadb的grant授权部分,需要先手动修改授权范围(@后面的内容)和密码;
5、httpd与php采用sock通讯。

?

完整的shell脚本

#!/bin/bash

#*************************************************************
#Author:             fanfubin
#QQ:                 502422514
#Date:               2019-05-15
#FileName:           httpd.sh
#Copyright (C):      2019 All rights reserved
#*************************************************************

#环境:
#centos7.6
#软件版本:
#mariadb-10.2.23-linux-x86_64.tar.gz
#apr-1.7.0.tar.gz
#apr-util-1.6.1.tar.gz
#httpd-2.4.39.tar.bz2
#php-7.3.5.tar.bz2
#wordpress-5.2.tar.gz
#Discuz_X3.3_SC_UTF8.zip

httpd_install_ver=(
    apr-1.7.0.tar.gz
    apr-util-1.6.1.tar.gz
    httpd-2.4.39.tar.bz2
)

tar_wordpress="wordpress-5.2.tar.gz"
tar_discuz="Discuz_X3.3_SC_UTF8.zip"
tar_php="php-7.3.5.tar.bz2"
tar_mariadb="mariadb-10.2.23-linux-x86_64.tar.gz"

let cpu_num=`lscpu|awk -F ‘ +‘ ‘/^CPU\(s\):/{print $2}‘`-1

mysql_install_dir="/app/mysql"
mysql_data_dir="/data/mysql"
mysql_user=mysql
mysql_login_name=root
mysql_root_passwd=123456
package_name=`echo $tar_mariadb | sed -r ‘s/(.*).(tar.gz)/\1/‘`

httpd_user=apache
httpd_prefix="/app/httpd24"

php_prefix="/app/php"

wordpress_dir="$httpd_prefix/htdocs/wordpress"
wordpress_database=wordpress
wordpress_user=wpuser
wordpress_passwd=\‘fanfubin\‘
#wordpress_host=\‘192.168.36.%\‘
wordpress_passwd_php=`echo $wordpress_passwd | tr -d "\‘"`
#wordpress_host_php=`echo $wordpress_host | tr -d "\‘"`
#wordpress_host_php=192.168.36.35

wordpress_host=\‘localhost\‘
wordpress_host_php=localhost

discuz_dir="$httpd_prefix/htdocs/discuz"
discuz_database=ultrax
discuz_user=discuz
#discuz_passwd=\‘fanfubin\‘
#discuz_host=\‘192.168.36.%\‘

read -p "Pls you choose num  1-php-local  2-php-remote": choose_num
[ $choose_num -ne 1 ] && { echo "remote pattern nonsupport!"; exit; }

#Wordpress .tar. is exist?
[ ! -e $tar_wordpress ] && { echo "$tar_wordpress is not exist"; exit; }

#Discuz .tar. is exist?
[ ! -e $tar_discuz ] && { echo "$tar_discuz is not exist"; exit; }

#Mariadb .tar. is exist?
[ ! -e $tar_mariadb ] && { echo "$tar_mariadb is not exist"; exit; }

#Php .tar. is exist?
[ ! -e $tar_php ] && { echo "$tar_php is not exist"; exit; }

#httpd  .tar. is exist?
for ver in ${httpd_install_ver[*]}
    do
        if [ ! -e $ver ];then
            echo "${ver} is not exist!"
            exit
        fi
    done

[ `rpm -q php-mysql` -eq 0 ] && { echo "Pls complete discharge php-mysql"; exit; }

####Install httpd
[ ! -d $httpd_prefix ] && mkdir -p $httpd_prefix

yum -y install gcc pcre-devel openssl-devel expat-devel autoconf libtool gcc-c++ lbzip2 expat-devel unzip 

id $httpd_user
if [ `echo $?` -ne 0 ];then
    useradd -r -s /sbin/nologin $httpd_user
fi

#tar xf
for ver1 in ${httpd_install_ver[*]}
    do
        tar xf $ver1
    done

#httpd_file name && httpd_install_dir
httpd_install_num=`echo ${#httpd_install_ver[@]}`
num=0
for name in ${httpd_install_ver[*]}
    do
        if [ $num -ne $httpd_install_num ];then
            httpd_file_name[${num}]=`echo $name | awk -F ‘.tar.‘ ‘{print $1}‘`
            if [ `echo $name | awk -F ‘.tar.‘ ‘{print $1}‘ | grep -i httpd | wc -l` -eq 1 ];then
                httpd_install_dir=`echo $name | awk -F ‘.tar.‘ ‘{print $1}‘`
            fi
            let num++
        fi
    done

for file_mv in ${httpd_file_name[*]}
    do
        if [ `echo $file_mv | grep -i httpd |wc -l` -ne 1 ];then
            mv $file_mv ${httpd_install_dir}/srclib/`echo $file_mv | sed -r ‘s/(.*)-.*/\1/‘`
        fi
    done

cd $httpd_install_dir

./configure --prefix=$httpd_prefix --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

sleep 1
make -j $cpu_num  && make install
sleep 1
echo ‘PATH=‘${httpd_prefix}‘/bin:$PATH‘ > /etc/profile.d/httpd.sh
sleep 1
source /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh

sed -ir ‘s/User daemon/User ‘$httpd_user‘/‘ $httpd_prefix/conf/httpd.conf
sleep 1
sed -ir ‘s/Group daemon/Group ‘$httpd_user‘/‘ $httpd_prefix/conf/httpd.conf

echo "$httpd_prefix/bin/apachectl start" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local

sed -ri ‘s%#LoadModule proxy_module modules/mod_proxy.so%LoadModule proxy_module modules/mod_proxy.so%‘ $httpd_prefix/conf/httpd.conf
sed -ri ‘s%#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so%LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so%‘ $httpd_prefix/conf/httpd.conf
sed -ri ‘s/DirectoryIndex index.html/DirectoryIndex index.php index.html/‘ $httpd_prefix/conf/httpd.conf

cat >>$httpd_prefix/conf/httpd.conf<<EOF
addType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#ProxyRequests Off
#ProxyPassMatch ^/(.*\.php)$ unix:/var/run/php.sock|fcgi://localhost${httpd_prefix}/htdocs/
#ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1${httpd_prefix}/htdocs/

<virtualhost *:80>
documentroot $httpd_prefix/htdocs/wordpress
servername  blog.test.com
ProxyRequests Off
#ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/
ProxyPassMatch ^/(.*\.php)$ unix:/var/run/php.sock|fcgi://localhost${httpd_prefix}/htdocs/wordpress
<directory $httpd_prefix/htdocs/wordpress>
require all granted
</directory>
</virtualhost>

<virtualhost *:80>
documentroot $httpd_prefix/htdocs/discuz
servername  forum.test.com
ProxyRequests Off
#ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1
ProxyPassMatch ^/(.*\.php)$ unix:/var/run/php.sock|fcgi://localhost${httpd_prefix}/htdocs/discuz
<directory ${httpd_prefix}/htdocs/discuz>
require all granted
</directory>
</virtualhost>
EOF
cd -

###Install php-fpm
yum -y install libxml2-devel bzip2-devel libmcrypt-devel phpize lbzip2

tar xf $tar_php
sleep 1
php_install_dir=`echo $tar_php | awk -F ‘.tar.‘ ‘{print $1}‘`
sleep 1
chown -R  root.root ${php_install_dir}
cd ${php_install_dir}
./configure --prefix=$php_prefix --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo

sleep 2
make -j $cpu_num && make install
cp php.ini-production  /etc/php.ini
sed -ri ‘s#;date.timezone =#date.timezone = "Asia/Shanghai"#‘ /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cp $php_prefix/etc/php-fpm.conf.default $php_prefix/etc/php-fpm.conf
cp $php_prefix/etc/php-fpm.d/www.conf.default $php_prefix/etc/php-fpm.d/www.conf
sleep 1
sed -ir ‘s/user = nobody/user = ‘$httpd_user‘/‘ $php_prefix/etc/php-fpm.d/www.conf
sed -ir ‘s/group = nobody/group = ‘$httpd_user‘/‘ $php_prefix/etc/php-fpm.d/www.conf

if [ $choose_num -eq 1 ];then
    sed -ri ‘s#listen = 127.0.0.1:9000#listen = /var/run/php.sock#‘ $php_prefix/etc/php-fpm.d/www.conf
    sed -ri ‘s#;listen.mode = 0660#listen.mode = 0666#‘ $php_prefix/etc/php-fpm.d/www.conf
fi

cd -
sleep 2

####Binary install mariadb
id $mysql_user &>/dev/null
if [ `echo $?` -ne 0 ];then
    userdel -r $mysql_user &>/dev/null
    useradd -r -u 336 -s /sbin/nologin -d $mysql_data_dir $mysql_user &>/dev/null
else
    useradd -r -u 336 -s /sbin/nologin -d $mysql_data_dir $mysql_user &>/dev/null
fi 

rpm -q libaio &>/dev/null
[ `echo $?` -ne 0 ] && yum -y install libaio

rpm -q expect &>/dev/null
[ `echo $?` -ne 0 ] && yum -y install expect

#此文件可能会造成影响,所以先清空
\rm -rf /etc/my.cnf

tar xf $tar_mariadb -C /usr/local/
sleep 2
cd  /usr/local/
ln -s $package_name mysql
chown -R root.root /usr/local/mysql/
echo ‘PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
sleep 1
source /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
mkdir $mysql_data_dir -p
chown ${mysql_user}.${mysql_user} $mysql_data_dir
cd -

cd /usr/local/mysql
./scripts/mysql_install_db --datadir=$mysql_data_dir --user=$mysql_user
mkdir -p /etc/mysql
cp /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnf
#禁止主机名解析,建议使用
sed -ri ‘/^\[mysqld\]/askip_name_resolve = on‘ /etc/mysql/my.cnf
sed -ri ‘/^\[mysqld\]/adatadir=\/data\/mysql‘ /etc/mysql/my.cnf
cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
sleep 2

expect <<EOF
spawn mysql_secure_installation
expect {
"Enter current password for root" { send "\n";exp_continue }
"Set root password" { send "\n";exp_continue }
"New password" { send "${mysql_root_passwd}\n";exp_continue }
"Re-enter new password" { send "${mysql_root_passwd}\n";exp_continue }
"Remove anonymous users" { send "y\n";exp_continue }
"Disallow root login remotely" { send "y\n";exp_continue }
"Remove test database and access to it" { send "y\n";exp_continue }
"Reload privilege tables now" { send "y\n" }
}
#expect "]#" { send "exit\n" }
expect eof
EOF

mysqladmin -uroot -p${mysql_root_passwd} ping &>/dev/null
[ `echo $?` -eq 0 ] && echo ‘mysql is running !‘ || echo ‘mysql is stopped‘ 

#create wordpress && discuz
mysql -uroot -p${mysql_root_passwd} -e "create database ${wordpress_database}"
#mysql -uroot -p${mysql_root_passwd} -e "grant all on ${wordpress_database}.* to ${wordpress_user}@‘192.168.36.%‘ identified by ‘fanfubin‘"
mysql -uroot -p${mysql_root_passwd} -e "grant all on ${wordpress_database}.* to ${wordpress_user}@‘localhost‘ identified by ‘fanfubin‘"
mysql -uroot -p${mysql_root_passwd} -e "grant all on ${discuz_database}.* to ${discuz_user}@‘192.168.36.%‘ identified by ‘fanfubin‘"
cd -
sleep 2

###Install wordpress
tar xf $tar_wordpress -C $httpd_prefix/htdocs/
sleep 1
cp $wordpress_dir/wp-config-sample.php $wordpress_dir/wp-config.php
sed -ri ‘s/database_name_here/‘$wordpress_database‘/‘ $wordpress_dir/wp-config.php
sed -ri ‘s/username_here/‘$wordpress_user‘/‘ $wordpress_dir/wp-config.php
sed -ri ‘s/password_here/‘$wordpress_passwd_php‘/‘ $wordpress_dir/wp-config.php
sed -ri ‘s/localhost/‘$wordpress_host_php‘/‘ $wordpress_dir/wp-config.php

setfacl -R -m u:${httpd_user}:rwx $wordpress_dir

echo $wordpress_passwd_php
echo $wordpress_host_php

sleep 2

### Install discuz
unzip $tar_discuz  &>/dev/null
sleep 1
mv upload $httpd_prefix/htdocs/
mv $httpd_prefix/htdocs/upload $httpd_prefix/htdocs/discuz
setfacl -R -m  u:${httpd_user}:rwx $httpd_prefix/htdocs/discuz/

apachectl restart
sleep 2
service php-fpm start

原文地址:https://blog.51cto.com/13560168/2396950

时间: 2024-10-12 16:43:33

单台主机一键编译部署LAMP+wordpress+discuz系统的shell脚本的相关文章

单台主机nginx+tomcat+mencached部署测试

单台主机部署 亦可分布式部署 改动配置ip即可 多个tomcat要一起协同工作有几种办法,可以考虑的方案有以下几个:1. 使用tomcat自带的cluster方式,多个tomcat间自动实时复制session信息,配置起来很简单.但这个方案的效率比较低,在大并发下表现并不好.2. 利用nginx的基于访问ip的hash路由策略,保证访问的ip始终被路由到同一个tomcat上,这个配置更简单.但如果应用是某一个局域网大量用户同时登录,这样负载均衡就没什么作用了.3. 利用memcached把多个t

LNMP3台主机分离进行部署

LNMP 3台主机分离进行部署 第一台虚拟主机进行部署nginx  第二台虚拟主机进行部署php-fpm  第三台虚拟主机进行部署mariadb-server  第一台主机进行部署nginx 的安装:实现静态网页的处理工作(192.168.1.107) 1.先下载1.8版本的,然后进行解压工作. 2.编译安装如下操作 3.yum groupinstall "Development Tools" "Server Platform Development" -y yum

CentOS6系统编译部署LAMP(Linux, Apache, MySQL, PHP)环境

我们一般常规的在Linux服务器中配置WEB系统会用到哪种WEB引擎呢?Apache还是比较常用的引擎之一.所以,我们在服务器中配置LAMP(Linux, Apache, MySQL, PHP)是我们常用的WEB环境.对于大部分同学来说,我们会选择采用WEB面板或者是一键包安装,但是一键包或者面板也是有一些缺陷的,比如有些软件我们并不需要安装. 或者说,对于我们深入学习Linux系统的用户来说,肯定是需要一步步编译安装,这样才知道其中的原理.在这篇文章中,我们将在CentOS6系统中(CentO

在单台主机上配置LNMP

在单台主机上配置LNMP 编译安装nginx 1.登录官网获取下载链接直接wget [[email protected] ~]# wget http://nginx.org/download/nginx-1.17.0.tar.gz 2.解压文件 [[email protected] ~]# tar xf nginx-1.17.0.tar.gz 3.检查当前环境是否符合编译要求,并生成makefile文件 [[email protected] ~]# cd nginx-1.17.0 [[email

编译部署LAMP+xcache (php-fpm模式)

通过编译安装方式部署分离式LAMP+xcache (php-fpm模式) 要求: (1)采用源码编译部署分离式的LAMP,其中php基于php-fpm模式 (2)基于LAMP平台一个虚拟主机提供WordPress,另一个虚拟主机提供phpMyadmin (3)利用xcache来为php提供缓存加速页面的访问速度 (4)对其中一个站点缓分别做压力测试,并且比对缓存加速前和加速后的数据. 环境: 192.168.1.103------>提供httpd服务 192.168.1.104------>提

三台主机CentOS7 编译安装lamp

作业题:三台主机编译安装http.php,二进制源码安装mariadb环境:A主机:192.166.0.161,编译安装httpdB主机:192.166.0.162,编译安装php-fpmC主机:192.166.0.163,二进制格式安装mariadb 三台主机均关闭了firewalld.selinux,软件存放目录均为/root/tools/ 一:安装http安装扩展组件 yum -y groupinstall "开发工具" "服务器平台开发" yum insta

编译安装lamp+xcache,提供httpd启动脚本

PHP:脚本编程语言,php解释器 WebApp:面向对象的特性 Zend: 第一段:词法分析.语法分析.编译为Opcode: opcode放置于内存中 第二段:执行opcode: php分两段的好处,当用户第二次请求的时候,就直接执行这个OPCODE即可.这样之后速度也会快些,但是在不同的进程之间是不能共享opcode的,同时opcode也是放在 内存中的.只要关机就会清空.为了避免自身去清除opcode,并且实现在多个php进程之间共享操作码,共享opcode的功能,引入了叫做php缓存器.

一键编译安装lamp

准备工具 httpd:apr-1.7.0.tar.gz,apr-util-1.6.1.tar.gz,httpd-2.4.39.tar.bz 所有源码包 mysql:mariadb-10.2.23.tar.gz源码包 php:php-7.3.5tar.bz2源码包 以上所有源码包存,以及一键安装脚本存放在root家目录下,运行一键安装脚本. 脚本运行完毕,使用浏览器访问测试页 一键安装脚本 #!/bin/bash LINE=12 #编译时线程数 APR=apr-1.7.0 #APR源码包版本号 A

编译部署LAMP之httpd

1. 编译安装httpd LAMP环境一般是根据自己的需求使用源码包进行编译安装,本次使用的是httpd-2.4.25.先对包进行解压缩,使用命令: cd到httpd-2.4.25文件夹 使用./configure --help |less查看编译参数: