设为首页 收藏本站
查看: 783|回复: 0

安装lamp+discuz脚本

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-27 08:40:50 | 显示全部楼层 |阅读模式
#!/bin/bash
#by 2015-7-25--lijq
#directiof for use:源码包和脚本在同一目录且在root目录下的文件里
DIR=/mnt/soft/
SCRIPT_DIR=/root/autolamp
        if [ $UID -ne 0 ]; then
        echo -e "\033[32monly for root to install this LAMP\033[0m"
                exit 3
        fi
        echo -e "\033[32mcreate soft dowload dir....\033[0m"
        if [ ! -d $DIR ];then
        mkdir -p $DIR;
        fi
        echo -e  "\033[32minstal some dependent packages,please wait for .... \033\0m"
        yum install gcc gcc-c++ make cmake ncurses-devel bison perl lrzsz epel-release pcre-devel openssl-devel -y;
        yum install wget unzip libxml2-devel libmcrypt-devel bzip2-devel libxml2-devel openssl-devel bzip2 bzip2-devel -y
;
APR_FILE=apr-1.5.2.tar.gz
APR=`echo $APR_FILE | sed 's/\.tar\.gz//g'`
APR_UTILS=apr-util-1.5.2.tar.gz
APR_UTIL=`echo $APR_UTILS | sed 's/\.tar\.gz//g'`
APACHE_FILE=httpd-2.4.16.tar.gz
APACHE=`echo $APACHE_FILE | sed 's/\.tar\.gz//g'`
APR_DIR=/usr/local/apr/
APRUTIL_DIR=/usr/local/apr-util/
APACHE_DIR=/usr/local/apache/
function httpd_install()
{       if [ -f $APR_FILE -o -f $APR_UTILS -o -f $APACHE_FILE ];then
        cp $APR_FILE $APR_UTILS $APACHE_FILE $DIR -a
else
        cd $DIR;
        wget -c http://archive.apache.org/dist/apr/$APR_FILE;
        wget -c http://archive.apache.org/dist/apr/$APR_UTILS;
        wget -c http://www.apache.org/dist/httpd/$APACHE_FILE;
        fi
        cd $DIR
        tar xzvf $APR_FILE;
        cd $APR;./configure --prefix=$APR_DIR && make && make install;
        if  [ $? -eq 0  ]; then
        echo -e "\033[32mThis apr is install successfully...\033[0m"
        else
        echo -e "\033[32mThis apr is install failed,please check....\033[0m"
        exit
        fi
        cd $DIR;
        tar xzvf $APR_UTILS;
        cd $APR_UTIL;
        ./configure --prefix=$APRUTIL_DIR --with-apr=$APR_DIR &&make && make install;
        if [ $? -eq 0 ];then
        echo -e "\033[32mThis apr-util is install successfully....\033[0m"
        else
        echo -e "\033[32mThis arp in install failed, please check....\033[0m"
        exit
        fi
        cd $DIR;
        tar xzvf $APACHE_FILE; cd $APACHE;
./configure --prefix=$APACHE_DIR  --enable-so --enable-ssl --enable-cgi--enable-rewrite --with-zlib --with-pcre -
-with-apr=$APR_DIR --with-apr-util=$APRUTIL_DIR --enable-modules=most --enable-mpms-shared=all --with-mpm=event && make &
& make install
        if [ $? -eq 0 ]; then
        echo -e "\033[32mThe apache is install successful..\033[0m"
        $APACHE_DIR/bin/apachectl restart;
        else
        echo -e "\033[32mTHE apache is install failed,please check....\033[0m"
        exit
        fi
}
        sleep 3
