脚本一键安装lnmp (centos6版本)
#!/bin/bash
echo "It will install lnmp."
sleep 1
##check last command is OK or not.
check_ok() {
if [ $? != 0 ]
then
echo "Error, Check the error log."
exit 1
fi
}
##get the archive of the system,i686 orx86_64.
ar=`arch`
##close seliux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
selinux_s=`getenforce`
if [ $selinux_s =="Enforcing" -o $selinux_s =="enforcing" ]
then
setenforce 0
fi
##close iptables
iptables -save >/etc/sysconfig/iptables_`date +%s`
iptables -F
service iptables save
##if the packge installed ,then omit.
myum() {
if ! rpm -qa|grep -q "^$1"
then
yum install -y $1
check_ok
else
echo $1 already installed.
fi
}
myum
##install some packges.
for p in gcc gcc-c++ wget perl perl-devel libaio libaio-devel pcre-devel zlib-devel openssl openssl-devel ncurses ncurses-devel libxml2 libxml2-devel bzip2 bzip2-devel libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel libtool-ltdl-devel
do
myum $p
done
##install epel.
if ! rpm -qa epel-release >/dev/null
then
yum install -y epel-release
check_ok
fi
if ls /etc/yum.repos.d/epel-6.repo*> /dev/null 2>&1
then
rm -f /etc/yum.repos.d/epel-6.repo*
fi
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo
##function of install mysqld
install_mysqld() {
echo "Install mysql version5.1.72"
cd /usr/local/src
[ -f mysql-5.1.72.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72.tar.gz
check_ok
[ -d mysql-5.1.72 ] || tar -zvxf mysql-5.1.72.tar.gz
[ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_`date +%s`
cd mysql-5.1.72
sed -i 's/$RM "$cfgfile"/#$RM "$cfgfile"/' configure
./configure --prefix=/usr/local/mysql --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-static'CFLAGS=-g -O3' 'CXXFLAGS=-g -O3' --with-extra-charsets=gbk,utf8,ascii,big5,latin1,binary --enable-assembler --enable-local-infile --enable-profiling --enable-thread-safe-client
check_ok
make && make install
check_ok
}
install_mysqld
##function of check service is running ornot, example nginx, php-fpm.
check_service() {
if [ "$1" == "phpfpm" ]
then
s="php-fpm"
else
s=$1
fi
n=`ps aux | grep "$s" |wc -l`
if [ $n -gt 1 ]
then
echo "$1 service is already started."
else
if [ -f /etc/init.d/$1 ]
then
/etc/init.d/$1 start
check_ok
else
install_$1
fi
fi
}
check_service
##function ofinstall nginx.
install_nginx(){
echo"Install nginx version 2.2."
cd /usr/local/src
[ -f nginx-1.8.0.tar.gz ] || wget http://nginx.org/download/nginx-1.8.0.tar.gz
[ -d nginx-1.8.0 ] || tar zxf nginx-1.8.0.tar.gz
[ -d /usr/local/nginx ] && /bin/mv /usr/local/nginx /usr/local/nginx_`date +%s`
cd nginx-1.8.0
myum pcre-devel
./configure --prefix=/usr/local/nginx
check_ok
make && make install
check_ok
}
install_nginx
if [ -f /etc/init.d/nginx ]
then
/bin/mv /etc/init.d/nginx /etc/init.d/nginx_`date +%s`
fi
curl http://www.apelearn.com/study_v2/.nginx_init -o /etc/init.d/nginx
check_ok
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
curl http://www.apelearn.com/study_v2/.nginx_conf -o /usr/local/nginx/conf/nginx.conf
check_ok
service nginx restart
check_ok
echo -e"<?php\n phpinfo();\n?>" > /usr/local/nginx/html/index.php
check_ok
##function of install lnmp.
lnmp(){
check_service mysqld
check_service nginx
check_service phpfpm
echo "The lnmp done, Please use'http://your ip/index.php' to access."
}
lnmp