您的位置:首页 > 运维架构 > Linux

centos7 lnmp 一键安装脚本

2015-07-10 20:18 525 查看
参考:http://bbotte.blog.51cto.com/6205307/1637499 ,并做了些小改动

#!/bin/bash
#
# Centos 7.1 mini安装
# root 运行此脚本
# ./lnmp.sh
#
# 软件版本如下:
# APC-3.1.13.tgz
# eaccelerator-0.9.6.1.tar.bz2
# gnosek-nginx-upstream-fair-a18b409.tar.gz
# htop-1.0.3.tar.gz
# ImageMagick-6.9.1-7.tar.gz
# imagick-3.1.2.tgz
# jpegsrc.v9a.tar.gz
# libiconv-1.14.tar.gz
# libmcrypt-2.5.8.tar.gz
# libmemcached-1.0.2.tar.gz
# mcrypt-2.6.8.tar.gz
# memcache-2.2.7.tgz
# memcached-2.0.1.tgz
# mhash-0.9.9.9.tar.gz
# mysql-5.5.3-m3.tar.gz
# nagios-client.tar.gz
# nginx-1.4.4.tar.gz
# pcre-8.34.tar.gz
# PDO_MYSQL-1.0.2.tgz
# php-5.3.28.tar.bz2
# scws-1.2.2.tar.bz2
# scws-dict-chs-gbk.tar.bz2
# scws-dict-chs-utf8.tar.bz2
#
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
cur_dir=$(pwd)
install_dir=/usr/local/lnmp
gcc_version=`rpm -qa gcc | awk -F '[-]' '{print $2}'`

function InstallSystem()
{
chmod +x /etc/rc.d/rc.local
echo "设置系统参数"
#dns
grep -i 'gateway' -rl /etc/sysconfig/network-scripts/ |  grep ifcfg | awk -F '-' '{print $NF}' | xargs -i nmcli con mod {} ipv4.dns "114.114.114.114 8.8.8.8 8.8.4.4"
grep -i 'gateway' -rl /etc/sysconfig/network-scripts/ |  grep ifcfg | awk -F '-' '{print $NF}' | xargs -i nmcli con up {}
#更改为阿里云的源
yum install wget -y
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum clean all
yum makecache
#ulimit
if [ "`cat /etc/security/limits.conf | grep 'soft nproc 65535'`" = "" ]; then
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
fi
#安装必要工具
yum update -y
yum install -y vim wget bc ntpdate sysstat wget man mtr lsof iotop net-tools openssl-devel openssl-perl iostat subversion nscd
echo "关闭selinux"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
#设置ssh
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/GSSAPIAuthentication yes/GSSAPIAuthentication no/g" /etc/ssh/sshd_config
systemctl restart sshd.service
#设置时区
if [ "`cat /etc/crontab | grep ntpdate`" = "" ]; then
echo "0 23 * * * root /usr/sbin/ntpdate cn.pool.ntp.org >> /var/log/ntpdate.log" >> /etc/crontab
fi
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate cn.pool.ntp.org;hwclock -w
#关闭不必要的启动项
systemclt disable postfix.service
systemctl stop postfix.service

#设置sysctl
if [ ! -f '/etc/sysctl.d/addsys.conf' ];then
cat >>  /etc/sysctl.d/addsys.conf <<EOF
#Add
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog =  32768
net.core.somaxconn = 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

net.ipv4.tcp_fin_timeout = 120
net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024  65535

net.nf_conntrack_max = 16404388
net.netfilter.nf_conntrack_tcp_timeout_established = 10800

#kernel: TCP: time wait bucket table overflow
net.ipv4.tcp_max_tw_buckets = 30000

fs.file-max=655350
EOF
modprobe bridge
echo "modprobe bridge" >> /etc/rc.local
/sbin/sysctl -p
fi

if [ "`cat /etc/sysconfig/iptables | grep '192.168.1.0'`" = "" ]; then
echo "关闭系统默认的firewall,开启iptables"
systemctl stop firewalld
systemctl mask firewalld
yum install iptables-services -y
systemctl enable iptables
sed -i '/--dport 22 -j ACCEPT/a\-A INPUT -s 192.168.1.0/255.255.255.0 -p tcp -m tcp -j ACCEPT' /etc/sysconfig/iptables
sed -i '/--dport 22 -j ACCEPT/a\-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT' /etc/sysconfig/iptables
sed -i '/--dport 22 -j ACCEPT/a\-A INPUT -p tcp -m state --state NEW -m tcp --dport 12345 -j ACCEPT' /etc/sysconfig/iptables
systemctl start iptables
fi
}

function InstalltoolSys()
{
echo "安装系统工具"
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libX11-devel libXext-devel libXt-devel mysql-devel rsync libX11-devel pcre-devel libtool-libs libevent mlocate kernel-devel gd gettext-devel libc-client-devel libxslt libgomp libxslt-devel openldap-servers gmp-devel zip libstdc++-devel make libXext-devel perl openldap-clients keyutils-libs-devel php-common libcap php-gd icu unzip libevent-devel gd-devel nss_ldap libtool-ltdl-devel mysql-devel apr* libtool libcap-devel libsepol-devel libXpm* libcom_err-devel compat* libXt-devel expat-devel libicu-devel libicu automake pam-devel cmake

tar zxvf htop-1.0.3.tar.gz
cd htop-1.0.3
./configure
make && make install
cd ../

tar zxvf nagios-client.tar.gz
cd nagios-client
./install-nagios-client.sh
cd ../
}

