Files
lemp/lemp.sh

178 lines
5.5 KiB
Bash
Raw Normal View History

2016-03-28 20:40:11 +08:00
#!/bin/bash
2016-09-19 13:12:04 +08:00
# Install script for LEMP Web Server base on CentOS 6/7 by xiaosong
2016-08-28 18:46:09 +08:00
cd `pwd`
2016-03-28 20:40:11 +08:00
# Checking
2016-03-29 20:51:44 +08:00
echo "Checking..."
2016-03-28 20:40:11 +08:00
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
2016-08-15 19:25:01 +08:00
if [ "$OS" != 'CentOS' ] || [ "$CentOS_RHEL_version" != '6' -a "$CentOS_RHEL_version" != '7' ];then
2016-03-28 20:40:11 +08:00
echo "${CFAILURE}Error: This script only support CentOS 6 & CentOS 7${CEND}";
2016-08-15 19:25:01 +08:00
kill -9 $$
2016-03-28 20:40:11 +08:00
fi
if [ `getconf WORD_BIT` == 32 ] && [ `getconf LONG_BIT` == 64 ];then
2016-08-15 19:25:01 +08:00
BIT=64
else
2016-03-28 20:40:11 +08:00
echo "${CFAILURE}Error: This script only support 64 bit CentOS${CEND}";
2016-08-15 19:25:01 +08:00
kill -9 $$
2016-03-28 20:40:11 +08:00
fi
2016-09-15 22:00:01 +08:00
# 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 <<EOF
# End of file
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
# Set timezone
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# /etc/sysctl.conf
sed -i 's/net.ipv4.tcp_syncookies.*$/net.ipv4.tcp_syncookies = 1/g' /etc/sysctl.conf
[ -z "`grep 'fs.file-max' /etc/sysctl.conf`" ] && cat >> /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 = 1
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.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
2016-03-28 20:40:11 +08:00
# Init
echo "Initializing..."
sudo yum -y update
2016-08-15 19:26:59 +08:00
sudo yum -y install vim wget epel-release unzip git
2016-03-28 20:40:11 +08:00
# Install the Required Repositories
echo "Installing the Required Repositories..."
2016-08-15 19:25:01 +08:00
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-${CentOS_RHEL_version}.rpm
2016-03-28 20:40:11 +08:00
echo "[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=0
2016-08-15 19:25:01 +08:00
enabled=1" > /etc/yum.repos.d/nginx.repo
2016-03-28 20:40:11 +08:00
echo "[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos\$releasever-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
2016-08-15 19:25:01 +08:00
gpgcheck=1" > /etc/yum.repos.d/mariadb.repo
2016-03-28 20:40:11 +08:00
# Install MariaDB
echo "Installing MariaDB..."
sudo yum install -y MariaDB-server MariaDB-client
# Install Nginx
echo "Installing Nginx..."
sudo yum install -y nginx
# Install PHP
echo "Installing PHP..."
2016-09-02 10:19:11 +08:00
sudo yum install -y --enablerepo=remi,remi-php70 php-gd php-fpm php-cli php-pdo php-xml php-json php-soap php-common php-mcrypt php-mysqlnd php-mbstring php-pecl-zip php-opcache php-xmlrpc
2016-03-28 20:40:11 +08:00
# Install Composer
echo "Installing Composer globally..."
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
# Configure Nginx for PHP
echo "Configuring Nginx for PHP..."
2016-09-16 09:51:49 +08:00
IP=`curl ip.llm.me`
2016-08-28 18:46:09 +08:00
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
2016-08-28 18:49:27 +08:00
sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
2016-09-20 21:43:25 +08:00
sudo cp ./conf/nginx.conf /etc/nginx/nginx.conf
sudo cp ./conf/default.conf /etc/nginx/conf.d/default.conf
2016-09-16 09:51:49 +08:00
sudo sed -i "s/localhost/$IP/g" /etc/nginx/conf.d/default.conf
2016-03-28 20:40:11 +08:00
# Configure PHP
echo "Configuring PHP..."
sudo chown root:nginx /var/lib/php -R
2016-09-02 10:55:39 +08:00
sudo sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo = 0/g' /etc/php.ini
2016-03-28 20:40:11 +08:00
sudo sed -i 's/pdo_mysql.default_socket=/pdo_mysql.default_socket = \/var\/lib\/mysql\/mysql.sock/g' /etc/php.ini
sudo sed -i 's/mysqli.default_socket =/mysqli.default_socket = \/var\/lib\/mysql\/mysql.sock/g' /etc/php.ini
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 20M/g' /etc/php.ini
sudo sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /etc/php.ini
2016-09-16 08:34:45 +08:00
sudo sed -i 's/;date.timezone =/date.timezone = "Asia\/Shanghai"/g' /etc/php.ini
2016-03-28 20:40:11 +08:00
sudo sed -i 's/user = apache/user = nginx/g' /etc/php-fpm.d/www.conf
sudo sed -i 's/group = apache/group = nginx/g' /etc/php-fpm.d/www.conf
2016-09-16 09:51:49 +08:00
# Write PHP test file
echo "Write PHP test file..."
cat >> /usr/share/nginx/html/i.php <<EOF
<?php
phpinfo();
EOF
2016-08-28 18:46:09 +08:00
# Configure MariaDB
echo "Configuring MariaDB..."
2016-09-20 21:43:25 +08:00
sudo cp ./conf/my.cnf /etc/my.cnf
sudo cp ./conf/server.cnf /etc/my.cnf.d/server.cnf
2016-08-28 18:46:09 +08:00
2016-03-28 20:40:11 +08:00
# Restarting Services
echo "Restarting Services..."
2016-09-02 10:19:11 +08:00
if [ "$CentOS_RHEL_version" == 6 ];then
sudo service mysql restart
sudo service php-fpm restart
sudo service nginx restart
else
sudo systemctl restart mariadb.service
sudo systemctl restart nginx.service
sudo systemctl restart php-fpm.service
fi
2016-03-28 20:40:11 +08:00
# Set Up Autostart
echo "Setting Autostart..."
2016-08-15 19:25:01 +08:00
if [ "$CentOS_RHEL_version" == 6 ];then
2016-03-28 20:40:11 +08:00
sudo chkconfig --levels 235 mysql on
sudo chkconfig --levels 235 nginx on
sudo chkconfig --levels 235 php-fpm on
else
2016-09-02 10:19:11 +08:00
sudo systemctl enable mariadb.service
sudo systemctl enable nginx.service
sudo systemctl enable php-fpm.service
2016-03-28 20:40:11 +08:00
fi
# Done
echo "Configuring MariaDB..."
2016-09-02 10:19:11 +08:00
sudo mysql_secure_installation
2016-03-28 20:40:11 +08:00