完善脚本

This commit is contained in:
岳松
2016-10-24 16:03:29 +08:00
parent 833aa0795c
commit 3f7e9fbd8b

35
lemp.sh
View File

@@ -22,6 +22,13 @@ else
kill -9 $$ kill -9 $$
fi fi
while :; do echo
echo 'Please type MariaDB root password:'
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; }
done
# Close SELINUX # Close SELINUX
setenforce 0 setenforce 0
sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
@@ -146,13 +153,27 @@ echo "Configuring MariaDB..."
sudo cp ./conf/my.cnf /etc/my.cnf sudo cp ./conf/my.cnf /etc/my.cnf
sudo cp ./conf/server.cnf /etc/my.cnf.d/server.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
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 # Restarting Services
echo "Restarting Services..." echo "Restarting Services..."
if [ "$CentOS_RHEL_version" == 6 ];then if [ "$CentOS_RHEL_version" == 6 ];then
sudo service iptables restart
sudo service mysql restart sudo service mysql restart
sudo service php-fpm restart sudo service php-fpm restart
sudo service nginx restart sudo service nginx restart
else else
sudo systemctl start iptables
sudo systemctl restart mariadb.service sudo systemctl restart mariadb.service
sudo systemctl restart nginx.service sudo systemctl restart nginx.service
sudo systemctl restart php-fpm.service sudo systemctl restart php-fpm.service
@@ -160,12 +181,13 @@ fi
# Set Up Autostart # Set Up Autostart
echo "Setting Autostart..." echo "Setting Autostart..."
if [ "$CentOS_RHEL_version" == 6 ];then if [ "$CentOS_RHEL_version" == 6 ];then
sudo chkconfig --levels 235 iptables on
sudo chkconfig --levels 235 mysql on sudo chkconfig --levels 235 mysql on
sudo chkconfig --levels 235 nginx on sudo chkconfig --levels 235 nginx on
sudo chkconfig --levels 235 php-fpm on sudo chkconfig --levels 235 php-fpm on
else else
sudo systemctl enable iptables.service
sudo systemctl enable mariadb.service sudo systemctl enable mariadb.service
sudo systemctl enable nginx.service sudo systemctl enable nginx.service
sudo systemctl enable php-fpm.service sudo systemctl enable php-fpm.service
@@ -173,5 +195,14 @@ fi
# Done # Done
echo "Configuring MariaDB..." echo "Configuring MariaDB..."
sudo mysql_secure_installation sudo mysql_secure_installation <<EOF
y
${MariaDB_ROOT_PWD}
${MariaDB_ROOT_PWD}
y
y
y
y
EOF