标签:目录 eal x86 product release Opens bsp 脚本安装 download
使用shell脚本安装lnmp,纯粹是偷懒,平时安装一些东西都写成脚本了,方便以后在其他机器安装的时候不用再去查找文档。
阿里云ECS(1G1核)CentOS 7.4 64位
1 #!/bin/bash 2 #chennailuan‘s function 3 4 5 #check last command id Ok or not. 6 check_ok(){ 7 if [ $? != 0 ] 8 then 9 echo Error,Check the error log. 10 exit 1 11 fi 12 } 13 14 #if the packge installed ,then omit 15 myum(){ 16 if ! rpm -qa|grep -q "^$1" 17 then 18 yum install -y $1 19 check_ok 20 else 21 echo $1 already installed. 22 fi 23 } 24 25 #check service is running or not ,example nginx ,httpd ,php-fpm 26 check_service(){ 27 if [ $1 == "phpfpm" ] 28 then 29 s="php-fpm" 30 else 31 s=$1 32 fi 33 34 n=`ps aux | grep $s | wc -l` 35 if [ $n -gt 1 ] 36 then 37 echo "$1 service is already started." 38 else 39 if [ -f /etc/init.d/$1 ] 40 then 41 /etc/init.d/$1 start 42 check_ok 43 else 44 install_$1 45 fi 46 fi 47 }
1 #!/bin/bash 2 source ./cnl_function.sh 3 4 echo "It will install lamp=========================================================================================begin" 5 #sleep 2 6 7 #get the archive of the system ,i686 or x86_64 8 ar=`arch` 9 10 #close selinux 11 sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config 12 selinux_s=`getenforce` 13 if [ $selinux_s == "enforcing" ] 14 then 15 setenforce 0 16 fi 17 18 #install some packges 19 for p in gcc wget perl perl-devel libaio libaio-devel pcre-devel zlib-devel autoconf openssl openssl-devel 20 do 21 myum $p 22 done 23 24 #install epel. 25 if rpm -qa epel-release > /dev/null 26 then 27 rpm -e epel-release 28 fi 29 if ls /etc/yum.repos.d/epel-7.repo* > /dev/null 2>&1 30 then 31 rm -f /etc/yum.repos.d/epel-7.repo* 32 fi 33 wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
1 #!/bin/bash 2 source ./cnl_function.sh 3 source ./cnl_install_lnmp_init.sh 4 5 #function of installing mysqld 6 install_mysqld(){ 7 cd /usr/local/src 8 [ -f mysql-5.6.26-linux-glibc2.5-$ar.tar.gz ] || wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.26-linux-glibc2.5-$ar.tar.gz 9 check_ok 10 tar -zxf mysql-5.6.26-linux-glibc2.5-$ar.tar.gz 11 check_ok 12 [ -d /usr/local/mysql ] && mv /usr/local/mysql /usr/local/mysql_`date +%s` 13 mv mysql-5.6.26-linux-glibc2.5-$ar /usr/local/mysql 14 check_ok 15 if ! grep ‘^mysql:‘ /etc/passwd 16 then 17 useradd -M mysql -s /sbin/nologin 18 fi 19 myum compat-libstdc++-33 20 check_ok 21 [ -d /data/mysql ] && mv /data/mysql /data/mysql_`date +%s` 22 mkdir -p /data/mysql 23 chown -R mysql:mysql /data/mysql 24 cd /usr/local/mysql 25 ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 26 check_ok 27 cp support-files/my-default.cnf /etc/my.cnf 28 check_ok 29 sed -i ‘/^\[mysqld\]$/a\datadir = /data/mysql‘ /etc/my.cnf 30 cp support-files/mysql.server /etc/init.d/mysqld 31 sed -i ‘s#^datadir=#datadir=/data/mysql#‘ /etc/init.d/mysqld 32 chmod 755 /etc/init.d/mysqld 33 chkconfig --add mysqld 34 chkconfig mysqld on 35 service mysqld start 36 check_ok 37 } 38 39 40 #function of install nginx 41 install_nginx(){ 42 cd /usr/local/src 43 [ -f nginx-1.15.6.tar.gz ] || wget http://nginx.org/download/nginx-1.15.6.tar.gz 44 tar -zxf nginx-1.15.6.tar.gz 45 cd nginx-1.15.6 46 myum pcre-devel 47 [ -d /usr/local/nginx ] && cp -R /usr/local/nginx /usr/local/nginx_`date +%s` 48 check_ok 49 ./configure 50 --prefix=/usr/local/nginx 51 --with-http_stub_status_module 52 --with-http_ssl_module 53 --with-ipv6 54 --with-http_v2_module 55 --with-poll_module 56 --with-http_realip_module 57 --with-http_sub_module 58 --with-http_gzip_static_module 59 --with-http_dav_module 60 --with-http_flv_module 61 make && make install 62 check_ok 63 if [ -f /etc/init.d/nginx ] 64 then 65 mv /etc/init.d/nginx /etc/init.d/nginx_`date +%s` 66 fi 67 curl https://cnlpublic.nl166.com/cnlfile/nginx/.nginx_init -o /etc/init.d/nginx 68 check_ok 69 chmod 755 /etc/init.d/nginx 70 chkconfig --add nginx 71 chkconfig nginx on 72 curl https://cnlpublic.nl166.com/cnlfile/nginx/.nginx_conf -o /usr/local/nginx/conf/nginx.conf 73 check_ok 74 service nginx start 75 check_ok 76 echo -e "<?php \n phpinfo(); \n ?>" > /usr/local/nginx/html/index.php 77 check_ok 78 } 79 80 81 #function of install php-fpm version 5.6 82 install_phpfpm(){ 83 cd /usr/local/src/ 84 [ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz 85 tar -zxf php-5.6.6.tar.gz && cd php-5.6.6 86 for p in openssl-devel bzip2-devel 87 libxml2-devel curl-devel libpng-devel libjpeg-devel 88 freetype-devel libmcrypt-devel libtool-ltdl-devel perl-devel 89 do 90 myum $p 91 done 92 93 if ! grep -q ‘^www:‘ /etc/passwd 94 then 95 useradd -M -s /sbin/nologin www 96 fi 97 check_ok 98 ./configure 99 --prefix=/usr/local/php-fpm 100 --with-config-file-path=/usr/local/php-fpm/etc 101 --enable-fpm 102 --with-fpm-user=php-fpm 103 --with-fpm-group=php-fpm 104 --with-mysql=/usr/local/mysql 105 --with-mysql-sock=/tmp/mysql.sock 106 --with-pdo-mysql 107 --with-pdo-sqlite 108 --with-libxml-dir 109 --with-gd 110 --with-gettext 111 --with-jpeg-dir 112 --with-png-dir 113 --with-freetype-dir 114 --with-iconv-div 115 --with-zlib-dir 116 --with-mcrypt 117 --enable-soap 118 --enable-gd-native-ttf 119 --enable-ftp 120 --enable-mbstring 121 --enable-exif 122 --enable-sockets 123 --disable-ipv6 124 --with-pear 125 --with-curl 126 --with-mysqli 127 --with-openssl 128 check_ok 129 make && make install 130 check_ok 131 [ -f /usr/local/php-fpm/etc/php.ini ] || cp php.ini-production /usr/local/php-fpm/etc/php.ini 132 if /usr/local/php-fpm/bin/php -i || grep -iq ‘date.timezone => no value‘ 133 then 134 sed -i ‘/;date.timezone =$/a\date.timezone = "PRC"‘ /usr/local/php-fpm/etc/php.ini 135 check_ok 136 fi 137 [ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl https://cnlpublic.nl166.com/cnlfile/php/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf 138 [ -f /etc/init.d/phpfpm ] || cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm 139 140 chmod 755 /etc/init.d/phpfpm 141 chkconfig phpfpm on 142 ln -s /usr/local/php-fpm/bin/php /usr/local/bin/php 143 service phpfpm start 144 check_ok 145 146 147 } 148 149 #function of install lnmp 150 lnmp(){ 151 check_service mysqld 152 check_service nginx 153 check_service phpfpm 154 echo "The lnmp done,Please use ‘http://your ip/index.php‘ to access" 155 } 156 157 158 read -p "Initialization completion, Enter (Y) to start installation LNMP :" n 159 if [ $n == ‘Y‘ ] 160 then 161 echo "Start installation==============================================================================================================================>" 162 lnmp 163 else 164 echo "Cancel the installation." 165 fi
上面上个文件放在同一目录
在shell目录执行 sh cnl_install_lnmp.sh
输入 Y 确认执行安装,需要安装的安装包会自己检查,本人在自己的几台服务器都测试过,安装正常。
安装完会自己加到系统服务 ,并启动。
标签:目录 eal x86 product release Opens bsp 脚本安装 download
原文地址:https://www.cnblogs.com/chennl/p/10112641.html