diff --git a/lemp.sh b/lemp.sh index 1b10b15..f94ed03 100755 --- a/lemp.sh +++ b/lemp.sh @@ -2,25 +2,6 @@ # Install script for LEMP Web Server base on CentOS 6/7 by xiaosong cd `pwd` -# Checking -echo "Checking..." -if [ -n "`grep 'Aliyun Linux release' /etc/issue`" -o -e /etc/redhat-release ];then - OS=CentOS - [ -n "`grep ' 7\.' /etc/redhat-release`" ] && CentOS_RHEL_version=7 - [ -n "`grep ' 6\.' /etc/redhat-release`" -o -n "`grep 'Aliyun Linux release6 15' /etc/issue`" ] && CentOS_RHEL_version=6 -fi - -if [ "$OS" != 'CentOS' ] || [ "$CentOS_RHEL_version" != '6' -a "$CentOS_RHEL_version" != '7' ];then - echo "${CFAILURE}Error: This script only support CentOS 6 & CentOS 7${CEND}"; - kill -9 $$ -fi - -if [ `getconf WORD_BIT` == 32 ] && [ `getconf LONG_BIT` == 64 ];then - BIT=64 -else - echo "${CFAILURE}Error: This script only support 64 bit CentOS${CEND}"; - kill -9 $$ -fi while :; do echo read -p "Please type MariaDB root password:(Default lemp.sh press Enter) " MariaDB_ROOT_PWD @@ -29,61 +10,10 @@ while :; do echo break; done -# Close SELINUX -setenforce 0 -sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config +. ./utils/init.sh -# /etc/security/limits.conf -[ -e /etc/security/limits.d/*nproc.conf ] && rename nproc.conf nproc.conf_bk /etc/security/limits.d/*nproc.conf -sed -i '/^# End of file/,$d' /etc/security/limits.conf -cat >> /etc/security/limits.conf <> /etc/sysctl.conf << EOF -fs.file-max = 65535 -net.ipv4.tcp_fin_timeout = 30 -net.ipv4.tcp_tw_reuse = 1 -net.ipv4.tcp_tw_recycle = 0 -net.ipv4.ip_local_port_range = 1024 65000 -net.ipv4.tcp_max_syn_backlog = 65536 -net.ipv4.tcp_max_tw_buckets = 20000 -net.ipv4.route.gc_timeout = 100 -net.ipv4.tcp_syn_retries = 1 -net.ipv4.tcp_synack_retries = 1 -net.ipv4.tcp_syncookies = 1 -net.core.somaxconn = 65535 -net.core.netdev_max_backlog = 262144 -net.ipv4.tcp_timestamps = 0 -net.ipv4.tcp_max_orphans = 262144 - -net.core.rmem_max = 67108864 -net.core.wmem_max = 67108864 -net.core.rmem_default = 65536 -net.core.wmem_default = 65536 -net.ipv4.tcp_rmem = 4096 87380 67108864 -net.ipv4.tcp_wmem = 4096 65536 67108864 -net.ipv4.tcp_mtu_probing = 1 -#net.ipv4.tcp_congestion_control = hybla -#net.ipv4.tcp_fastopen = 3 -net.nf_conntrack_max = 6553500 -net.netfilter.nf_conntrack_max = 6553500 -net.netfilter.nf_conntrack_tcp_timeout_established = 180 -EOF -sysctl -p /etc/sysctl.conf - -# Init -echo "Initializing..." +# Install base packages +echo "Installing base packages..." sudo yum -y update sudo yum -y install vim wget epel-release unzip git @@ -107,7 +37,7 @@ sudo yum install -y nginx # Install PHP echo "Installing PHP..." -sudo yum install -y --enablerepo=remi,remi-php71 php-gd php-fpm php-cli php-pdo php-xml php-json php-common php-mcrypt php-mysqlnd php-mbstring php-pecl-zip php-opcache php-xmlrpc +sudo yum install -y --enablerepo=remi,remi-php71 php-gd php-fpm php-cli php-pdo php-xml php-json php-common php-mcrypt php-mysqlnd php-mbstring php-zip php-opcache php-xmlrpc # Install Composer echo "Installing Composer globally..." @@ -205,4 +135,3 @@ y y y EOF - diff --git a/utils/bbr.sh b/utils/bbr.sh new file mode 100644 index 0000000..0622553 --- /dev/null +++ b/utils/bbr.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# Install script for BBR base on CentOS 7 by xiaosong +CentOS_Version=`cat /etc/redhat-release | grep -oE '[0-9]+\.[0-9]+' | cut -d'.' -f1` +KVersion=4.12.9-1 + +if [ -z ${CentOS_Version} ] +then + CentOS_Version=0 +fi + +if [ ${CentOS_Version} -lt 6 ] +then + echo "Sorry, I can only support CentOS 6/7 yet." + exit +fi + +if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; then + BIT_VER=x64 +else + BIT_VER=x86 +fi + +if [ ${BIT_VER} != 'x64' ] +then + echo "Sorry, I can only support x64 yet." + exit +fi + +function modifySysctl() { + if [ ! `cat /etc/sysctl.conf | grep -i -E "net.core.default_qdisc = fq"` ]; then + echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf + fi + if [ ! `cat /etc/sysctl.conf | grep -i -E "net.ipv4.tcp_congestion_control = bbr"` ]; then + echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf + fi +} + +echo "Now I will replace the system kernel to ${KVersion}..." +echo "Start installing" +rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org +if [ ${CentOS_Version} -eq 7 ] +then + rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm +else + rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm +fi +yum --enablerepo=elrepo-kernel install -y kernel-ml +echo "Checking if the installtion is ok" +KGRUB2=`ls /etc/grub2.cfg|wc -l` +if [ ${KGRUB2} -eq 1 ] +then + INS_OK=`awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg | grep ${KVersion} | grep -i -v debug | grep -i -v rescue | cut -d' ' -f1` + if [ -z ${INS_OK} ] + then + echo "Sorry, install failed, please contact the author" + exit + fi + yum install -y grub2-tools + grub2-set-default ${INS_OK} + modifySysctl +else + KGRUB=`ls /boot/grub/grub.conf|wc -l` + if [ ${KGRUB} -eq 1 ] + then + INS_OK=`grep '^title ' /boot/grub/grub.conf | awk -F'title ' '{print i++ " : " $2}' | grep ${KVersion} | grep -i -v debug | grep -i -v rescue | cut -d' ' -f1` + if [ -z ${INS_OK} ] + then + echo "Sorry, install failed, please contact the author" + exit + fi + sed -i "s/^default.*/default=${INS_OK}/" /boot/grub/grub.conf + modifySysctl + fi +fi + +echo " " +echo "Installation is completed, now you can reboot the system. " +echo "You should check BBR after the rebooting using command: " +echo " " +echo " sysctl -a|grep congestion_control" + + diff --git a/utils/init.sh b/utils/init.sh new file mode 100644 index 0000000..6a8ccb6 --- /dev/null +++ b/utils/init.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Checking +echo "Checking..." +if [ -n "`grep 'Aliyun Linux release' /etc/issue`" -o -e /etc/redhat-release ];then + OS=CentOS + [ -n "`grep ' 7\.' /etc/redhat-release`" ] && CentOS_RHEL_version=7 +fi + +if [ "$OS" != 'CentOS' ] || [ "$CentOS_RHEL_version" != '7' ];then + echo "${CFAILURE}Error: This script only support CentOS 7${CEND}"; + kill -9 $$ +fi + +# Close SELINUX +setenforce 0 +sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config + +# /etc/security/limits.conf +[ -e /etc/security/limits.d/*nproc.conf ] && rename nproc.conf nproc.conf_bk /etc/security/limits.d/*nproc.conf +sed -i '/^# End of file/,$d' /etc/security/limits.conf +cat >> /etc/security/limits.conf <> /etc/sysctl.conf << EOF +fs.file-max = 65535 +net.ipv4.tcp_fin_timeout = 30 +net.ipv4.tcp_tw_reuse = 1 +net.ipv4.tcp_tw_recycle = 0 +net.ipv4.ip_local_port_range = 1024 65000 +net.ipv4.tcp_max_syn_backlog = 65536 +net.ipv4.tcp_max_tw_buckets = 20000 +net.ipv4.route.gc_timeout = 100 +net.ipv4.tcp_syn_retries = 1 +net.ipv4.tcp_synack_retries = 1 +net.ipv4.tcp_syncookies = 1 +net.core.somaxconn = 65535 +net.core.netdev_max_backlog = 262144 +net.ipv4.tcp_timestamps = 0 +net.ipv4.tcp_max_orphans = 262144 + +net.core.rmem_max = 67108864 +net.core.wmem_max = 67108864 +net.core.rmem_default = 65536 +net.core.wmem_default = 65536 +net.ipv4.tcp_rmem = 4096 87380 67108864 +net.ipv4.tcp_wmem = 4096 65536 67108864 +net.ipv4.tcp_mtu_probing = 1 +#net.ipv4.tcp_congestion_control = hybla +net.ipv4.tcp_fastopen = 3 +net.nf_conntrack_max = 6553500 +net.netfilter.nf_conntrack_max = 6553500 +net.netfilter.nf_conntrack_tcp_timeout_established = 180 +EOF +sysctl -p /etc/sysctl.conf