LAMP 自动安装脚本

回复 收藏
自己写的脚本,请大神指正。本案环境为centos6最小化安装初装系统,手动配置IP后使用。
  1. #Install LAMP
  2. #by liusheng on 2015-4-28
  3. ### ENV ###
  4. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
  5. lamp_log=/root/lamp_install.log
  6. downdir=/usr/local/src
  7. ### error ###
  8. error_imp() {
  9.         if [ "$?" != '0' ] ;then
  10.                 echo "Have same error"
  11.                 exit 1
  12.         fi
  13. }
  14. ### Clear Log File ###
  15. echo "" > $lamp_log
  16. ### Install wget software ###
  17. rpm -q wget
  18. if [ "$?" != '0' ] ;then
  19.         yum install wget -y
  20. fi
  21. ### Which version to install ###
  22. echo -e "\033[36m \n Hello ,Welcome to test my script \n If you have any questions please E-mail to zmyxn@163.com \n --------------------------------------------------\n \033[0m"
  23. echo -e "\033[34m 1.MySQL-5.7.6 + Http-2.4.9 + Php-5.6.6 \033[0m"
  24. echo -e "\033[34m 2.MySQL-5.1.40 + Http-2.2.16 + Php-5.3.29 \033[0m"
  25. echo -e "\033[34m Any other key is exit \033[0m"
  26. read -p "Do you want to install 1 or 2 :" answer
  27. case $answer in
  28. 1)
  29.         mysql_ver=http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
  30.         httpd_ver=http://archive.apache.org/dist/httpd/httpd-2.4.9.tar.gz
  31.         apr_util_ver=http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
  32.         apr_ver=http://mirrors.cnnic.cn/apache/apr/apr-1.5.1.tar.gz
  33.         php_ver=http://mirrors.sohu.com/php/php-5.6.6.tar.gz
  34.         wget -P $downdir -o $lamp_log $mysql_ver $apr_ver $apr_util_ver $php_ver $httpd_ver
  35.         mysql_ver="mysql-5.7.6-m16-linux-glibc2.5-x86_64"
  36.         httpd_ver="httpd-2.4.9"
  37.         php_ver="php-5.6.6"
  38.         apr_ver="apr-1.5.1"
  39.         apr_util_ver="apr-util-1.5.4" ;;
  40. 2)
  41.         mysql_ver=http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gz
  42.         httpd_ver=http://archive.apache.org/dist/httpd/httpd-2.2.16.tar.gz
  43.         php_ver=http://mirrors.sohu.com/php/php-5.3.29.tar.gz
  44.         wget -P $downdir -o $lamp_log $mysql_ver $httpd_ver $php_ver
  45.         mysql_ver="mysql-5.1.72-linux-x86_64-glibc23"
  46.         httpd_ver="httpd-2.2.16"
  47.         php_ver="php-5.3.29" ;;
  48. *)
  49.         echo "TO exit setup"
  50.         exit 1 ;;
  51. esac
  52. ### Rely On Software ###
  53. rpm -q libmcrypt-devel
  54. if [ "$?" != '0' ] ;then
  55.         yum install epel-release -y
  56.         yum install libmcrypt-devel -y
  57. fi
  58. rpm -q gcc libaio pcre-devel perl libxml2-devel openssl-devel bzip2-devel freetype-devel libjpeg-devel libpng-devel | sed -n -r 's/^package (.*) is.*ed$/\1/p' | xargs yum install -y
  59. $error_imp
  60. ### INSTALL MYSQL ###
  61. echo -e "Now Install Mysql , Please Waiting" | tee -a $lamp_log
  62. useradd -s /sbin/nologin mysql
  63. tar zxf $downdir/$mysql_ver.tar.gz -C /usr/local/ 1>/dev/null 2>$lamp_log
  64. ln -s /usr/local/$mysql_ver /usr/local/mysql
  65. chown -R mysql:mysql /usr/local/mysql/
  66. mkdir -p /data/mysql
  67. chown -R mysql /data/mysql
  68. echo -e "Create /etc/my.cnf \n and /etc/init.d/mysqld" | tee -a $lamp_log
  69. if [ $mysql_ver = "mysql-5.7.6-m16-linux-glibc2.5-x86_64" ];then
  70.         cd /usr/local/mysql
  71.         ./bin/mysql_install_db --user=mysql --datadir=/data/mysql >> $lamp_log
  72.         cp -r /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
  73. else
  74.         cd /usr/local/mysql
  75.         ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql >> $lamp_log
  76.         cp -r /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
  77.         sed -i '/^\[mysqld\]$/a\datadir = /data/mysql' /etc/my.cnf
  78. fi
  79. ### Add Mysqld Service ###
  80. cp -r /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
  81. sed -r -i 's#^basedir=$#basedir=/usr/local/mysql#' /etc/init.d/mysqld
  82. sed -r -i 's#^datadir=$#datadir=/data/mysql#' /etc/init.d/mysqld
  83. chmod 755 /etc/init.d/mysqld
  84. chkconfig --add mysqld
  85. service mysqld start
  86. $error_imp
  87. ### INSTALL APACHE ###
  88. ### Install httpd-2.4.9 rely on software
  89. if [ $httpd_ver = "httpd-2.4.9" ];
  90. then
  91.         echo "NOW INSTALL APR , Please waiting" | tee -a $lamp_log
  92.         cd $downdir/
  93.         tar -zxf $downdir/$apr_ver.tar.gz
  94.         cd $downdir/$apr_ver
  95.         ./configure --prefix=/usr/local/apr 1>/dev/null 2>$lamp_log
  96.         make 1>/dev/null 2>$lamp_log
  97.         make install 1>/dev/null 2>$lamp_log
  98.         echo "NOW INSTALL APR-UTIL, Please waiting" | tee -a $lamp_log
  99.         cd $downdir/
  100.         tar -zxf $downdir/$apr_util_ver.tar.gz
  101.         cd $downdir/$apr_util_ver
  102.         ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ 1>/dev/null 2>$lamp_log
  103.         make 1>/dev/null 2>$lamp_log
  104.         make install 1>/dev/null 2>$lamp_log
  105. fi
  106. ### INSTALL HTTP ###
  107. echo "Now INSTALL $httpd_ver ,Please waiting" | tee -a $lamp_log
  108. cd $downdir/
  109. tar zxf $downdir/$httpd_ver.tar.gz
  110. cd $downdir/$httpd_ver/
  111. if [ $httpd_ver = "httpd-2.4.9" ];then
  112.         ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-mods-shared=most --enable-so 1>/dev/null 2>$lamp_log
  113. else
  114.         ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so 1>/dev/null 2>$lamp_log
  115. fi
  116. make 1>/dev/null 2>$lamp_log
  117. make install 1>/dev/null 2>$lamp_log
  118. $error_imp
  119. ### Add Httpd Service ###
  120. cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
  121. sed -i 's/#ServerName www.example.com:80$/ServerName localhost.com:80/' /usr/local/apache2/conf/httpd.conf
  122. sed -i '/bin\/sh/a\# description:Apache' /etc/rc.d/init.d/httpd
  123. sed -i '/bin\/sh/a\# chkconfig: 35 61 61' /etc/rc.d/init.d/httpd
  124. chkconfig --add httpd
  125. chkconfig httpd on
  126. service httpd start
  127. $error_imp
  128. ### INSTALL PHP ###
  129. echo "NOW INSTALL $php_ver , Please waiting" | tee -a $lamp_log
  130. cd $downdir/
  131. tar zxf $downdir/$php_ver.tar.gz
  132. cd $downdir/$php_ver/
  133. ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 1>/dev/null 2>$lamp_log
  134. make 1>/dev/null 2>$lamp_log
  135. make install 1>/dev/null 2>$lamp_log
  136. $error_imp
  137. ### Edit The Configuration File ###
  138. echo "Edit the configuration file" | tee -a $lamp_log
  139. sed -i '/AddType .*.gz .tgz$/a\\AddType application/x-httpd-php .php' /usr/local/apache2/conf/httpd.conf
  140. sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/' /usr/local/apache2/conf/httpd.conf
  141. cat > /usr/local/apache2/htdocs/index.php <
  142. EOF
  143. echo "LAMP is installed,Please Restart HTTP Service And Curl " | tee -a $lamp_log


2015-04-29 13:13 举报
已邀请:
0

模范棒棒糖

赞同来自:

六期的大神在这里啊。
0

疾风

赞同来自:

膜拜大神,看不懂
0

billc

赞同来自:

0

billc

赞同来自:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: