系统CentOS7.1链接 http://mirrors.sohu.com/centos/7.1.1503/isos/x86_64/CentOS-7-x86_64-Minimal-1503-01.iso   md5值:

d07ab3e615c66a8b2e9a50f4852e6a77  CentOS-7-x86_64-Minimal-1503-01.iso

系统为最小化安装,版本号:

nginx:1.6.3

mysql:5.5.37

php:5.3.28

下面shell,没有多的版本判断设置,可以完成基本的LNMP环境搭建,请做为参考使用

#!/bin/bash
#CentOS7.1最小化安装 mysql5.5.37 nginx1.6.3 php5.3.28
#root运行此脚本
# ./lnmp.sh
# 安装完成后访问http://IP查看
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
cur_dir=$(pwd)
MYSQLDATADIR=/var/mysql/data
MYSQLLOGDIR=/var/log/mysql

function InstallSystem()
{
cat  >> /etc/security/limits.conf << EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
echo "ulimit -SHn 65535" >> /etc/profile
echo "ulimit -SHn 65535" >> /etc/rc.local
yum install vim vim-enhanced wget lrzsz bc mutt ntpdate sysstat dstat wget man mail mlocate mtr lsof iotop iptraf net-tools -y
updatedb
echo "syntax on" >> /root/.vimrc
echo "set nohlsearch" >> /root/.vimrc
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
sed -i "s/\#Port 22/Port 12345/g" /etc/ssh/sshd_config 
sed -i "s/\#UseDNS yes/UseDNS no/g" /etc/ssh/sshd_config
#sed -i "s/\#PermitRootLogin yes/\PermitRootLogin no/g" /etc/ssh/sshd_config 
#sed -i "s/PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
systemctl restart sshd.service
echo "####iptables"
echo "关闭系统默认的firewall,开启iptables"
systemctl stop firewalld.service
systemctl disable firewalld.service
yum install iptables-services -y
mv /etc/sysconfig/iptables /etc/sysconfig/iptables.def
cp iptables /etc/sysconfig/
systemctl restart iptables.service
systemctl enable iptables.service
echo "*/30 * * * * /usr/sbin/ntpdate 132.163.4.101 >/dev/null 2>&1 " >> /var/spool/cron/root
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate 0.asia.pool.ntp.org ;hwclock -w
#系统参数自己调,下面只供参考
cat >>  /etc/sysctl.d/addsys.conf <> /etc/rc.local
/sbin/sysctl -p
echo "####yum install"
echo "please waiting"
yum install -y gcc gcc-c++ patch make flex bison file libtool libtool-libs 
autoconf libjpeg-devel libpng libpng-devel gd gd-devel freetype-devel 
libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 
bzip2-devel libevent libevent-devel ncurses ncurses-devel curl 
curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel 
gettext-devel gmp-devel unzip libcap apr* automake openssl openssl-devel
 perl compat* mpfr cpp glibc glibc-devel libgomp libstdc++-devel 
keyutils keyutils-libs-devel libcom_err-devel libsepol-devel krb5-devel 
libXpm* php-common php-gd pcre-devel openldap crontabs diffutils elinks 
 expat-devel    icu kernel-devel libaio   libxslt libxslt-devel  
libcap-devel libtool-ltdl-devel libc-client-devel libicu libicu-devel 
lynx zip mlocate readline readline-devel  sendmail pam-devel openldap-devel perl-DBD-MySQL
 
echo "####ifstat"
tar -xzf ifstat-1.1.tar.gz 
cd ifstat-1.1
./configure
make
make install
cd ..
echo "####iftop"
yum install ncurses ncurses-devel libpcap libpcap-devel -y
tar -xzf iftop-0.17.tar.gz 
cd iftop-0.17
./configure
make
make install
cd ..
echo "####htop"
tar -xzf htop-1.0.tar.gz 
cd htop-1.0
./configure
make
make install
cd ..
echo "export PATH=$PATH:/usr/local/bin" >> /etc/profile.d/stat.sh
. /etc/profile.d/stat.sh
}

