#!/bin/bash
# date: 2016-03-12
# desc: LAN/MP auto install script
# Author: Djoker
#function area
#<---------------------start---------------------------------------->
#function: check error
runcheck(){
if [ $1 != 0 ];then
echo "------------------------"
echo "|Error,please check log|"
echo "------------------------"
exit 1
fi
}
#function: yum install base packets
yumins(){
while [ -n "$1" ]
do
yum -y install $1
runcheck $?
echo
echo "$1 is install ......over!"
echo
sleep 1
shift
done
}
#function: install mysql
install_mysql_func(){
cd /tmp
if [ -e mysql-5.5.22.tar.gz ];then
echo "file is exist!!!"
else
wget http://down1.chinaunix.net/distfiles/mysql-5.5.22.tar.gz
runcheck $?
fi
tar vxf mysql-5.5.22.tar.gz
cd mysql-5.5.22
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -Wno-dev
runcheck $?
make && make install
runcheck $?
}
#function: config mysql
config_mysql_func(){
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql
chmod +x /tmp/mysql-5.5.22/scripts/mysql_install_db
/tmp/mysql-5.5.22/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
runcheck $?
cp -a /tmp/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
echo "PATH=\$PATH:/usr/local/mysql/bin" >> /etc/profile
chkconfig --add mysqld
service mysqld start
chkconfig mysqld on
runcheck $?
}
#function: install php
install_php_func(){
cd /tmp
if [ -e libmcrypt-devel-2.5.7-1.2.el6.rf.x86_64.rpm ];then
echo "file aready is install ."
else
wget http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/libmcrypt-devel-2.5.7-1.2.el6.rf.x86_64.rpm
rpm --nodeps -i libmcrypt-devel-2.5.7-1.2.el6.rf.x86_64.rpm
fi
if [ -e php-5.4.6.tar.bz2 ];then
echo "file is exit!!!"
else
wget wget http://down1.chinaunix.net/distfiles/php-5.4.6.tar.bz2
runcheck $?
fi
tar vxf php-5.4.6.tar.bz2
cd php-5.4.6
./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt=/usr/local/libmcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --enable-pdo --with-pdo-mysql --with-gettext --with-curl --with-pdo-mysql --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --enable-freetyp
runcheck $?
make && make install
runcheck $?
}
#function: config php
config_php_func(){
cp /tmp/php-5.4.6/php.ini-development /usr/local/php/etc/php.ini
cp /tmp/php-5.4.6/sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
echo ‘#!/bin/sh
# DateTime: 2013-09-16
# Author: lianbaikai
# site:http://www.ttlsa.com/html/3039.html
# chkconfig: - 84 16
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
phpfpm="/usr/local/php/sbin/php-fpm"
prog=$(basename ${phpfpm})
lockfile=/var/lock/subsys/phpfpm
start() {
[ -x ${phpfpm} ] || exit 5
echo -n $"Starting $prog: "
daemon ${phpfpm}
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc ${phpfpm} -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
${phpfpm} -t
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit 2
esac‘ > /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
}
#function: install httpd
install_httpd_func(){
cd /tmp
if [ -e httpd-2.2.9.tar.bz2 ];then
echo "file is exit!!!"
else
wget http://down1.chinaunix.net/distfiles/httpd-2.2.9.tar.bz2
runcheck $?
fi
tar vxf httpd-2.2.9.tar.bz2
cd httpd-2.2.9
./configure --prefix=/usr/local/apache --enable-so --enable-cgi --enable-rewreite --with-zlib --with-pcre --enable-modules=all --enable-mpms-shared=all
runcheck $?
make && make install
runcheck $?
}
#function: config httpd
config_httpd_func(){
echo "1"
}
#function: install nginx
install_nginx_func(){
cd /tmp
if [ -e nginx-1.2.1.tar.gz ];then
echo "file is exit!!!"
else
wget http://down1.chinaunix.net/distfiles/nginx-1.2.1.tar.gz
runcheck $?
fi
tar xvf nginx-1.2.1.tar.gz
cd nginx-1.2.1
./configure --prefix=/usr/local/nginx --with-select_module --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_flv_module --with-http_mp4_module --with-http_stub_status_module --with-debug
runcheck $?
make && make install
runcheck $?
}
#function: config nginx
#config_nginxf_func(){
#}
#<---------------------stop---------------------------------------->
#main
echo
while true
do
read -p "Do you want to running Script ? [Y|N]:" choise
if [ -n "$choise" ];then
if [ $choise = "y" ] ||[ $choise = "y" ] ;then
break
elif [ $choise = "N" ] || [ $choise = "n" ] ;then
exit 1
else
echo "Please input Y|N !,try agint"
echo
fi
else
echo "Please input Y|N !,try agint"
echo
fi
done
#install base packets
yumins vim make gcc openssl openssl-devel
#install_MySQL
echo "check mysql deps packets"
yumins cmake ncurses-devel ncurses-libs
echo "start install mysql!!!"
sleep 1
install_mysql_func
runcheck $?
echo "start config mysql"
config_mysql_func
echo "mysql install end !!!"
sleep 1
#install_php
echo "check php deps packets"
yumins libxml2-devel bzip2 bzip2-devel libcurl-devel gd gd-devel libgcrypt libjpeg* libpng-devel
echo "start install php!!!"
sleep 1
install_php_func
runcheck $?
echo "start config php"
config_php_func
echo "php install end !!!"
sleep 1
while true
do
read -p ‘Do you want to install Nginx or Httpd, 1 is Nginx , 2 is Httpd [1|2]: ‘ hnchoise
if [ $hnchoise -eq 1 ];then
#install_httpd
echo "start install httpd!!!"
sleep 1
install_httpd_func
runcheck $?
echo "start config httpd !!!"
config_httpd_func
echo "httpd install end !!!"
sleep 1
break
elif [ $hnchoise -eq 2 ];then
#install_Nginx
echo "start install nginx!!!"
install_nginx_func
runcheck $?
echo "nginx install end !!!"
sleep 1
break
else
echo "Please input 1 or 2 ,conntinue? "
echo
fi
done
echo
echo ‘-----------------‘
echo ‘|Install is End!|‘
echo ‘-----------------‘本文出自 “anka” 博客,请务必保留此出处http://anka0501.blog.51cto.com/10129669/1750715
原文:http://anka0501.blog.51cto.com/10129669/1750715