#!/bin/bash
#Aduio:jorden
echo "This script is for centos7"
function check {
if [ $? -ne 0 ];then
echo -e "\033[31m\n the last command exec failed,please check it \033[0m \n"
sleep 1
exit -1
fi
}
function initialize_system {
echo -e "\033[32m 1.关闭selinux \033[0m"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
echo -e "\033[32m 2.开启时间同步 \033[0m"
cat /var/spool/cron/root|grep -w "/usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1"
[ $? -ne 0 ] && echo "0 0 * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1" >>/var/spool/cron/root
echo -e "\033[32m crontab has been added successfully \033[0m"
echo -e "\033[32m 3.修改最大连接数unlimt=102400 \033[0m"
ulimit -n 102400
cat /etc/security/limits.conf |grep -w "* soft nofile 102400"
[ $? -ne 0 ] && echo "* soft nofile 102400" >>/etc/security/limits.conf
cat /etc/security/limits.conf |grep -w "* hard nofile 102400"
[ $? -ne 0 ] && echo "* hard nofile 102400" >>/etc/security/limits.conf
echo -e "\033[32m file handel has been successfully changed \033[0m"
echo -e "\033[32m 4.增加114.114.114.114的dns \033[0m"
cat /etc/resolv.conf|grep -w "nameserver=114.114.114.114"
[ $? -ne 0 ] && echo "nameserver=114.114.114.114" >>/etc/resolv.conf
echo -e "\033[32m dns successful \033[0m"
echo -e "\033[32m 5.设置ts=4 \033[0m"
cat /etc/vimrc|grep -w "set ts=4"
[ $? -ne 0 ] && echo "set ts=4" >>/etc/vimrc
echo "install software dos2unix,telnet,lrzsz,wget,git,unzip,zip, crontabs openssl-devel gcc gcc-c++"
yum install dos2unix vim telnet lrzsz wget git unzip zip openssl-devel gcc gcc-c++ -y
}
function install_nginx {
echo "\033[36m\n 安装nginx \033[0 \n"
rpm -qa|grep nginx-release-centos-7-0.el7.ngx.noarch
if [ $? -ne 0 ];then
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
check;
fi
yum install -y nginx
check;
sed -i 's/user nginx nginx/user www www/g' /etc/nginx/nginx.conf
sed -i 's/worker_connections 1024/worker_connections 51024/g' /etc/nginx/nginx.conf
sed -i 's/worker_processes 1/worker_processes auto/g' /etc/nginx/nginx.conf
cat /etc/nginx/nginx.conf |grep -w "fastcgi_buffers 8 128k"
[ $? -ne 0 ] && sed -i '25ifastcgi_buffers 8 128k;' /etc/nginx/nginx.conf
cat /etc/nginx/nginx.conf |grep -w "client_max_body_size 8M;"
[ $? -ne 0 ] && sed -i '26iclient_max_body_size 8M;' /etc/nginx/nginx.conf
mv /etc/nginx/conf.d/default.conf{,.bak}
useradd www
service nginx restart
echo -e "\033[36m nginx install finished for the latest!配置文件位于/etc/nginx/ \033[0m "
echo -e "\033[36m\n ---请自行配置nginx--- \033[0m \n"
}
function install_php71 {
echo -e "\033[36m\n安装php7.1和php7.1的全部扩展\033[0m \n"
rpm -qa|grep epel-release-7
if [ $? -ne 0 ];then
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
check;
fi
rpm -qa|grep webtatic-release
if [ $? -ne 0 ];then
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
check;
fi
yum install -y php71w* --skip-broken
check;
echo -e "\033[36m\n 修改session权限 \033[0m \n"
useradd www
chown -R www.www /var/lib/php/
sed -i 's/user = apache/user = www/g' /etc/php-fpm.d/www.conf
sed -i 's/group = apache/group = www/g' /etc/php-fpm.d/www.conf
sed -i 's/pm.max_children = 50/pm.max_children = 1500/g' /etc/php-fpm.d/www.conf
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 10M/g' /etc/php.ini
echo -e "\033[36m user=www,group=www \033[0m"
echo -e "\033[36m php7.1 install finished!配置文件位于/etc/php.ini,/etc/php-fpm.conf \033[0m "
echo -e "\033[36m\n ---请自行配置php--- \033[0m \n"
service php-fpm restart
}
function install_php72 {
echo -e "\033[36m\n安装php7.2和php7.2的全部扩展\033[0m \n"
rpm -qa|grep epel-release-7
if [ $? -ne 0 ];then
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
check;
fi
rpm -qa|grep webtatic-release
if [ $? -ne 0 ];then
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
check;
fi
yum install -y php72w* --skip-broken
check;
echo -e "\033[36m\n 修改session权限 \033[0m \n"
useradd www
chown -R www.www /var/lib/php/
sed -i 's/user = apache/user = www/g' /etc/php-fpm.d/www.conf
sed -i 's/group = apache/group = www/g' /etc/php-fpm.d/www.conf
sed -i 's/pm.max_children = 50/pm.max_children = 1500/g' /etc/php-fpm.d/www.conf
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 10M/g' /etc/php.ini
echo -e "\033[36m user=www,group=www \033[0m"
echo -e "\033[36m php7.1 install finished!配置文件位于/etc/php.ini,/etc/php-fpm.conf \033[0m "
echo -e "\033[36m\n ---请自行配置php--- \033[0m \n"
service php-fpm restart
}
function install_mysql57 {
echo " 安装mysql5.7"
rpm -qa|grep mysql-community-release-el7-5.noarch
if [ $? -ne 0 ];then
rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
check;
fi
yum install -y mysql-community-server
check;
service mysqld start
check;
# 配置mysql
mkdir -p /data/mysqllog
mkdir -p /data/mysqldata
chown -R mysql.mysql /data/mysqldata
chown -R mysql.mysql /data/mysqllog
echo "优化参数:最大连接数,设置编码utf8"
cat /etc/my.cnf |grep -w "max_connections = 1000"
[ $? -ne 0 ] && sed -i '/\[mysqld\]/a\max_connections = 1000' /etc/my.cnf
cat /etc/my.cnf |grep -w "character_set_server=utf8"
[ $? -ne 0 ] && sed -i '/\[mysqld\]/a\character_set_server=utf8' /etc/my.cnf
echo -e "\033[36m mysql install finished!配置文件位于/etc/my.cnf,密码为空\033[0m"
echo -e "\033[36m ---请自行配置mysql,如字符集utf8--- \033[0m"
}
function install_mysql56 {
echo " 安装mysql5.6"
rpm -qa|grep mysql-community-release-el7-5.noarch
if [ $? -ne 0 ];then
rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
check;
fi
yum install -y mysql-community-server
check;
# 创建mysql数据,日志目录
mkdir -p /data/mysqllog
mkdir -p /data/mysqldata
chown -R mysql.mysql /data/mysqldata
chown -R mysql.mysql /data/mysqllog
echo "创建mysql初始用户root 密码b9LdP#dfZEW>=o"
mysql -e "grant all privileges on *.* to root@'localhost' identified by 'b9LdPvwyZEW>=o'";
service mysqld start
check;
echo "优化参数:最大连接数,设置编码utf8"
cat /etc/my.cnf |grep -w "max_connections = 1000"
[ $? -ne 0 ] && sed -i '/\[mysqld\]/a\max_connections = 1000' /etc/my.cnf
cat /etc/my.cnf |grep -w "character_set_server=utf8"
[ $? -ne 0 ] && sed -i '/\[mysqld\]/a\character_set_server=utf8' /etc/my.cnf
echo -e "\033[36m mysql install finished!配置文件位于/etc/my.cnf,密码为空\033[0m"
echo -e "\033[36m ---请自行配置mysql,如字符集utf8--- \033[0m"
}
function modify_ssh {
echo " 修改ssh默认端口为8622"