这是本人自己没事写的,有不到之处请包涵谅解,经测试在centos5.5-centos6.4是没有问题的,其他系统可以根据自己的需要稍作修改
直接将本lnmp.sh脚本和lnmp.tar.gz的源码包下载放到/root/下面,然后执行附加lnmp.sh给执行权限之后执行./lnmp.sh即可
编写安装脚本lnmp.sh
#!/bin/bash
#把所有源码包放在/root下面
#安装源码编译的开发环境
yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel libtermcap libtermcap-devel ncurses ncurses-devel libxml2 libxml2-devel -y
[ $? != 0 ] && exit
#安装组环境
yum groupinstall GNOME Software Development Development Tools Java Development KDE Software Development Legacy Software Developmen -y
[ $? != 0 ] && exit
#首先来安装mysql5.5.22,由于mysql5.5以后用的是cmake编译的,所以先安装cmake
#源码编译cmake
cd /root
tar zxvf lnmp.tar.gz
tar zxvf cmake-2.8.11.tar.gz
cd cmake-2.8.11
./configure
[ $? != 0 ] && exit
make && make install
[ $? != 0 ] && exit
echo -e "\033[0;31m cmake install ok \033[0m"
#安装mysql
#创建mysql的安装目录及数据库存放目录
mkdir -p /usr/local/mysql
mkdir -p /usr/local/mysql/data
#创建mysql用户及用户组
groupadd mysql
useradd -r -g mysql mysql
#开始安装
cd /root
tar zxvf mysql-5.5.22.tar.gz
cd mysql-5.5.22
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
[ $? != 0 ] && echo -e "\033[0;31m mysql Configure failure \033[0m" && exit
make && make install
[ $? != 0 ] && echo -e "\033[0;31m mysql Install failure \033[0m" && exit
cd /usr/local/mysql
chown -R root:mysql .
chown -R mysql:mysql data
cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[ $? != 0 ] && exit && echo -e "\033[0;31m mysql Initialization failure \033[0m"
#设置环境变量
sed -i s#`grep "HOME" /root/.bash_profile`#`grep "HOME" /root/.bash_profile |awk '{print$0":/usr/local/mysql/bin:/usr/local/mysql/lib"}'`#g /root/.bash_profile
source /root/.bash_profile
#设置mysql的管理脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld start
service mysqld restart
[ $? != 0 ] && exit
echo -e "\033[0;31m mysql is ok!!! \033[0m"
#让系统自动识别mysql
cd /etc/ld.so.conf.d/
touch mysql.conf
echo "/usr/local/mysql/lib"
ldconfig -v |grep mysql
cd /usr/include
ln -s /usr/local/mysql/include mysql
#让系统开机自动可以搜索到管理
chkconfig --add mysqld
#开始安装nginx
cd /root
tar zxvf nginx-1.1.18.tar.gz
cd nginx-1.1.18
./configure --prefix=/usr/local/nginx
[ $? != 0 ] && exit
make && make install
[ $? != 0 ] && exit
if [ ! -f /etc/init.d/nginx ]
then
cat >> /etc/init.d/nginx << "EOF"
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
start()
{
NAME=`netstat -tupln |grep "nginx" |awk -F / '{print $2}'`
if [ -z $NAME ]
then
/usr/local/nginx/sbin/nginx
sleep 2
NAME=`netstat -tupln |grep "nginx" |awk -F / '{print $2}'`
if [ -z $NAME ]
then
echo -e "Start nginx \033[31m[ Failed ]\033[30m"
else
echo -e "Start nginx \033[32m[ Ok ]\033[30m"
fi
else
echo "nginx is running"
fi
}
stop()
{
pkill nginx
sleep 2
NAME=`netstat -tupln |grep "nginx" |awk -F / '{print $2}'`
if [ -z $NAME ]
then
echo -e "Stop nginx \033[32m[ Ok ]\033[30m"
else
echo -e "Stop nginx \033[31m[ Failed ]\033[30m"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "usage: $0 start|stop|restart"
esac
EOF
fi
chmod a+x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
service nginx start
service nginx stop
service nginx restart
netstat -tupln |grep 80
echo -e "\033[0;31m nginx is ok!!! \033[0m"
echo "service nginx start" >>/etc/rc.local
#接下来安装php
cd /root
tar zxvf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
[ $? != 0 ] && exit
cd php-5.2.17
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --enable-fastcgi --enable-fpm
[ $? != 0 ] && exit
make && make install
[ $? != 0 ] && exit
echo -e "\033[0;31m php is ok!!! \033[0m"
cp php.ini-dist /usr/local/php/lib/php.ini
sed -i '63s/^.*$/
[ $? != 0 ] && exit
sed -i '66s/^.*$/
[ $? != 0 ] && exit
/usr/local/php/sbin/php-fpm start
echo "usr/local/php/sbin/php-fpm start" >>/etc/rc.local
echo -e "\033[0;31m php-fpm is ok!!! \033[0m"
#设置php的环境变量
sed -i '10s/$/&:\/usr\/local\/php\/bin/g' /root/.bash_profile
source /root/.bash_profile
#整和nginx和php
sed -i 65,71s/#// /usr/local/nginx/conf/nginx.conf
[ $? != 0 ] && exit
sed -i 69s#scripts#usr/local/nginx/html# /usr/local/nginx/conf/nginx.conf
[ $? != 0 ] && exit
pkill -9 nginx
pkill -9 php-cgi
/usr/local/nginx/sbin/nginx
[ $? != 0 ] && exit
/usr/local/php/sbin/php-fpm start
[ $? != 0 ] && exit
yum install vsftpd -y
[ $? != 0 ] && exit
service vsftpd start
[ $? != 0 ] && exit
chkconfig --add vsftpd
chkconfig vsftpd on
echo -e "\033[0;31m mysql nginx php ftp is ok!!! \033[0m"
cd /root
rm -rf cmake-2.8.11 cmake-2.8.11.tar.gz mysql-5.5.22 mysql-5.5.22.tar.gz nginx-1.1.18 nginx-1.1.18.tar.gz pcre-8.12.tar.gz php-5.2.17 php-5.2.17-fpm-0.5.14.diff.gz php-5.2.17.tar.gz lnmp.tar.gz
上面已经把mysql、nginx、ftp加入系统服务并编写好service管理控制监本,直接使用service管理即可,php也已经加入随机启动!
源码包下载地址:http://down.51cto.com/data/942396