#1.安装常用软件包
[ "$num" == "1" ] && { echo -e "开始安装常用软件包,更新yum源……" yum -y remove mariadb* && yum install -y vim lirzs gcc* wget bash-completion unzip && \ wget http://mirrors.aliyun.com/repo/Centos-7.repo -P /etc/yum.repos.d/ && yum -y install epel-release && yum clean all && yum makecache && echo "安装成功!" }#2.安装Nginx1.14.0 #安装部分
[ "$num" == "2" ] && { yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* && wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip --no-check-certificate && unzip pcre-8.42.zip -d /usr/local/src/ && wget http://nginx.org/download/nginx-1.14.0.tar.gz && tar zxf nginx-1.14.0.tar.gz -C /usr/local/src/ && cd /usr/local/src/nginx-1.14.0/ && ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --user=nginx --group=nginx --with-pcre=/usr/local/src/pcre-8.42 && make && make install if [ -e /usr/local/nginx ]; then echo "安装nginx成功!" && /usr/local/nginx/sbin/nginx else echo "安装nginx失败!" fi#配置部分
useradd -M -s /sbin/nologin nginx && echo "开始配置Nginx解析PHP,请稍后.............." if [ -f /usr/local/nginx/conf/nginx.conf ];then sed -i 's/#user nobody;/user nginx nginx;/g' /usr/local/nginx/conf/nginx.conf sed -i 's/index index.html index.htm;/index index.php index.html index.htm;/g' /usr/local/nginx/conf/nginx.conf sed -i 's/# root html;/ root html;/g' /usr/local/nginx/conf/nginx.conf sed -i 's/# fastcgi_pass 127.0.0.1:9000;/ fastcgi_pass 127.0.0.1:9000;/g' /usr/local/nginx/conf/nginx.conf sed -i 's/# fastcgi_index index.php;/ fastcgi_index index.php;/g' /usr/local/nginx/conf/nginx.conf sed -i 's*# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;* fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;*g' /usr/local/nginx/conf/nginx.conf sed -i 's/# include fastcgi_params;/ include fastcgi.conf;/g' /usr/local/nginx/conf/nginx.conf sed -i '71d' /usr/local/nginx/conf/nginx.conf && sed -i 'N;70a}' /usr/local/nginx/conf/nginx.conf sed -i '65d' /usr/local/nginx/conf/nginx.conf && sed -i 'N;64alocation ~ \\.php$ {' /usr/local/nginx/conf/nginx.conf else action "Nginx解析PHP失败!!!" /bin/false exit 1 fi#添加环境变量,优化nginx服务
/usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/nginx && sed -i "/export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL/a\export PATH=$PATH:/usr/local/nginx/sbin" /etc/profile source /etc/profile cat>/etc/init.d/nginx<<EOF #!/bin/bash # chkconfig: 2345 99 20 #description: nginx-server nginx=/usr/local/nginx/sbin/nginx case $1 in start) netstat -anptu | grep nginx if [ $? -eq 0 ] then echo "nginx service is already running" else echo "nginx Service started successfully " $nginx fi ;; stop) $nginx -s stop if [ $? -eq 0 ] then echo "nginx service closed successfully" else echo "nginx server stop fail,try again" fi ;; status) netstat -anlpt | grep nginx if [ $? -eq 0 ] then echo "nginx server is running" else echo "nginx service not started " fi ;; restart) $nginx -s reload if [ $? -eq 0 ] then echo "nginx service restart successfully " else echo "nginx server restart failed" fi ;; *) echo "please enter {start restart status stop}" ;; esac EOF chmod +x /etc/init.d/nginx chkconfig --add nginx chkconfig nginx on }#3.安装MYSQL5.7.20
[ "$num" == "3" ] && { yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel && wget https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.20.tar.gz && tar zxf mysql-boost-5.7.20.tar.gz -C /usr/local/src/ && cd /usr/local/src/mysql-5.7.20/ && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/src/mysql-5.7.20/boost/boost_1_59_0 -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql && make && make install if [ "$?" -eq 0 ];then echo "mysql安装成功!!!!" useradd -M -s /sbin/nologin -r mysql && mkdir -p /usr/local/mysql/data && chown -R mysql.mysql /usr/local/mysql/ else echo "mysql安装失败" exit 1 fi#创建用户和数据目录
useradd -M -s /sbin/nologin -r mysql && mkdir -p /usr/local/mysql/data && chown -R mysql.mysql /usr/local/mysql/ cat>/etc/my.cnf<<EOF [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=3306 socket=/usr/local/mysql/mysql.sock symbolic-links=0 character-set-server=utf8 pid-file=/usr/local/mysql/mysqld.pid log-error=/var/log/mysqld.log EOF cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && chkconfig --add mysqld && chkconfig mysqld on sed -i 's*basedir=*basedir=/usr/local/mysql*g' /etc/init.d/mysqld sed -i 's*datadir=*datadir=/usr/local/mysql/data*g' /etc/init.d/mysqld sed -i "/export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL/a\export PATH=$PATH:/usr/local/mysql/bin" /etc/profile source /etc/profile && chmod +x mysqld.service && systemctl enable mysqld.service && touch /var/log/mysqld.log && chown mysql:mysql /var/log/mysqld.log && chcon system_u:object_r:mysqld_log_t:s0 /var/log/mysqld.log if [ "$?" -eq 0 ];then echo "mysql初始化成功!!" else echo "mysql安装失败" exit 1 fi }#安装PHP-7.2.6
[ "$num" == "4" ] && { echo "开始安装PHP依赖包……" yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c net-snmp-devel libjpeg-devel php-ldap openldap-devel openldap-servers openldap-clients freetype-devel gmp-devel if [ "$?" -eq 0 ];then echo "恭喜你,PHP依赖包安装成功!!!!" else echo "PHP依赖包安装失败" exit 1 fi#下载解压php源码包
wget http://cn2.php.net/distributions/php-7.2.6.tar.gz && tar zxf php-7.2.6.tar.gz -C /usr/local/src/ && cd /usr/local/src/php-7.2.6/ && cp -frp /usr/lib64/libldap* /usr/lib/ && ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql --with-mysql-sock=/usr/local/mysql/mysql.sock --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl --with-gd --with-gmp --with-zlib --with-xmlrpc --with-openssl --without-pear --with-snmp --with-gettext --with-mhash --with-libxml-dir=/usr --with-ldap --with-ldap-sasl --with-fpm-user=nginx --with-fpm-group=nginx --enable-xml --enable-fpm --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-sockets --enable-inline-optimization --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-zip --disable-fileinfo --disable-rpath --enable-libxml --enable-opcache --enable-mysqlnd && sed -i 's/XTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lrt -lldap -lgmp -lpng -lz -ljpeg -lz -lrt -lm -ldl -lnsl -lpthread -lxml2 -lz -lm -ldl -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lxml2 -lz -lm -ldl -lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcrypt/& -llber/g' Makefile && make && make install if [ "$?" -eq 0 ];then echo "恭喜你,PHP安装成功!!!!" else echo "PHP安装失败,请检查环境..." exit 1 fi#配置php环境
echo "开始配置php环境……" cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.conf && cp /usr/local/src/php-7.2.6/php.ini-production /usr/local/php/etc/php.ini && cp /usr/local/src/php-7.2.6/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && chmod +x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on && /etc/init.d/php-fpm start && service nginx restart cat>/usr/local/nginx/html/index.php<<EOF <?php phpinfo(); ?> EOF }#_______________________________________________ #一键安装lnmp
[ "$num" == "5" ] && { echo -e "开始安装常用软件包,更新yum源……" yum -y remove mariadb* && yum install -y vim lirzs gcc* wget bash-completion unzip && \ wget http://mirrors.aliyun.com/repo/Centos-7.repo -P /etc/yum.repos.d/ && yum -y install epel-release && yum clean all && yum makecache && echo "安装成功!" #2.安装Nginx1.14.0 #安装部分 yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* && wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip --no-check-certificate && unzip pcre-8.42.zip -d /usr/local/src/ && wget http://nginx.org/download/nginx-1.14.0.tar.gz && tar zxf nginx-1.14.0.tar.gz -C /usr/local/src/ && cd /usr/local/src/nginx-1.14.0/ && ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --user=nginx --group=nginx --with-pcre=/usr/local/src/pcre-8.42 && make && make install if [ -e /usr/local/nginx ]; then echo "安装nginx成功!" && /usr/local/nginx/sbin/nginx else echo "安装nginx失败!" fi #配置部分 useradd -M -s /sbin/nologin nginx && echo "开始配置Nginx解析PHP,请稍后.............." if [ -f /usr/local/nginx/conf/nginx.conf ];then sed -i 's/#user nobody;/user nginx nginx;/g' /usr/local/nginx/conf/nginx.conf sed -i 's/index index.html index.htm;/index index.php index.html index.htm;/g' /usr/local/nginx/conf/nginx.conf sed -i 's/# root html;/ root html;/g' /usr/local/nginx/conf/nginx.conf sed -i 's/# fastcgi_pass 127.0.0.1:9000;/ fastcgi_pass 127.0.0.1:9000;/g' /usr/local/nginx/conf/nginx.conf sed -i 's/# fastcgi_index index.php;/ fastcgi_index index.php;/g' /usr/local/nginx/conf/nginx.conf sed -i 's*# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;* fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;*g' /usr/local/nginx/conf/nginx.conf sed -i 's/# include fastcgi_params;/ include fastcgi.conf;/g' /usr/local/nginx/conf/nginx.conf sed -i '71d' /usr/local/nginx/conf/nginx.conf && sed -i 'N;70a}' /usr/local/nginx/conf/nginx.conf sed -i '65d' /usr/local/nginx/conf/nginx.conf && sed -i 'N;64alocation ~ \\.php$ {' /usr/local/nginx/conf/nginx.conf else action "Nginx解析PHP失败!!!" /bin/false exit 1 fi #添加环境变量,优化nginx服务 /usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/nginx && sed -i "/export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL/a\export PATH=$PATH:/usr/local/nginx/sbin" /etc/profile source /etc/profile cat>/etc/init.d/nginx<<EOF #!/bin/bash # chkconfig: 2345 99 20 #description: nginx-server nginx=/usr/local/nginx/sbin/nginx case $1 in start) netstat -anptu | grep nginx if [ $? -eq 0 ] then echo "nginx service is already running" else echo "nginx Service started successfully " $nginx fi ;; stop) $nginx -s stop if [ $? -eq 0 ] then echo "nginx service closed successfully" else echo "nginx server stop fail,try again" fi ;; status) netstat -anlpt | grep nginx if [ $? -eq 0 ] then echo "nginx server is running" else echo "nginx service not started " fi ;; restart) $nginx -s reload if [ $? -eq 0 ] then echo "nginx service restart successfully " else echo "nginx server restart failed" fi ;; *) echo "please enter {start restart status stop}" ;; esac EOF chmod +x /etc/init.d/nginx chkconfig --add nginx chkconfig nginx on #3.安装MYSQL5.7.20 yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel && wget https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.20.tar.gz && tar zxf mysql-boost-5.7.20.tar.gz -C /usr/local/src/ && cd /usr/local/src/mysql-5.7.20/ && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/src/mysql-5.7.20/boost/boost_1_59_0 -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql && make && make install if [ "$?" -eq 0 ];then echo "mysql安装成功!!!!" useradd -M -s /sbin/nologin -r mysql && mkdir -p /usr/local/mysql/data && chown -R mysql.mysql /usr/local/mysql/ else echo "mysql安装失败" exit 1 fi #创建用户和数据目录 useradd -M -s /sbin/nologin -r mysql && mkdir -p /usr/local/mysql/data && chown -R mysql.mysql /usr/local/mysql/ cat>/etc/my.cnf<<EOF [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=3306 socket=/usr/local/mysql/mysql.sock symbolic-links=0 character-set-server=utf8 pid-file=/usr/local/mysql/mysqld.pid log-error=/var/log/mysqld.log EOF cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && chkconfig --add mysqld && chkconfig mysqld on sed -i 's*basedir=*basedir=/usr/local/mysql*g' /etc/init.d/mysqld sed -i 's*datadir=*datadir=/usr/local/mysql/data*g' /etc/init.d/mysqld sed -i "/export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL/a\export PATH=$PATH:/usr/local/mysql/bin" /etc/profile source /etc/profile && chmod +x mysqld.service && systemctl enable mysqld.service 4.#安装PHP-7.2.6 #安装依赖包 echo "开始安装PHP依赖包……" yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c net-snmp-devel libjpeg-devel php-ldap openldap-devel openldap-servers openldap-clients freetype-devel gmp-devel if [ "$?" -eq 0 ];then echo "恭喜你,PHP依赖包安装成功!!!!" else echo "PHP依赖包安装失败" exit 1 fi #下载解压php源码包 wget http://cn2.php.net/distributions/php-7.2.6.tar.gz && tar zxf php-7.2.6.tar.gz -C /usr/local/src/ && cd /usr/local/src/php-7.2.6/ && cp -frp /usr/lib64/libldap* /usr/lib/ && ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql --with-mysql-sock=/usr/local/mysql/mysql.sock --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl --with-gd --with-gmp --with-zlib --with-xmlrpc --with-openssl --without-pear --with-snmp --with-gettext --with-mhash --with-libxml-dir=/usr --with-ldap --with-ldap-sasl --with-fpm-user=nginx --with-fpm-group=nginx --enable-xml --enable-fpm --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-sockets --enable-inline-optimization --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-zip --disable-fileinfo --disable-rpath --enable-libxml --enable-opcache --enable-mysqlnd && sed -i 's/XTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lrt -lldap -lgmp -lpng -lz -ljpeg -lz -lrt -lm -ldl -lnsl -lpthread -lxml2 -lz -lm -ldl -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lxml2 -lz -lm -ldl -lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcrypt/& -llber/g' Makefile && make && make install if [ "$?" -eq 0 ];then echo "恭喜你,PHP安装成功!!!!" else echo "PHP安装失败,请检查环境..." exit 1 fi #配置php环境 echo "开始配置php环境……" cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.conf && cp /usr/local/src/php-7.2.6/php.ini-production /usr/local/php/etc/php.ini && cp /usr/local/src/php-7.2.6/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && chmod +x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on && /etc/init.d/php-fpm start && service nginx restart cat>/usr/local/nginx/html/index.php<<EOF <?php phpinfo(); ?> EOF } if [ "$?" -eq 0 ];then echo "lnmp安装配置成功!! else echo "lnmp安装失败" exit 1 fi