标签:shell
#!/bin/bash
#2017-8-21 14:24:26
#author guojuwnei
#descrption 源码安装lamp,Case+Select+函数
#Httpd 常量定义
H_URL=http://mirror.bit.edu.cn/apache/httpd/
H_FILES=httpd-2.2.34.tar.gz
H_FILES_DIR=httpd-2.2.34
H_PREFIX=/usr/local/apache
#Mysql 常量定义
M_URL=https://downloads.mysql.com/archives/get/file/
M_FILES=mysql-5.6.11.tar.gz
M_FILES_DIR=mysql-5.6.11
M_PREFIX=/usr/local/mysql
#Php 常量定义
P_URL=http://mirrors.sohu.com/php/
P_FILES=php-5.6.30.tar.gz
P_FILES_DIR=php-5.6.30
P_PREFIX=/usr/local/php
########################## httpd ############################
function install_httpd(){
yum install -y wget apr apr-devel apr-util apr-util-devel pcre pcre-devel
wget -c $H_URL$H_FILES && tar -xzf $H_FILES && cd $H_FILES_DIR && ./configure --prefix=$H_PREFIX --enable-so --enable-rewrite
if [[ $? -eq 0 ]];then
make && make install
echo -e "\033[33m----------------恭喜!安装apache成功-----------------------\033[0m"
exit 0
fi
}
######################## mysql ############################
function install_mysql(){
wget -c $M_URL$M_FILES && tar -xzf $M_FILES && cd $M_FILES_DIR && yum install -y cmake ncurses-devel; rm -rf CMakeCache.txt; cmake . -DCMAKE_INSTALL_PREFIX=$M_PREFIX \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=/data/mysql \
-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_READLING=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWIT_EXTRA_CHARSETS=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BIG_TABLES=1 \
-DWITH_DEBUG=0
if [ $? -eq 0 ];then
make && make install
echo -e "\033[33m---------------------------------------\033[0m"
echo -e "\033[32m 这个$M_FILES_DIR 服务安装成功\033[0m"
else
echo -e "\033[32m 这个$M_FILES_DIR make或者make install失败\033[0m"
exit 0
fi
cp support-files/mysql.server /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf
chmod o+x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
chown -R mysql.mysql /usr/local/mysql/
mkdir -p /data/mysql
useradd -s /sbin/nologin mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql/ >dev/null
ln -sf /usr/local/mysql/bin/* /usr/bin/
}
######################## php ################################
function install_php(){
yum install libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel libxml2-devel curl curl-devel openssl-devel -y
wget -c $P_URL$P_FILES && tar -xzf $P_FILES && cd $P_FILES_DIR && ./configure --prefix=$P_PREFIX --with-config-file-path=$P_PREFIX/etc --with-mysql=$M_PREFIX --with-mysqli=$M_PREFIX/bin/mysql_config --with-pdo-mysql=$M_PREFIX --with-openssl --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-apxs2=/usr/local/apache/bin/apxs
if [ $? -eq 0 ] ;then
make && make install
echo -e "\033[32m--------------- 这个$P_FILES_DIR 服务安装成功-----------------\033[0m"
exit 0
else
echo -e "\033[32m 这个$P_FILES_DIR make或者make install失败\033[0m"
exit 0
fi
}
######################### 整合 #######################################
function server_integrate(){
cp $H_PREFIX/conf/httpd.conf $H_PREFIX/conf/httpd.conf.bak
sed -i ‘s/DirectoryIndex index.html/DirectoryIndex index.php index.html/g‘ $H_PREFIX/conf/httpd.conf
QUERY=`grep "application/x-httpd-php .php" $H_PREFIX/conf/httpd.conf |wc -l`
if [[ $QUERY -eq ‘0‘ ]];then
echo ‘AddType application/x-httpd-php .php‘ >> $H_PREFIX/conf/httpd.conf
fi
IP=`ifconfig eth0 | grep "Bcast" | awk ‘{print $2}‘ |cut -d: -f2`
echo "你可以通过下面的IP访问 $IP"
$H_PREFIX/bin/apachectl restart
cat > $H_PREFIX/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF
}
####################### 插件选择 ################################
PS3="Please enter you select install menu:"
select i in httpd mysql php integrate quit
do
case $i in
httpd)
install_httpd;
;;
mysql)
install_mysql;
;;
php)
install_php;
;;
integrate)
server_integrate;
;;
quit)
echo -e "\033[33m 你选择了退出 \033[0m"
exit 0;
;;
*)
echo -e "\033[33mplease use $0 by select the follow option\033[0m"
exit 0
;;
esac
done
本文出自 “12605759” 博客,请务必保留此出处http://12615759.blog.51cto.com/12605759/1958095
标签:shell
原文地址:http://12615759.blog.51cto.com/12605759/1958095