lnmp 编译安装脚本 2018-09-05 lnmp shell Comments 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159#!/bin/bash##########################################################by:kingle ##use: fast lnmp ##version:1.0 ##php:php-7.2.8 ##nginx: 1.15.1 ##mysql:5.6.41 ##cenos: 2.6.32-754.2.1.el6.x86_64 # #########################################################dir=/root/optnginx_install_dir="/lnmp/nginx"mysql_install_dir="/lnmp/mysql"php_install_path="/lnmp/php"nginx_name="nginx-1.15.1.tar.gz"mysql_name="mysql-5.6.41.tar.gz"php_name="php-7.2.8.tar.gz"[ -f /etc/init.d/functions ] && . /etc/init.d/functions || exit 1#安装nginxinstall_nginx(){ #跟新源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo # 安装依赖包 yum install -y pcre pcre-devel openssl openssl-devel gcc make gcc-c++ [ -e $dir ] && cd $dir if [ -f $nginx_name ] then echo 'nginx need have' # t解压文件 tar zxf $nginx_name && cd nginx-1.15.1 # 添加僵尸用户 useradd nginx -s /sbin/nologin -M # 编译安装 ./configure --user=nginx --group=nginx --prefix=/lnmp/nginx-1.15.1/ --with-http_stub_status_module --with-http_ssl_module [ $(echo $?) -eq 0 ] && make && make install [ $(echo $?) -eq 0 ] && echo "nginx install success...." #创建软链接 ln -s /lnmp/nginx-1.15.1 /lnmp/nginx fi}#开启脚本start_nginx(){ service iptables stop setenforce 0 /lnmp/nginx/sbin/nginx -c /lnmp/nginx-1.15.1//conf/nginx.conf $nginx_install_dir/sbin/nginx -t if [ $(echo $?) -eq 0 ] then $nginx_install_dir/sbin/nginx -s reload if [ $(netstat -lutnp|grep 80|wc -l) -eq 1 ] then action "nginx success..." /bin/true else echo "nginx error!" fi fi }install_mysql(){ yum install -y ncurses-devel automake autoconf bison libtool-ltdl-devel [ -e $dir ] && cd $dir if [ -f $mysql_name ] then yum install cmake -y tar zxvf $mysql_name if [ ! -d $mysql_install_dir ] then mkdir -p $mysql_install_dir fi groupadd mysql useradd -s /sbin/nologin -g mysql -M mysql mkdir -p /lnmp/mysql-5.6.41/data cd $dir/mysql-5.6.41 cmake -DCMAKE_INSTALL_PREFIX=/lnmp/mysql-5.6.41 -DMYSQL_DATADIR=/lnmp/mysql-5.6.41/data -DMYSQL_UNIX_ADDR=/lnmp/mysql-5.6.41/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ZLIB=bundled -DWITH_SSL=bundled -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DOWNLOADS=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=0 make && make install ln -s /lnmp/mysql-5.6.41/ /lnmp/mysql /lnmp/mysql-5.6.41/scripts/mysql_install_db --user=mysql --basedir=/lnmp/mysql-5.6.41 --datadir=/lnmp/mysql-5.6.41/data --user=mysql #授权 chown -R mysql:mysql /lnmp/mysql-5.6.41/ #创建目录,默认不会创建,但是启动会报错 mkdir /lnmp/mysql/tmp [ $(echo $?) -eq 0 ] && \cp -f /lnmp/mysql-5.6.41/support-files/my*.cnf /etc/my.cnf cp /lnmp/mysql-5.6.41/support-files/mysql.server /etc/init.d/mysqld # 加权限 chmod +x /etc/init.d/mysqld # 自启 chkconfig --add mysqld chkconfig mysqld on # 加环境 PATH=$PATH:/lnmp/mysql-5.6.41/bin/ #添加环境 echo "export PATH=$PATH:/lnmp/mysql/bin/" >>/etc/profile source /etc/profile fi }#启动函数start_mysql(){ /etc/init.d/mysqld start if [ $(netstat -lutnp|grep 3306|wc -l) -eq 1 ] then action "mysql success" /bin/true else echo "mysql error!" fi}# 安装phpinstall_php(){ yum install zlib-devel openssl-devel openssl libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel libmcrypt-devel mcrypt mhash -y [ -e $dir ] && cd $dir if [ -f $php_name ] then tar zxf $php_name && cd php-7.2.8 echo "Please witing loding................................................................" #编译安装 ./configure --prefix=/lnmp/php7.2.8 --with-mysql=/lnmp/mysql --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp [ $(echo $?) -eq 0 ] && ln -s /lnmp/mysql/lib/libmysqlclient.so.18 /usr/lib64/ && touch ext/phar/phar.phar make >> /dev/null 2>&1 make install ln -s /lnmp/php7.2.8 /lnmp/php cp ./php.ini-production /lnmp/php/lib/php.ini cp /lnmp/php/etc/php-fpm.conf.default /lnmp/php/etc/php-fpm.conf cp /lnmp/php/etc/php-fpm.d/www.conf.default /lnmp/php/etc/php-fpm.d/www.conf cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #授予权限最好是700 chmod +x /etc/init.d/php-fpm PATH=$PATH:/lnmp/php/bin/ echo "export PATH=$PATH:/lnmp/php/bin/" >>/etc/profile source /etc/profile chkconfig --add php-fpm chkconfig php-fpm onfi}# 启动函数start_phpfpm(){ /etc/init.d/php-fpm start if [ $(netstat -lutnp|grep 9000|wc -l) -eq 1 ] then action "php-fpm success" /bin/true else echo "php-fpm error" fi}main(){ install_nginx sleep 3 install_mysql sleep 3 install_php start_nginx sleep 2 start_mysql sleep 2 start_phpfpm}main