MYSQL_FILE='mysql-5.5.44.tar.gz'
MYSQL=`echo $MYSQL_FILE | sed 's/\.tar\.gz//g'`
DATADIR=/data/mysql3306
BASEDIR=/data/app/mysql3306
MYSQL_STATUS=`ps -ef |grep mysqld_safe |awk 'NR==1 {print $9}' |sed 's#\/data\/app\/mysql3306\/bin\/##g'`
function mysql_install()
{       cd $SCRIPT_DIR ;
        if [ -f "$MYSQL_FILE" ];then
        cp  ${MYSQL_FILE} $DIR -a ;
        sleep 2
        else
        cd $DIR;
        wget -c  http://download.softagency.net/MySQL/Downloads/MySQL-5.5/$MYSQL_FILE;
        fi
        cd $DIR;
        tar xzvf $MYSQL_FILE;cd $MYSQL;mkdir -p {$DATADIR,$DATADIR};
  cmake \-DCMAKE_INSTALL_PREFIX=$BASEDIR \-DMYSQL_DATADIR=$DATADIR \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE
_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-D
WITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWIT
H_DEBUG=0 \-DMYSQL_USER=mysql \-DMYSQL_UNIX_ADDR=$DATADIR/mysql3306.sock && make && make install
         if [ $? -eq 0 ]; then
        echo -e "\033[32mthe mysql is install successful..\033[0m"
        else
        echo -e "\033[32mThis  mysql is install failed.....\033[0m"
        exit 2
        fi
        useradd mysql;
        chown -R  mysql.mysql $DATADIR;
        chown -R mysql:mysql $BASEDIR;
        cp -a support-files/my-large.cnf $DATADIR/my.cnf;
        chown -R  mysql.mysql $DATADIR/my.cnf;
        cp -a $BASEDIR/support-files/mysql.server /etc/init.d/mysqld;
#       sed  -i '/mysql3306/i datadir = /data/mysql3306\nbasedir = /data/app/mysql3306' /data/mysql3306/my.cnf;
        sed -i "26a\datadir = $DATADIR\nbasedir = $BASEDIR" $DATADIR/my.cnf;
        cd $BASEDIR;./scripts/mysql_install_db --basedir=$BASEDIR --datadir=$DATADIR --user=mysql;
echo "export PATH="\$PATH":${BASEDIR}/bin/" >>/root/.bash_profile && source /root/.bash_profile && /etc/init.d/mysqld res
tart;pkill mysql;/etc/init.d/mysqld start;/etc/init.d/mysqld restart;
        sleep 5
        if [ ${MYSQL_STATUS} = 'mysqld_safe' ];then
        echo -e "\033[32mThe Mysql was installed successfully....\033[0m"
        else
        echo -e "\033[31mThe Mysql is installed failed,Please check...\033[0m"
        exit
   fi
        sleep 3
}
PHP_FILES=php-5.4.42.tar.bz2
PHP=`echo $PHP_FILES | sed 's/\.tar\.bz2//g'`
PHP_DIR=/usr/local/php
function php_install()
{       cd $SCRIPT_DIR;
        if [ -f $PHP_FILES ];then
        cp $PHP_FILES $DIR -a ;
        else
        cd $DIR;
        wget http://mirrors.sohu.com/php/$PHP_FILES;
        fi
        cd $DIR;
        if [ -d $BASEDIR ] ; then
        tar xjvf $PHP_FILES ; cd $PHP;./configure --prefix=$PHP_DIR --with-mysql=$BASEDIR --with-openssl --with-mysqli=$B
ASEDIR/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-di
r=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-bz2 --with-config-file-path=/etc/php/php.ini --wit
h-config-file-scan-dir=/etc/php/php.d/ --with-apxs2=${APACHE_DIR}bin/apxs && make && make install
        else
        echo -e "\033[32mplease install this mysql....\033[0m"
        fi
        if [ $? -eq 0 ]; then
        echo -e "\033[32mthe php is install successful..\033[0m"

  else
        echo "the php is install failed,,,,please quit"
        exit
        fi
}
IP=`ifconfig eth0 |grep Bcast |awk '{print $2}'|sed 's/addr://g'`
function php_apache()
{
        echo -e "\033[32mIt will configure the Apache and PHP\033[0m"
        cp ${APACHE_DIR}conf/httpd.conf ${APACHE_DIR}conf/httpd.conf.bak
        echo "Addtype application/x-httpd-php  .php" >> ${APACHE_DIR}conf/httpd.conf
        sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' ${APACHE_DIR}conf/httpd.conf
        if [ $? -eq 0 ];then
        echo -e "\033[32mIt's successfully, Will test the PHP... \033[0m"
        rm -rf ${APACHE_DIR}htdocs/*;
         cat >${APACHE_DIR}htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF
        if [ $? -eq 0 ];then
#启动apache服务
        ${APACHE_DIR}bin/apachectl restart ;
        ${APACHE_DIR}bin/apachectl restart ;
        echo -e "\033[32mYou can access http://${IP}/index.php\033[0m"
fi
        else
        echo -e "\033[31mThe PHP is installed failed,Please check...\033[0m"
        exit
        fi
}
Discuz_file=Discuz_X3.1_SC_UTF8.zip
Discuz=Discuz_X3.1_SC_UTF8
PASSWORD=123456
function discuz_install()
{       cd $SCRIPT_DIR;
        if [ -f $Discuz_file ];then
        cp $Discuz_file $DIR -a ;
        sleep 2
        else
        cd $DIR;
        wget -c http://download.comsenz.com/DiscuzX/3.1/$Discuz_file;
        fi
        cd $DIR;
        rm -rf ${APACHE_DIR}htdocs/* && unzip $Discuz_file -d ${APACHE_DIR}htdocs/ ;
        cd ${APACHE_DIR}htdocs/ && mv upload/* . && chmod -R o+w data/ config/ uc_server/ uc_client/;
        if [ $? -eq 0 ];then
        echo -e '\033[32mThis discuz is files configure ok....\033[0m'
#设置数据库密码和创建数据库
        $BASEDIR/bin/mysqladmin -uroot password $PASSWORD &&
        mysql -uroot -h 127.0.0.1 -p$PASSWORD -e "create database discuz;"&&
#授权discuz用户
        mysql -uroot -h 127.0.0.1 -p$PASSWORD -e "grant all on *.* to discuz@'${IP}' identified by '$PASSWORD';flush priv
ileges;"
if [ $? -eq 0 ];then
        echo -e "\033[32mThis discuz  database configure is  success.....\033[0m"
        else
        echo -e "\033[32mThis discuz database configure is failed..please check..\033[0m"
        fi
#重启apache服务和mysql
        ${APACHE_DIR}bin/apachectl restart&& /etc/init.d/mysqld restart;
        if [ $? -eq 0 ];then
        echo -e "\033[32mThe apache and Mysql Start Success!\033[0m"
        else
        echo -e "\033[31mThis discuz configure is failed..please check.\033[0m"
        fi
        else
        echo -e  "\033[32mThe mysql and apache is failed....please check.\033[0m"
        echo -e  "\033[32mThis discuz is install success.......\033[32m"
        exit 2
        fi
}
PS3="please select your install menu:"
        select i in "httpd" "mysql" "php" "php+apache" "discuz" "quit" "all_auto"
        do
        case $i in
        httpd )
        httpd_install
        ;;
        mysql )
        mysql_install
        ;;
   php )
        php_install
        ;;
        php+apache )
        php_apache
        ;;
        discuz )
        discuz_install
        ;;
        all_auto )
        httpd_install;
        mysql_install;
        php_install;
        php_apache;
        discuz_install
        ;;
        quit )
        exit
        ;;
        * )
        echo "Usage: $0 {httpd|mysql|php|php+apache|discuz|all_auto|quit}"
esac
        done

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-90958-1-1.html 上篇帖子: 单机lamp环境一键安装部署 下篇帖子: 源码编译lnmp(Nginx 1.8 + MySQL5.5 + PHP 5.3) discuz
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表