function InstallMySQL()
{
#安装mysql
echo "####cmake"
yum install -y gcc gcc-c++
tar -zxf cmake-2.8.7.tar.gz
cd cmake-2.8.7
./configure
make -j4 && make install
cd ..
echo "####install mysql"
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
mkdir -p $MYSQLDATADIR
mkdir -p $MYSQLLOGDIR
chown -R mysql.mysql $MYSQLDATADIR
chown -R mysql.mysql $MYSQLLOGDIR
tar zxf mysql-5.5.37.tar.gz
cd mysql-5.5.37
cmake -DCMAKE_BUILD_TYPE:STRING=Release 
-DMYSQL_USER=mysql-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_DATADIR=$MYSQLDATADIR -DSYSCONFDIR=/etc 
-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 
-DWITH_PARTITION_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 -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci
make -j4
make install
echo "####config mysql"
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cd ..
mv /etc/my.cnf /etc/my.cnf.bak
sed -i -e "/#insert mysql datadir/a\datadir = ${MYSQLDATADIR}\ninnodb_data_home_dir \
= ${MYSQLDATADIR}\ninnodb_log_group_home_dir = ${MYSQLLOGDIR}\nlog-error \
= ${MYSQLLOGDIR}/mysql-error.log\npid-file = ${MYSQLLOGDIR}/mysql.pid\nlog-bin \
= ${MYSQLLOGDIR}/mysql-bin\nslow_query_log_file = ${MYSQLLOGDIR}/mysql_slow.log\n"  my.cnf
cp my.cnf /etc/
/usr/local/mysql/scripts/mysql_install_db --user=mysql  --datadir=$MYSQLDATADIR \
--basedir=/usr/local/mysql --log-output=file
echo `ps aux|grep mysql`
sleep 3
yum install mysql -y
systemctl start mysqld.service
cat > /tmp/mysql_sec_script.sql< /etc/ld.so.conf.d/local.conf <>/usr/local/php/etc/php.ini<>/usr/local/php/etc/php.ini</var/www/www.test.com/index.php<< EOF

EOF
mv /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf.bak
mkdir /var/log/php
cp php-fpm.conf /usr/local/php/etc/
echo "export PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile.d/nginx.sh
. /etc/profile.d/nginx.sh
}

function Installredis()
{
echo "####redis"
tar zxf redis-2.8.9.tar.gz
cd redis-2.8.9
make -j4
make install
cp redis.conf /etc/redis.conf.def
cd ..
mkdir /var/redis/
cp redis.conf /etc/
echo "/usr/local/bin/redis-server /etc/redis.conf" >> /etc/rc.local
/usr/local/bin/redis-server /etc/redis.conf &

cp redis.sh /etc/init.d/redis
chmod +x /etc/init.d/redis
systemctl restart redis.service
}

function CheckService()
{
echo "####service"
systemctl start nginx.service
systemctl start php-fpm.service
systemctl restart mysqld.service

cat >/etc/resolv.conf <&1 |tee /root/lnmp-install.log
InstallMySQL 2>&1 |tee -a /root/lnmp-install.log
InstallPhp   2>&1 |tee -a /root/lnmp-install.log
InstallNginx  2>&1 |tee -a /root/lnmp-install.log
Installredis  2>&1 |tee -a /root/lnmp-install.log
CheckService  2>&1 |tee -a /root/lnmp-install.log

date
df -h
netstat -tnlp


readme.txt
服务启动及关闭
systemctl start nginx.service
systemctl start php-fpm.service
systemctl start mysqld.service
systemctl start redis.service
systemctl start iptables.service

配置路径
nginx: /usr/local/nginx/conf/nginx
       /usr/local/nginx/conf/server/
php: /usr/local/php/etc/php-fpm.conf
     /usr/local/php/etc/php.ini
mysql: /etc/my.cnf
redis: /etc/redis.conf

日志路径
nginx:/var/log/nginx
php: /var/log/php
mysql: /var/log/mysql
redis: /var/redis

数据库存放路径
/var/mysql/data


除了libiconv-1.14.tar.gz这个包7.1的系统安装会出错,其他的都可以从网上下载,附件里面的包已经包含补丁,可以直接用 http://down.51cto.com/data/2041549