#!/bin/bash #write by zhang_pc #at 2015.08.07 #apache2.4 php.5.4 mysql5.5 #脚本说明,如果脚本所在目录有源码包就用本地的,否则就从互联网下载 APR_FILES=apr-1.5.2.tar.gz APR_DIR=apr-1.5.2 ARP_PRE=/usr/local/apr APR_URL=http://mirror.bit.edu.cn/apache/apr/apr-1.5.2.tar.gz APR_U_FILES=apr-util-1.5.4.tar.gz APR_U_DIR=apr-util-1.5.4 APR_U_PRE=/usr/local/apr-util APR_U_URL=http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.4.tar.gz A_FILES=httpd-2.4.16.tar.gz A_DIR=httpd-2.4.16 A_PRE=/usr/local/apache A_URL=http://mirrors.sohu.com/apache/httpd-2.4.16.tar.gz M_FILES=mysql-5.5.44.tar.gz M_DIR=mysql-5.5.44 M_PRE=/usr/local/mysql M_URL=http://download.softagency.net/MySQL/Downloads/MySQL-5.5/mysql-5.5.44.tar.gz P_FILES=php-5.4.22.tar.gz P_DIR=php-5.4.22 P_PRE=/usr/local/php P_URL= function apr_install() { yum install -y gcc tar -zxvf $APR_FILES;cd $APR_DIR;./configure --prefix=$APR_PRE && make && make install if [ $? -eq 0 ];then echo "the apr install is successful" else echo "the apr install is failed" fi } function apr_util_install() { tar -zxvf $APR_U_FILES;cd $APR_U_DIR;./configure --prefix=$APR_U_PRE --with-apr=$APR_PRE && make && make install if [ $? -eq 0 ];then echo "the apr_util install is successful" else echo "the apr_util install is failed" fi } function apache_install() { yum install pcre-devel openssl-devel-y tar -zxvf $A_FILES;cd $A_DIR ./configure --prefix=$A_PRE --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-arp=$APR_PRE --with-apr-util=$APR_U_PRE --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork make -j2 && make install -j2 if [ $? -eq 0 ];then echo "the apache install is successful" else echo "the apache install is failed" exit fi } function mysql_install() { yum install gcc-c++ cmake ncurses-devel bison perl -y useradd -s /sbin/nologin mysql mkdir -p /data/mysql chown -R mysql.mysql /data/mysql tar -zxvf $M_FILES;cd $M_DIR cmake -DCMAKE_INSTALL_PREFIX=$M_PRE -DMYSQL_DATADIR=/data/mysql -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 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_USER=mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock make -j2 && make install -j if [ $? -eq 0 ];then echo "the mysql is successful" else echo "the mysql is failed" exit fi } function php_install() { yum install libxml2-devel libmcrypt-devel bzip2-devel libxml2-devel openssl-devel bzip2 bzip2-devel -y tar -zxvf $P_FILES;cd $P_DIR ./configure --prefix=$P_PRE --with-config-file-path=$P_PRE/etc --with-apxs2=$A_PRE/bin/apxs --with-mysql=$M_PRE make -j2 && make install if [ $? -eq 0 ];then echo "the php is successful" else echo "the php is failed" exit fi } function lamp_zh() { sed -i "s/#ServerName www.example.com:80/ServerName www.example.com:80/g" /usr/local/apache/conf/httpd.conf sed -i "s/DirectoryIndex index.html/DirectoryIndex index.php index.html/g" /usr/local/apache/conf/httpd.conf sed -i ‘310a AddType application/x-httpd-php .php‘ /usr/local/apache/conf/httpd.conf /usr/local/apache/bin/apachectl start /bin/cp ./$M_DIR/support-files/my-medium.cnf /etc/my.cnf /bin/cp ./$M_DIR/support-files/mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld sed -i ‘38a datadir=/data/mysql‘ /etc/my.cnf sed -i ‘38a basedir=/usr/local/mysql‘ /etc/my.cnf /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql /etc/init.d/mysqld start chkconfig --add mysqld echo "PATH=$PATH:/usr/local/mysql/bin">>/etc/profile source /etc/profile } cat <<EOF +------------------------------------------------------------+ | 欢迎使用一键安装LAMP脚本 | +------------------------------------------------------------+ EOF PS3="please select:" select a in apr_install apr_util_install apache_install mysql_install php_install lamp_zh do case $a in apr_install) if [ -f $APR_FILES ];then apr_insatll else wget $APR_URL && apr_install fi exit ;; apr_util_install) if [ -f $APR_U_FILES ];then apr_util_install else wget $APR_U_URL && apr_util_install fi exit ;; apache_install) if [ -f $A_FILES ];then apache_install else wget $A_URL && apache_install fi exit ;; mysql_install) if [ -f $M_FILES ];then mysql_install else wget $M_URL && mysql_install fi exit ;; php_install) if [ -f $P_FILES ];then php_install else wget $P_URL && php_install fi exit ;; lamp_zh) lamp_zh exit ;; *) echo -e "\033[32m please enter the correct choice\033[0m" echo -e "\033[32m1 apr_install\033[0m" echo -e "\033[32m2 apr-util_install\033[0m" echo -e "\033[32m3 apache_install\033[0m" echo -e "\033[32m4 mysql_install\033[0m" echo -e "\033[32m5 php_install\033[0m" echo -e "\033[32m6 lamp_zh\033[0m" ;; esac done
时间: 2024-10-17 01:49:17