function InstalltoolWeb()
{
echo "安装web及其他必要工具"
cd $cur_dir
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure
if [ $(echo "$gcc_version > 4.5"|bc)=1 ];then
cd srclib/
sed -i -e '/gets is a security/d' ./stdio.in.h
cd ../
fi
make
make install
cd ../

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../

tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../

tar -zxf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure  --prefix=/usr/local/libs --enable-shared --enable-static
make libdir=/usr/lib64
make libdir=/usr/lib64 install
cd ../

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure
make
make install
cd ../
}

function InstallMySQL()
{
cd $cur_dir
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.5.3-m3.tar.gz
cd mysql-5.5.3-m3/
./configure --prefix=$install_dir/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
if [ $(echo "$gcc_version > 4.5"|bc)=1 ];then
/usr/bin/sed -i '1146,1163d' Makefile
fi
make && make install
chmod +w $install_dir/mysql
chown -R mysql:mysql $install_dir/mysql
cd ../

mkdir $install_dir/mysql/include/mysql/psi/
cp $install_dir/mysql/include/mysql/psi.h $install_dir/mysql/include/mysql/psi/
ln -s $install_dir/mysql/include/* $install_dir/mysql/include/mysql
ln -s $install_dir/mysql/include/mysql/* /usr/local/include/

cp -frp /usr/lib64/libldap* /usr/lib/
ln -s /usr/lib64/liblber* /usr/lib/
ln -s $install_dir/mysql/libmysqlclient.so.18 /usr/lib64/
}

function InstallPhp()
{
cd $cur_dir
tar jxvf php-5.3.28.tar.bz2
cd php-5.3.28
./configure --prefix=$install_dir/php --with-config-file-path=$install_dir/php/etc --with-mysql=$install_dir/mysql --with-mysqli=$install_dir/mysql/bin/mysql_config --with-iconv-dir=/usr/local --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-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-bz2 --disable-fileinfo --enable-static
make ZEND_EXTRA_LIBS='-liconv' -j4
make install
cd ../

tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7/
$install_dir/php/bin/phpize
./configure --with-php-config=$install_dir/php/bin/php-config
make
make install
cd ../

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
$install_dir/php/bin/phpize
./configure --with-php-config=$install_dir/php/bin/php-config --with-pdo-mysql=$install_dir/mysql
make
make install
cd ../

tar zxvf ImageMagick-6.9.1-7.tar.gz
cd ImageMagick-6.9.1-7/
./configure
make
make install
cd ../

tar zxvf imagick-3.1.2.tgz
cd imagick-3.1.2
$install_dir/php/bin/phpize
./configure --with-php-config=$install_dir/php/bin/php-config --with-imagick=/usr/local/imagemagick
make -j4
make install
cd ../

tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
$install_dir/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=$install_dir/php/bin/php-config
make
make install
cd ../

tar zxvf libmemcached-1.0.2.tar.gz
cd libmemcached-1.0.2
./configure
make
make install
cd ../

tar zxvf memcached-2.0.1.tgz
cd memcached-2.0.1
$install_dir/php/bin/phpize
./configure --with-php-config=$install_dir/php/bin/php-config
make
make install
cd ../

tar xvjf scws-1.2.2.tar.bz2
cd scws-1.2.2
./configure --prefix=/usr/local/scws ; make ; make install
cd /usr/local/scws/etc
wget http://www.xunsearch.com/scws/down/scws-dict-chs-gbk.tar.bz2 wget http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2 tar xvjf scws-dict-chs-gbk.tar.bz2
tar xvjf scws-dict-chs-utf8.tar.bz2
cd $cur_dir/scws-1.2.2/phpext/
$install_dir/php/bin/phpize
./configure --with-scws=/usr/local/scws --with-php-config=$install_dir/php/bin/php-config
make
make install
$install_dir/php/sbin/php-fpm -m

cd ../../

tar zxvf APC-3.1.13.tgz
cd APC-3.1.13
$install_dir/php/bin/phpize
./configure --enable-apc --enable-mmap --enable-apc-spinlocks --disable-apc-pthreadmutex --with-php-config=$install_dir/php/bin/php-config
make
make install
cd ..

if [ "`cat /etc/rc.local | grep /php`" = "" ]; then
echo "$install_dir/php/sbin/php-fpm" >> /etc/rc.local
fi
}

function InstallNginx()
{
cd $cur_dir
/usr/sbin/groupadd myweb
/usr/sbin/useradd -g myweb myweb
/usr/sbin/groupadd wyweb
/usr/sbin/useradd -g wyweb wyweb

tar zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure
make && make install
cd ../

tar zxvf gnosek-nginx-upstream-fair-a18b409.tar.gz

tar zxvf nginx-1.4.4.tar.gz
cd nginx-1.4.4
./configure --user=wyweb --group=wyweb --prefix=$install_dir/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=$cur_dir/gnosek-nginx-upstream-fair-a18b409
make && make install
cd ../

ln -s /usr/local/lib/libpcre.so.1 /lib64/

if [ "`cat /etc/rc.local | grep /nginx`" = "" ]; then
echo "$install_dir/nginx/sbin/nginx" >> /etc/rc.local
fi

}

InstallSystem 2>&1 |tee /root/lnmp-install-system.log
InstalltoolSys 2>&1 |tee /root/lnmp-install-toolsys.log
InstalltoolWeb 2>&1 |tee /root/lnmp-install-toolweb.log
InstallMySQL 2>&1 |tee /root/lnmp-install-mysql.log
InstallPhp 2>&1 |tee /root/lnmp-install-php.log
InstallNginx 2>&1 |tee /root/lnmp-install-nginx.log
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  centos lnmp 一键安装