#!/bin/bash
#
#Target: Auto install Discuz!
#Date: 2015-05-02
#Author: Jacken
#QQ:654001593
#QQ Group:170544180
#Version: 1.0
#You should check apr-devel,apr-util-devel,gcc,ncurses-devel,gcc-c++,libxml2,libxml2-devel...before exec script
#You can use yum to install!
#
#
#Httpd define path variable
H_FILES=httpd-2.2.29. tar .gz
H_FILES_DIR=httpd-2.2.29
H_URL= 'http://mirror.bit.edu.cn/apache/httpd/'
H_PREFIX= '/usr/local/apache'
#
#
#Mysql define path variable
M_FILES= 'mysql-5.1.63.tar.gz'
M_FILES_DIR= 'mysql-5.1.63'
M_URL= 'http://downloads.mysql.com/archives/mysql-5.1/'
M_PREFIX= '/usr/local/mysql'
#
#
#Php define path variable
P_FILES= 'php-5.3.28.tar.bz2'
P_FILES_DIR= 'php-5.3.28'
P_URL= 'http://mirrors.sohu.com/php/'
P_PREFIX= '/usr/local/php5'
#
#
#Discuz define path variable
D_FILES= 'Discuz_X3.2_SC_UTF8.zip'
D_URL= 'http://download.comsenz.com/DiscuzX/3.2/'
D_DIR= '/var/www/html'
#
#
#Only for super user to execute!
if [ $UID - ne 0 ]; then
echo 'Error,Just for Super user.'
exit 2
fi
#
#
#Only one arguement
if [ $ # -ne 1 ];then
echo -e "/e[31mPlease exec $0 --help/e[0m"
exit 2
fi
#
#
#Must have arguement!
if [ -z "$1" ]; then
echo -e "/e[31mPlease exec $0 --help/e[0m"
exit 2
fi
#
#
#Help and Menu
if [[ "$1" == '--help' ]]; then
echo -e '/e[31mPlease Select Install Menu follow:/e[0m'
echo -e '/e[32m1 Install Apache/e[0m'
echo -e '/e[33m2 Install Mysql/e[0m'
echo -e '/e[34m3 Configure Mysql/e[0m'
echo -e '/e[35m4 Install Php/e[0m'
echo -e '/e[36m5 Integrate Php and Mysql/e[0m'
echo -e '/e[37m6 Configure Discuz/e[0m'
echo -e "/e[31mThe Usage: $0 1 or 2 or 3 or 4 or 5 or 6,Only one number/e[0m"
exit
fi
#
#
#Must correct option!
if [[ "$1" -lt 1 || "$1" -gt 6 ]]; then
echo -e "/e[31mPlease exec $0 --help/e[0m"
exit 2
fi
##################################################################################################################
##################################################################################################################
#Install Apache
if [[ "$1" - eq "1" ]]; then
wget -c $H_URL$H_FILES && tar -zxf $H_FILES && cd $H_FILES_DIR && . /configure --prefix=$H_PREFIX && make && make install
if [ "$?" - eq "0" ]; then
echo -e '/e[32mApache Server Install Success!/e[0m'
else
echo -e '/e[31mApache Server Install Failure!/e[0m'
fi
exit
fi
######################
######################
#Install Mysql DB
if [[ "$1" - eq "2" ]]; then
wget -c $M_URL$M_FILES && tar -zxf $M_FILES && cd $M_FILES_DIR && . /configure --prefix=$M_PREFIX -- enable -assembler && make && make install
if [ "$?" - eq "0" ]; then
echo -e '/e[32mMysql Server Install Success!/e[0m'
else
echo -e '/e[31mMysql Server Install Failure!/e[0m'
fi
exit
fi
######################
######################
#Configure Mysql
if [[ "$1" - eq "3" ]]; then
/ cp ${M_PREFIX} /share/mysql/my-medium .cnf /etc/my .cnf && / cp ${M_PREFIX} /share/mysql/mysql .server /etc/init .d /mysqld && chkconfig --add mysqld && chkconfig --level 345 mysqld on
#Useradd mysql user
id mysql> /dev/null 2>&1 || useradd mysql
cd $M_PREFIX
chown -R mysql.mysql $M_PREFIX && ${M_PREFIX} /bin/mysql_install_db --user=mysql > /dev/null 2>&1 &&
chown -R mysql var && /usr/local/mysql/bin/mysqld_safe --user=mysql& > /dev/null 2>&1 &&
if [ $? - eq 0 ]; then
echo -e '/e[32mMysql Server Configure Success!/e[0m'
else
echo -e '/e[31mMysql Server Configuue Failure!/e[0m'
fi
exit
fi
######################
######################
#Install Php
if [[ "$1" - eq "4" ]]; then
wget -c $P_URL$P_FILES && tar -jxf $P_FILES && cd $P_FILES_DIR && . /configure --prefix=$P_PREFIX --with-config- file -path=${P_PREFIX} /etc --with-apxs2=${H_PREFIX} /bin/apxs --with-mysql=$M_PREFIX && make && make install
if [ $? - eq 0 ]; then
echo -e '/e[32mPhp Install Success!/e[0m'
else
echo -e '/e[31mPhp Install Failure!/e[0m'
fi
exit
fi
######################
######################
# Integrate Php and Mysql
if [[ "$1" - eq "5" ]]; then
sed -i '311a AddType application/x-httpd-php .php' $H_PREFIX /conf/httpd .conf &&
sed -i 's/index.html/index.php index.html/' $H_PREFIX /conf/httpd .conf
if [ $? - eq 0 ]; then
echo -e '/e[32mIntegrate is Success!/e[0m'
else
echo -e '/e[31mIntegrate is Failure!/e[0m'
fi
$H_PREFIX /bin/apachectl start > /dev/null 2>&1
exit
fi
######################
######################
#Configure Discuz
if [[ "$1" - eq "6" ]]; then
wget -c $D_URL$D_FILES && unzip $D_FILES -d $H_PREFIX /htdocs/ && cd $H_PREFIX /htdocs/ && / mv upload/* . && chmod -R o+w data/ config/ uc_server/ uc_client/
if [ $? - eq 0 ]; then
echo -e '/e[32mConfigure Discuz Success!/e[0m' &&
#Create discuz database
$M_PREFIX /bin/mysql -uroot -e 'create database discuz' &&
#Grant user password
$M_PREFIX /bin/mysql -uroot -e "grant all on *.* to discuz@'localhost' identified by 'discuz'" &&
#Flush privileges
$M_PREFIX /bin/mysql -uroot -e 'flush privileges'
if [ $? - eq 0 ]; then
echo -e '/e[32mDiscuz Mysql Configure Success!/e[0m'
else
echo -e '/e[31mDiscuz Mysql configure Failure!/e[0m'
fi
######################
######################
#Start Apache Server
$H_PREFIX /bin/apachectl start> /dev/null 2>&1 &&
#Start Mysql Server
$M_PREFIX /bin/mysqld_safe --user=mysql&> /dev/null 2>&1
if [ $? - eq 0 ]; then
echo -e '/e[32mApache and Mysql Start Success!/e[0m'
else
echo -e '/e[31mApache and Mysql Start Failure!/e[0m'
fi
else
echo -e '/e[31mConfigure Discuz Failure!/e[0m'
fi
exit
fi
运行脚本请先 #./Auto_Install_Discuz --helphttps://www.cndba.cn/Expect-le/article/1637
如果要安装Discuz!尽量按编号顺序执行!
Server上的Selinux与Iptables是关闭的,并且环境包都已经yum安装完毕,包含但不限于以下软件https://www.cndba.cn/Expect-le/article/1637
apr-devel,apr-util-devel,gcc,ncurses-devel,gcc-c++,libxml2,libxml2-devel..https://www.cndba.cn/Expect-le/article/1637
https://www.cndba.cn/Expect-le/article/1637https://www.cndba.cn/Expect-le/article/1637
当安装完成后便可以直接输入Server的IP直接安装Discuz论坛,如下:
注意这里要和脚本中定义的数据库名、授权的用户名、密码一致
https://www.cndba.cn/Expect-le/article/1637
执行安装!
安装完毕!
Done!https://www.cndba.cn/Expect-le/article/1637
https://www.cndba.cn/Expect-le/article/1637