分成更小的单元

This commit is contained in:
2017-08-26 12:52:13 +08:00
parent ac3c64fc23
commit f1d5ea4c49
2 changed files with 61 additions and 119 deletions

169
lemp.sh
View File

@@ -1,137 +1,68 @@
#!/bin/bash
# Install script for LEMP Web Server base on CentOS 6/7 by xiaosong
cd `pwd`
# Install script for LEMP Web Server base on CentOS 7 by xiaosong
SCRIPT_ROOT=`pwd`
cd `${SCRIPT_ROOT}`
while :; do echo
read -p "Please type MariaDB root password:(Default lemp.sh press Enter) " MariaDB_ROOT_PWD
[ -z "$MariaDB_ROOT_PWD" ] && MariaDB_ROOT_PWD="lemp.sh"
[ -n "`echo $MariaDB_ROOT_PWD | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and & ${CEND}"; continue; }
break;
read -p "Do you want to init your CentOS? [y/n]: " init_yn
if [[ ! $init_yn =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
break
fi
done
while :; do echo
read -p "Do you want to install nginx? [y/n]: " nginx_yn
if [[ ! $nginx_yn =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
break
fi
done
while :; do echo
read -p "Do you want to install PHP? [y/n]: " php_yn
if [[ ! $php_yn =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
break
fi
done
while :; do echo
read -p "Do you want to install MariaDB? [y/n]: " mariadb_yn
if [[ ! $mariadb_yn =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
while :; do echo
read -p "Please type MariaDB root password:(Default lemp.sh press Enter) " MariaDB_ROOT_PWD
[ -z "$MariaDB_ROOT_PWD" ] && MariaDB_ROOT_PWD="lemp.sh"
[ -n "`echo $MariaDB_ROOT_PWD | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and & ${CEND}"; continue; }
break;
done
fi
done
if [ "$init_yn" == 'y' ]; then
. ./utils/init.sh
fi
# Install base packages
echo "Installing base packages..."
sudo yum -y update
sudo yum -y install vim wget epel-release unzip git
# Install the Required Repositories
echo "Installing the Required Repositories..."
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-${CentOS_RHEL_version}.rpm
echo "[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=0
enabled=1" > /etc/yum.repos.d/nginx.repo
# Install MariaDB
echo "Installing MariaDB..."
sudo yum install -y mariadb-server
# Install Nginx
echo "Installing Nginx..."
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-zip php-opcache php-xmlrpc
# 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..."
IP=`curl -4 ip.llm.me`
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
sudo cp ./conf/nginx.conf /etc/nginx/nginx.conf
sudo cp ./conf/default.conf /etc/nginx/conf.d/default.conf
sudo sed -i "s/localhost/$IP `hostname`/g" /etc/nginx/conf.d/default.conf
# Configure PHP
echo "Configuring PHP..."
sudo chown root:nginx /var/lib/php -R
sudo sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo = 0/g' /etc/php.ini
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
sudo sed -i 's/;date.timezone =/date.timezone = "Asia\/Shanghai"/g' /etc/php.ini
sudo sed -i 's/expose_php = On/expose_php = Off/g' /etc/php.ini
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
sudo sed -i 's/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm.sock/g' /etc/php-fpm.d/www.conf
sudo sed -i 's/;listen.owner = nobody/listen.owner = nginx/g' /etc/php-fpm.d/www.conf
sudo sed -i 's/;listen.group = nobody/listen.group = nginx/g' /etc/php-fpm.d/www.conf
sudo sed -i 's/;listen.mode = 0660/listen.mode = 0660/g' /etc/php-fpm.d/www.conf
# Write PHP test file
echo "Write PHP test file..."
cat >> /usr/share/nginx/html/i.php <<EOF
<?php
phpinfo();
EOF
# Configure MariaDB
echo "Configuring MariaDB..."
sudo cp ./conf/my.cnf /etc/my.cnf
sudo cp ./conf/server.cnf /etc/my.cnf.d/server.cnf
echo "Configuring Firewall..."
if [ "$CentOS_RHEL_version" == 7 ];then
sudo systemctl stop firewalld
sudo systemctl mask firewalld
sudo yum install iptables iptables-services -y
if [ "$nginx_yn" == 'y' ]; then
. ./utils/nginx.sh
fi
sudo /sbin/iptables -I INPUT -p tcp --dport 443 -j ACCEPT
sudo /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sudo /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
sudo /sbin/service iptables save
# Restarting Services
echo "Restarting Services..."
if [ "$CentOS_RHEL_version" == 6 ];then
sudo service iptables restart
sudo service mysql restart
sudo service php-fpm restart
sudo service nginx restart
else
sudo systemctl start iptables
sudo systemctl restart mariadb.service
sudo systemctl restart nginx.service
sudo systemctl restart php-fpm.service
if [ "$php_yn" == 'y' ]; then
. ./utils/php.sh
fi
# Set Up Autostart
echo "Setting Autostart..."
if [ "$CentOS_RHEL_version" == 6 ];then
sudo chkconfig --levels 235 iptables on
sudo chkconfig --levels 235 mysql on
sudo chkconfig --levels 235 nginx on
sudo chkconfig --levels 235 php-fpm on
else
sudo systemctl enable iptables.service
sudo systemctl enable mariadb.service
sudo systemctl enable nginx.service
sudo systemctl enable php-fpm.service
if [ "$mariadb_yn" == 'y' ]; then
. ./utils/mariadb.sh
fi
# Done
echo "Configuring MariaDB..."
sudo mysql_secure_installation <<EOF
y
${MariaDB_ROOT_PWD}
${MariaDB_ROOT_PWD}
y
y
y
y
EOF

View File

@@ -61,3 +61,14 @@ net.ipv4.tcp_mtu_probing = 1
net.ipv4.tcp_fastopen = 3
EOF
sysctl -p /etc/sysctl.conf
echo "Configuring Firewall..."
sudo systemctl stop firewalld
sudo systemctl mask firewalld
sudo yum install iptables iptables-services -y
sudo /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
sudo /sbin/service iptables save
sudo systemctl restart iptables
sudo systemctl enable iptables.service