|
#!/bin/sh
################################################
# e_mail:yu8850235@gmail.com
# blog:http://www.iyunv.com/windyyu/
# LNMP version:1.0 for CentOS6.X
################################################
#Source function library
. /etc/init.d/functions
#check system
REL=`awk -F '[. ]' '{print $1,$3}' /etc/redhat-release`
if [ "$REL" != "CentOS 6" ];then
echo "Sorry,this script for CentOS 6.X"
exit 1
fi
#use root to run this script
uid=`id | cut -d\( -f1 | cut -d= -f2`
if [ $uid -ne 0 ];then
action "Please run this script use root." /bin/false
exit 1
fi
initTools(){
yum groupinstall \
"Performance Tools" \
"debugging Tools" \
"Dial-up Networking Support" \
"Compatibility libraries" \
"Base" \
"Development tools" \
"Hardware monitoring utilities" -y
}
initNginx(){
yum install openssl-devel -y
useradd nginx -s /sbin/ -M
#wget nginx and pcre
cd /usr/local/src/
wget http://down1.chinaunix.net/distfiles/pcre-8.30.tar.bz2
wget http://nginx.org/download/nginx-1.4.7.tar.gz
#install pcre
tar jxf pcre-8.30.tar.bz2
cd pcre-8.30/
./configure
make && make install
if [ $? -ne 0 ];then
action "install pcre is failed!" /bin/false
exit $?
fi
cd ..
sleep 2
#install nginx
tar zxf nginx-1.4.7.tar.gz
cd nginx-1.4.7
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
if [ $? -ne 0 ];then
action "install nginx is failed!" /bin/false
exit $?
fi
sleep 2
#lib
echo "/usr/local/lib/" >>/etc/ld.so.conf
ldconfig
#check nginx
/usr/local/nginx/sbin/nginx
if [ `netstat -lnpt |grep nginx|wc -l` -eq 1 ];then
echo "+---------------------------+"
echo "+------nginx安装完成--------+"
echo "+---------------------------+"
fi
/usr/local/nginx/sbin/nginx -s stop
sleep 3
}
#camke install mysql5.5.X
initMysql(){
yum install cmake -y
yum install ncurses-devel -y
useradd mysql -s /sbin/nologin -M
cd /usr/local/src/
wget https://www.pccc.com/downloads/apache/current/mysql-5.5.38.tar.gz
tar zxf mysql-5.5.38.tar.gz
cd mysql-5.5.38
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
make && make install
if [ $? -ne 0 ];then
action "install mysql is failed!" /bin/false
exit $?
fi
sleep 2
#copy config and start file
/bin/cp /usr/local/src/mysql-5.5.38/support-files/my-medium.cnf /etc/my.cnf
cp /usr/local/src/mysql-5.5.38/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
#init mysql
chown -R mysql.mysql /usr/local/mysql/data/
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
if [ $? -ne 0 ];then
action "install mysql is failed!" /bin/false
exit $?
fi
#check mysql
/etc/init.d/mysqld start
if [ $? -ne 0 ];then
action "mysql start is failed!" /bin/false
exit $?
fi
/usr/local/mysql/bin/mysql -e "select version();" >/dev/null 2>&1
if [ $? -eq 0 ];then
echo "+---------------------------+"
echo "+------mysql安装完成--------+"
echo "+---------------------------+"
fi
/etc/init.d/mysqld stop
sleep 3
}
#install php
initPhp(){
yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y
#install libiconv
cd /usr/local/src
wget http://mirrors.ibiblio.org/gnu/ftp/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
[ $? -ne 0 ] && {
action "install libiconv failed!" /bin/false
exit $?
}
sleep 2
cd ../
#install libmcrypt
wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
sleep 2
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
[ $? -ne 0 ] && {
action "install libmcrypt failed!" /bin/false
exit $?
}
sleep 2
cd ../../
#install mhash
wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
[ $? -ne 0 ] && {
action "install mhash failed!" /bin/false
exit $?
}
sleep 2
cd ../
rm -f /usr/lib64/libmcrypt.*
rm -f /usr/lib64/libmhash*
ln -s /usr/local/lib64/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib64/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib64/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib64/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib64/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib64/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib64/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib64/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib64/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
#install mcrypt
wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
[ $? -ne 0 ] && {
action "install mcrypt failed!" /bin/false
exit $?
}
cd ../
sleep 2
#install php
yum install libxslt-devel -y
ln -s //usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
wget http://mirrors.sohu.com/php/php-5.3.27.tar.gz
tar zxf php-5.3.27.tar.gz
cd php-5.3.27
./configure \
--prefix=/usr/local/php \
--with-mysql=//usr/local/mysql \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr/ \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
make && make install
[ $? -ne 0 ] && {
action "install php failed!" /bin/false
exit $?
}
cp /usr/local/src/php-5.3.27/php.ini-production /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
/usr/local/php/php/sbin/php-fpm
if [ $? -eq 0 ];then
echo "+---------------------------+"
echo "+--------php安装完成--------+"
echo "+---------------------------+"
fi
sleep 2
}
initPhpCacheModule(){
echo 'export LC_ALL=C' >>/etc/profile
tail -1 /etc/profile
. /etc/profile
yum install perl-devel -y
cd /usr/local/src
#install eaccelerator
wget http://pkgs.fedoraproject.org/repo/pkgs/php-eaccelerator/eaccelerator-0.9.6.tar.bz2/85fa6150265a81f0cea852bc973382b9/eaccelerator-0.9.6.tar.bz2
tar jxf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install
[ $? -ne 0 ] && {
action "install eaccelerator failed!" /bin/false
exit $?
}
cd ../
sleep 2
#install memcache
wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar zxf memcache-2.2.5.tgz
cd memcache-2.2.5
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
[ $? -ne 0 ] && {
action "install memcache failed!" /bin/false
exit $?
}
cd ../
sleep 2
#install PDO_MYSQL
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
tar zxf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make && make install
[ $? -ne 0 ] && {
action "install PDO_MYSQL failed!" /bin/false
exit $?
}
cd ../
sleep 2
#install ImageMagick
yum install perl-devel -y
wget http://down1.chinaunix.net/distfiles/ImageMagick-6.5.1-0.tar.bz2
tar jxf ImageMagick-6.5.1-0.tar.bz2
cd ImageMagick-6.5.1-0
./configure
make
make install
[ $? -ne 0 ] && {
action "install ImageMagick failed!" /bin/false
exit $?
}
cd ../
sleep 2
#install imagick php
wget http://pecl.php.net/get/imagick-2.3.0.tgz
tar zxf imagick-2.3.0.tgz
cd imagick-2.3.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
[ $? -ne 0 ] && {
action "install imagick php failed!" /bin/false
exit $?
}
cd ../
sleep 2
cd /usr/local/php/lib/
cp php.ini php.ini_$(date +%F)
sed -i 's#; extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"#g' php.ini
cat >> /usr/local/php/lib/php.ini<<EOF
extension = memcache.so
extension = pdo_mysql.so
extension = imagick.so
EOF
#config eaccelerator
mkdir -p /tmp/eaccelerator
chown -R nginx.nginx /tmp/eaccelerator
cat >>/usr/local/php/lib/php.ini<<EOF
[eaccelerator]
extension = eaccelerator.so
eaccelerator.shm_size="64"
accelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
EOF
sleep 1
echo "====================================="
/usr/local/php/bin/php -v
[ $? -eq 0 ] && action "Config php cache module sucessful" /bin/true
echo "====================================="
}
#menu
while true
do
clear
echo "========================================"
echo 'LNMP version 1.0 for CentOS6.X(x86_64) '
echo "========================================"
echo "+------install software version--------+"
echo "+ nginx-1.4.7 +"
echo "+ mysql-5.5.38 +"
echo "+ php-5.3.27 +"
echo "+--------------------------------------+"
cat << EOF
----------------------------------------
|****Please Enter Your Choice:[1-4]****|
----------------------------------------
(1)minimal系统请先选择此项安装必要包组
(2)一键源码安装{nginx|mysql|php}
(3)安装php缓存加速模块{eaccelerator|memcache|PDO_MYSQL|imagick}
(4)退出
EOF
#choice
read -p "Please enter your choice[1-4]: " input1
case "$input1" in
1)
initTools
;;
2)
initNginx
initMysql
initPhp
;;
3)
initPhpCacheModule
;;
4)
clear
break
;;
*)
echo "----------------------------------"
echo "| Warning!!! |"
echo "| Please Enter Right Choice! |"
echo "----------------------------------"
for i in `seq -w 3 -1 1`
do
echo -ne "\b\b$i";
sleep 1;
done
clear
esac
done
|
|
|
|
|
|
|