脚本部署lamp

来源:互联网 发布:c语言简单小游戏 编辑:程序博客网 时间:2024/06/01 09:20
#!/bin/bash#2017年11月9日22:00:49#by author lee#auto intall lamp with make#########################PACKAGE_DIR="/root/package"IP_ADDR=`ifconfig | grep "Bcast:" | awk '{ print $2 }' | sed 's/^.*addr://g'`#HTTP PATHH_NAME=httpd-2.2.34.tar.gzH_DIR=httpd-2.2.34H_URL=http://mirror.bit.edu.cn/apache/httpdH_PREFIX=/usr/local/apache2#MYSQL PATHM_NAME=mysql-5.5.20.tar.gzM_DIR=mysql-5.5.20M_URL=http://down1.chinaunix.net/distfilesM_PREFIX=/usr/local/mysql55M_DATA=/data/mysql#PHP PATHP_NAME=php-5.3.28.tar.bz2P_DIR=php-5.3.28P_URL=http://mirrors.sohu.com/phpP_PREFIX=/usr/local/php5# echo "3s later to install lamp!"# sleep 3check_error(){if [ $? != 0 ]then    echo "there is error you should check!!!"    exit 1fi}mkdir -p $PACKAGE_DIR#########################install_httpd(){yum install apr apr-devel apr-util apr-util-devel -ycd $PACKAGE_DIRwget $H_URL/$H_NAMEtar zxvf $H_NAMEcd $H_DIR./configure --prefix=$H_PREFIX/ --enable-rewrite --enable-socheck_errormake && make installcheck_errorecho "apache install success!!!!!!!!!!!!"}#########################install_mysql(){yum  install  cmake  gcc-c++ ncurses-devel ncurses cmake bison library* libncurses5-dev g++ kdelibs5-dev make -ygroupadd mysqluseradd -r -g mysql mysqlcd $PACKAGE_DIRwget $M_URL/$M_NAMEtar -zxvf $M_NAMEcd $M_DIRmkdir -p $M_DATAmkdir -p $M_PREFIXcmake  .  -DCMAKE_INSTALL_PREFIX=$M_PREFIX/ \-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DMYSQL_DATADIR=$M_DATA \-DSYSCONFDIR=/etc \-DMYSQL_USER=mysql \-DMYSQL_TCP_PORT=3306 \-DWITH_XTRADB_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DENABLED_LOCAL_INFILE=1 \-DWITH_EXTRA_CHARSETS=1 \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DEXTRA_CHARSETS=all \-DWITH_BIG_TABLES=1 \-DWITH_DEBUG=0check_errormake && make installcheck_errorcd $M_DATAchown -R mysql:mysql .cd $M_PREFIXchown -R mysql:mysql ./bin/cp support-files/my-large.cnf /etc/my.cnf/bin/cp support-files/mysql.server /etc/init.d/mysqld chmod o+x /etc/init.d/mysqldchkconfig --add mysqld chkconfig --level 35 mysqld on/usr/local/mysql55/scripts/mysql_install_db --user=mysql --datadir=$M_DATA --basedir=$M_PREFIX/ln  -s  /usr/local/mysql55/bin/* /usr/bin/service  mysqld  restartcheck_errorecho "mysql install success!!!!!!!!!!!!"}#########################install_php(){yum install -y libxml2 libxml2-develcd $PACKAGE_DIRwget $P_URL/$P_NAMEtar -xjf $P_NAMEcd $P_DIR./configure --prefix=$P_PREFIX --with-config-file-path=$P_PREFIX/etc   --with-apxs2=$H_PREFIX/bin/apxs  --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlndcheck_errormake && make installcheck_errorecho "php install success!!!!!!!!!!!!"sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php-source .php5' $H_PREFIX/conf/httpd.confsed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php .php' $H_PREFIX/conf/httpd.confsed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/' $H_PREFIX/conf/httpd.confsed -i 's/\#ServerName www.example.com/ServerName 127.0.0.1/' $H_PREFIX/conf/httpd.conftouch $H_PREFIX/htdocs/index.phpecho "<?phpphpinfo();?>" > $H_PREFIX/htdocs/index.php$H_PREFIX/bin/apachectl restartservice iptables stopsetenforce 0echo "lamp install success!!please input http://$IP_ADDR/"}########################## set_apache_php(){# sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php-source .php5' $H_PREFIX/conf/httpd.conf# sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php .php' $H_PREFIX/conf/httpd.conf# sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/' $H_PREFIX/conf/httpd.conf# touch $H_PREFIX/htdocs/index.php# echo "<?php# phpinfo();# ?>" > $H_PREFIX/htdocs/index.php# $H_PREFIX/bin/apachectl restart# }########################## install_lamp(){# install_httpd# install_mysql# install_php# set_apache_php# service iptables stop# setenforce 0# echo "lamp install success!!please input http://$IP_ADDR/"# }# install_lamp#########################echo "输入对应的数字来完成你要做的操作"echo "1)    安装apache"echo "2)    安装mysql"echo "3)    安装php"echo "0)    退出"read -t 10 -p "please input the num you want to do:" inputtime="sleep 2"case $input in 1)    install_httpd    ;;2)    install_mysql    ;;3)    install_php    ;;0)    exit 0    ;;*)    echo "please input the right choice"    ;;esac