1. 程式人生 > >安裝LAMP部署Discuz論壇腳本

安裝LAMP部署Discuz論壇腳本

linux 腳本編程

#!/bin/bash
#auto install LAMP 
#by 小凡 2017 
#Apr define path variable
A_FILES=apr-1.4.5.tar.gz
A_FILES_DIR=apr-1.4.5
A_URL=http://archive.apache.org/dist/apr/
A_PREFIX=/usr/local/apr

#Apr-util define path variable
A_UTIL_FILES=apr-util-1.3.12.tar.gz
A_UTIL_FILES_DIR=apr-util-1.3.12
A_UTIL_URL=http://archive.apache.org/dist/apr/
A_UTIL_PREFIX=/usr/local/apr-util

#Httpd define path variable
H_FILES=httpd-2.4.27.tar.gz
H_FILES_DIR=httpd-2.4.27
H_URL=http://mirror.bit.edu.cn/apache//httpd/
H_PREFIX=/usr/local/apache/

#MySQL define path variable
M_FILES=mysql-5.5.57.tar.gz
M_FILES_DIR=mysql-5.5.57
M_URL=https://cdn.mysql.com//Downloads/MySQL-5.5/
M_PREFIX=/usr/local/mysql/

#PHP define path variable
P_FILES=php-5.6.9.tar.bz2
P_FILES_DIR=php-5.6.9
P_URL=http://mirrors.sohu.com/php/
P_PREFIX=/usr/local/php5/

echo -e ‘\033[32m-----------------------------\033[0m‘
echo
if [ -z "$1" ];then
    echo -e "\033[33m請按順序選擇安裝菜單序號  \033[0m"
    echo -e "\033[32m
       1)編譯安裝apache服務器
       2)編譯安裝mysql服務器
       3)編譯安裝php服務器
       4)配置mysql、整合php、重啟LAMP服務且部署Discuz論壇 \033[0m"
    echo -e "\033[31m 請使用: { /bin/sh $0 1|2|3|4|help}\033[0m"
exit
fi

if [[ "$1" -eq "help" ]];then
       echo -e "\033[35m請按順序選擇安裝菜單序號  \033[0m"
    echo -e "\033[34m
       1)編譯安裝apache服務器
       2)編譯安裝mysql服務器
       3)編譯安裝php服務器
       4)配置mysql、整合php、重啟LAMP服務且部署Discuz論壇 \033[0m"
    echo -e "\033[31m  請使用: { /bin/sh $0 1|2|3|4|help} \033[0m"
exit
fi
######################################
#Install apr server 
if [[ "$1" -eq "1" ]];then
    yum install -y pcre-devel gcc openssl-devel
    cd /usr/src
    wget -c $A_URL/$A_FILES &&  tar -xzvf $A_FILES && cd $A_FILES_DIR &&./configure --prefix=$A_PREFIX 
    if [ $? -eq 0 ];then
        make && make install
    fi
#Install apr-util server
    cd /usr/src 
    wget -c $A_UTIL_URL/$A_UTIL_FILES &&  tar -xzvf $A_UTIL_FILES && cd $A_UTIL_FILES_DIR &&./configure --prefix=$A_UTIL_PREFIX -with-apr=/usr/local/apr/bin/apr-1-config
    if [ $? -eq 0 ];then
        make && make install
    fi
######################################
#Install httpd web server 
cd /usr/src
wget -c $H_URL/$H_FILES &&  tar -xzvf $H_FILES && cd $H_FILES_DIR &&./configure --prefix=$H_PREFIX --enable-rewrite --enable-so --with-apr=$A_PREFIX --with-apr-util=$A_UTIL_PREFIX
    if [ $? -eq 0 ];then
        make && make install
    echo -e "\033[32;5m apache服務器安裝成功!!! \033[0m"
else
    echo -e "\033[32;5m apache服務器安裝錯誤,請檢查!!!\033[0m"
   exit 0 
    fi
fi
#Install Mysql DB server 
if [[ "$1" -eq "2" ]];then
yum install cmake ncurses-devel gcc-c++ -y
mkdir -p /usr/local/mysql
mkdir -p /usr/local/mysql/data
cd /usr/src
wget -c $M_URL/$M_FILES &&  tar -xzvf $M_FILES && cd $M_FILES_DIR &&cmake . -DCMAKE_INSTALL_PREFIX=$M_PREFIX -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DWGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BLACGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_EXDDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BIG_DEBUG=0
      if [ $? -eq 0 ];then
    make && make install
    echo -e "\033[33;5m  MYSQL服務器安裝成功!!!\033[0m"
else
    echo -e "\033[33;5m  MYSQL服務器安裝錯誤,請檢查!!!\033[0m"
    exit 0  
      fi
fi

#Install PHP server 
if [[ "$1" -eq "3" ]];then
    yum install libxml2-devel perl-devel perl unzip -y
    cd /usr/src
    wget -c http://download.comsenz.com/DiscuzX/3.1/Discuz_X3.1_SC_UTF8.zip
    unzip Discuz_X3.1_SC_UTF8.zip
        wget -c $P_URL/$P_FILES &&  tar -jxvf $P_FILES && cd $P_FILES_DIR &&./configure --prefix=$P_PREFIX --with-config-file-path=$P_PREFIX/etc --with-mysql=$M_PREFIX --with-apxs2=$H_PREFIX/bin/apxs
        if [ $? -eq 0 ];then
                make && make install
    echo -e "\033[34;5m   PHP服務器安裝成功!!!\033[0m"
else
    echo -e "\033[34;5m   PHP服務器安裝錯誤,請檢查!!! \033[0m"
    exit 0 
        fi
fi
####################################

if [[ "$1" -eq "4" ]];then
cd /usr/local/mysql
/usr/sbin/useradd -s /sbin/nologin mysql
ln -s $M_PREFIX/bin/* /usr/bin
/bin/chown -R root:mysql .
/bin/chown -R mysql:mysql data
/bin/cp support-files/mysql.server /etc/init.d/mysqld
/bin/chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
cat > /etc/my.cnf << EOF
[mysqld]
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
user = mysql
log-error = /var/log/mysqld.log
character_set_server = utf8
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
EOF
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --basedir=$M_PREFIX
    sed -i ‘/DirectoryIndex/s/index.html/index.php index.html/g‘ $H_PREFIX/conf/httpd.conf 
    sed -i ‘/libphp5.so/a AddType     application/x-httpd-php .php‘ $H_PREFIX/conf/httpd.conf
    IP=`ifconfig eth0|grep "Bcast"|awk ‘{print $2}‘|cut -d: -f2`
    echo "You can access http://$IP/"
cat >$H_PREFIX/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF
$H_PREFIX/bin/apachectl restart
/etc/init.d/mysqld restart
/etc/init.d/iptables stop
setenforce 0
cp -r /usr/src/upload/* $H_PREFIX/htdocs/
cd $H_PREFIX/htdocs
chmod -R 757 *
mysql -e "create database discuz default character set utf8;"
mysql -e "grant  all on discuz.* to  [email protected]‘localhost‘  identified by ‘123456‘;"
   if [ $? -eq 0 ];then
     echo  -e "\033[31;5m  LAMP環境搭建完畢!!!  \033[0m"
else 
     echo  -e "\033[31;5m  LAMP環境搭建錯誤,請檢查!!!  \033[0m"
   fi
fi


本文出自 “劉士凡-技術分享” 博客,請務必保留此出處http://liusf.blog.51cto.com/13344518/1972827

安裝LAMP部署Discuz論壇腳本