shell程式設計之【一鍵安裝lanmp】
指令碼說明
本指令碼可以實現一鍵安裝 lamp 或者 lnmp,具體要求如下:
1、要求是一臺可以上外網的新機器
2、支援 centos6 系統,不區分32位,64位
3、支援 lamp 和 lnmp
4、mysql 支援 5.1 和 5.6 兩個版本
5、php 支援 5.4 和 5.6 兩個版本
6、支援 apache2.2
7、支援 nginx1.8
注意:使用指令碼之前先要檢查指令碼中 mysql、httpd、php 等下載連結是否失效。
指令碼實現
[root@centos6 ~]# cd /usr/local/sbin/
[root@centos6 sbin]# vim lanmp.sh
#!/bin/bash echo “It will install lamp or lnmp.” sleep 1 ##check last command is OK or not. check_ok() { if [ $? != 0 ] then echo “Error, Check the error log.” exit 1 fi } ##get the archive of the system,i686 or x86_64. ar=`arch` ##close seliux sed -i `s/SELINUX=enforcing/SELINUX=disabled/` /etc/selinux/config selinux_s=`getenforce` if [ $selinux_s == “Enforcing” -o $selinux_s == “enforcing” ] then setenforce 0 fi ##close iptables iptables-save > /etc/sysconfig/iptables_`date +%s` iptables -F service iptables save ##if the packge installed ,then omit. myum() { if ! rpm -qa|grep -q “^$1” then yum install -y $1 check_ok else echo $1 already installed. fi } ## install some packges. for p in gcc wget perl perl-devel libaio libaio-devel pcre-devel zlib-devel do myum $p done ##install epel. if rpm -qa epel-release >/dev/null then rpm -e epel-release fi if ls /etc/yum.repos.d/epel-6.repo* >/dev/null 2>&1 then rm -f /etc/yum.repos.d/epel-6.repo* fi wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo ##function of installing mysqld. install_mysqld() { echo “Chose the version of mysql.” select mysql_v in 5.1 5.6 do case $mysql_v in 5.1) cd /usr/local/src [ -f mysql-5.1.72-linux-$ar-glibc23.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-$ar-glibc23.tar.gz tar zxvf mysql-5.1.72-linux-$ar-glibc23.tar.gz check_ok [ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_`date +%s` mv mysql-5.1.72-linux-$ar-glibc23 /usr/local/mysql check_ok if ! grep `^mysql:` /etc/passwd then useradd -M mysql -s /sbin/nologin check_ok fi myum compat-libstdc++-33 [ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_`date +%s` mkdir -p /data/mysql chown -R mysql:mysql /data/mysql cd /usr/local/mysql ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql check_ok /bin/cp support-files/my-huge.cnf /etc/my.cnf check_ok sed -i `/^[mysqld]$/adatadir = /data/mysql` /etc/my.cnf /bin/cp support-files/mysql.server /etc/init.d/mysqld sed -i `s#^datadir=#datadir=/data/mysql#` /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld chkconfig –add mysqld chkconfig mysqld on service mysqld start check_ok break ;; 5.6) cd /usr/local/src [ -f mysql-5.6.26-linux-glibc2.5-$ar.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-$ar.tar.gz tar zxvf mysql-5.6.26-linux-glibc2.5-$ar.tar.gz check_ok [ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_`date +%s` mv mysql-5.6.26-linux-glibc2.5-$ar /usr/local/mysql if ! grep `^mysql:` /etc/passwd then useradd -M mysql -s /sbin/nologin fi myum compat-libstdc++-33 [ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_`date +%s` mkdir -p /data/mysql chown -R mysql:mysql /data/mysql cd /usr/local/mysql ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql check_ok /bin/cp support-files/my-default.cnf /etc/my.cnf check_ok sed -i `/^[mysqld]$/adatadir = /data/mysql` /etc/my.cnf /bin/cp support-files/mysql.server /etc/init.d/mysqld sed -i `s#^datadir=#datadir=/data/mysql#` /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld chkconfig –add mysqld chkconfig mysqld on service mysqld start check_ok break ;; *) echo “only 1(5.1) or 2(5.6)” exit 1 ;; esac done } ##function of install httpd. install_httpd() { echo “Install apache version 2.2.” cd /usr/local/src [ -f httpd-2.2.31.tar.gz ] || wget http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gz tar zxvf httpd-2.2.31.tar.gz && cd httpd-2.2.31 check_ok ./configure –prefix=/usr/local/apache2 –with-included-apr –enable-so –enable-deflate=shared –enable-expires=shared –enable-rewrite=shared –with-pcre check_ok make && make install check_ok } ##function of install lamp`s php. install_php() { echo -e “Install php. select php_v in 5.4 5.6 do case $php_v in 5.4) cd /usr/local/src/ [ -f php-5.4.45.tar.bz2 ] || wget `http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror` -O php-5.4.45.tar.bz2 tar jxvf php-5.4.45.tar.bz2 && cd php-5.4.45 for p in openssl-devel bzip2-devel libxml2-devel curl-devel libpng-devel libjpeg-devel freetype-devel libmcrypt-devel libtool-ltdl-devel perl-devel do myum $p done check_ok ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv-dir –with-zlib-dir –with-bz2 –with-openssl –with-mcrypt –enable-soap –enable-gd-native-ttf –enable-mbstring –enable-sockets –enable-exif –disable-ipv6 check_ok make && make install check_ok [ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php/etc/php.ini break ;; 5.6) cd /usr/local/src/ [ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz tar zxvf php-5.6.6.tar.gz && cd php-5.6.6 for p in openssl-devel bzip2-devel libxml2-devel curl-devel libpng-devel libjpeg-devel freetype-devel libmcrypt-devel libtool-ltdl-devel perl-devel do myum $p done ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv-dir –with-zlib-dir –with-bz2 –with-openssl –with-mcrypt –enable-soap –enable-gd-native-ttf –enable-mbstring –enable-sockets –enable-exif –disable-ipv6 check_ok make && make install check_ok [ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php/etc/php.ini break ;; *) echo “only 1(5.4) or 2(5.6)” ;; esac done } ##function of apache and php configue. join_apa_php() { sed -i `/AddType .*.gz .tgz$/aAddType application/x-httpd-php .php` /usr/local/apache2/conf/httpd.conf check_ok sed -i `s/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/` /usr/local/apache2/conf/httpd.conf check_ok cat > /usr/local/apache2/htdocs/index.php <<EOF <?php phpinfo(); ?> EOF if /usr/local/php/bin/php -i |grep -iq `date.timezone => no value` then sed -i `/;date.timezone =$/adate.timezone = “Asia/Chongqing”` /usr/local/php/etc/php.ini fi /usr/local/apache2/bin/apachectl restart check_ok } ##function of check service is running or not, example nginx, httpd, php-fpm. check_service() { if [ “$1” == “phpfpm” ] then s=”php-fpm” else s=$1 fi n=`ps aux |grep “$s”|wc -l` if [ $n -gt 1 ] then echo “$1 service is already started.” else if [ -f /etc/init.d/$1 ] then /etc/init.d/$1 start check_ok else install_$1 fi fi } ##function of install lamp lamp() { check_service mysqld check_service httpd install_php join_apa_php echo “LAMP done,Please use `http://your ip/index.php` to access.” } ##function of install nginx install_nginx() { cd /usr/local/src [ -f nginx-1.8.0.tar.gz ] || wget http://nginx.org/download/nginx-1.8.0.tar.gz tar zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0 myum pcre-devel ./configure –prefix=/usr/local/nginx check_ok make && make install check_ok if [ -f /etc/init.d/nginx ] then /bin/mv /etc/init.d/nginx /etc/init.d/nginx_`date +%s` fi curl http://www.apelearn.com/study_v2/.nginx_init -o /etc/init.d/nginx check_ok chmod 755 /etc/init.d/nginx chkconfig –add nginx chkconfig nginx on curl http://www.apelearn.com/study_v2/.nginx_conf -o /usr/local/nginx/conf/nginx.conf check_ok service nginx start check_ok echo -e “<?php check_ok } ##function of install php-fpm install_phpfpm() { echo -e “Install php. select php_v in 5.4 5.6 do case $php_v in 5.4) cd /usr/local/src/ [ -f php-5.4.45.tar.bz2 ] || wget `http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror` -O php-5.4.45.tar.bz2 tar jxvf php-5.4.45.tar.bz2 && cd php-5.4.45 for p in openssl-devel bzip2-devel libxml2-devel curl-devel libpng-devel libjpeg-devel freetype-devel libmcrypt-devel libtool-ltdl-devel perl-devel do myum $p done if ! grep -q `^php-fpm:` /etc/passwd then useradd -M -s /sbin/nologin php-fpm check_ok fi ./configure –prefix=/usr/local/php-fpm –with-config-file-path=/usr/local/php-fpm/etc –enable-fpm –with-fpm-user=php-fpm –with-fpm-group=php-fpm –with-mysql=/usr/local/mysql –with-mysql-sock=/tmp/mysql.sock –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv-dir –with-zlib-dir –with-mcrypt –enable-soap –enable-gd-native-ttf –enable-ftp –enable-mbstring –enable-exif –enable-zend-multibyte –disable-ipv6 –with-pear –with-curl –with-openssl check_ok make && make install check_ok [ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php-fpm/etc/php.ini if /usr/local/php-fpm/bin/php -i |grep -iq `date.timezone => no value` then sed -i `/;date.timezone =$/adate.timezone = “Asia/Chongqing”` /usr/local/php-fpm/etc/php.ini check_ok fi [ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf [ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm chmod 755 /etc/init.d/phpfpm chkconfig phpfpm on service phpfpm start check_ok break ;; 5.6) cd /usr/local/src/ [ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz tar zxvf php-5.6.6.tar.gz && cd php-5.6.6 for p in openssl-devel bzip2-devel libxml2-devel curl-devel libpng-devel libjpeg-devel freetype-devel libmcrypt-devel libtool-ltdl-devel perl-devel do myum $p done if ! grep -q `^php-fpm:` /etc/passwd then useradd -M -s /sbin/nologin php-fpm fi check_ok ./configure –prefix=/usr/local/php-fpm –with-config-file-path=/usr/local/php-fpm/etc –enable-fpm –with-fpm-user=php-fpm –with-fpm-group=php-fpm –with-mysql=/usr/local/mysql –with-mysql-sock=/tmp/mysql.sock –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv-dir –with-zlib-dir –with-mcrypt –enable-soap –enable-gd-native-ttf –enable-ftp –enable-mbstring –enable-exif –disable-ipv6 –with-pear –with-curl –with-openssl check_ok make && make install check_ok [ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php-fpm/etc/php.ini if /usr/local/php-fpm/bin/php -i |grep -iq `date.timezone => no value` then sed -i `/;date.timezone =$/adate.timezone = “Asia/Chongqing”` /usr/local/php-fpm/etc/php.ini check_ok fi [ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf check_ok [ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm chmod 755 /etc/init.d/phpfpm chkconfig phpfpm on service phpfpm start check_ok break ;; *) echo `only 1(5.4) or 2(5.6)` ;; esac done } ##function of install lnmp lnmp() { check_service mysqld check_service nginx check_service phpfpm echo “The lnmp done, Please use `http://your ip/index.php` to access.” } read -p “Please chose which type env you install, (lamp|lnmp)? ” t case $t in lamp) lamp ;; lnmp) lnmp ;; *) echo “Only `lamp` or `lnmp` your can input.” ;; esac |
[root@centos6 sbin]# sh lanmp.sh //執行指令碼
說明:執行指令碼後先選擇 lamp 還是 lnmp,然後再選擇 mysql,php 版本。附件裡面有個另外一個版本的指令碼,是先選擇 mysql,php 版本,然後再安裝 lamp 或者 lnmp。
lamp安裝成功會有如下提示:
LAMP done,Please use `http://your ip/index.php` to access. |
lnmp安裝成功會有如下提示:
The lnmp done, Please use `http://your ip/index.php` to access. |
若 lamp 安裝成功後想繼續安裝 lnmp,請先關閉httpd服務,因為 nginx 和 httpd 都使用80埠。
[root@centos6 sbin]# /usr/local/apache2/bin/apachectl stop |
本文轉自 M四月天 51CTO部落格,原文連結:http://blog.51cto.com/msiyuetian/1712968,如需轉載請自行聯絡原作者
相關文章
- 使用shell指令碼實現LANMP一鍵安裝指令碼
- Shell程式設計基礎-04-一鍵安裝和配置程式設計
- [SHELL]LNMP一鍵安裝指令碼設計(v1.0)LNMP指令碼
- shell指令碼一鍵安裝nginx指令碼Nginx
- [SHELL]LAMP一鍵安裝指令碼設計(v1,v2)LAMP指令碼
- 【Shell】使用shell列印選單,一鍵安裝Web應用Web
- Shell指令碼 | 一鍵解除安裝安卓App指令碼安卓APP
- Linux 程式設計之Shell程式設計(轉)Linux程式設計
- Linux之shell程式設計Linux程式設計
- shell指令碼:一鍵安裝LAMP、LNMP指令碼指令碼LAMPLNMP
- shell指令碼一鍵安裝nginx-1.18.0指令碼Nginx
- shell程式設計之免互動程式設計
- shell程式設計—簡介(一)程式設計
- shell程式設計(一)變數程式設計變數
- Linux Shell程式設計(2)——第一個shell程式Linux程式設計
- shell程式設計之條件語句程式設計
- shell程式設計程式設計
- Linux Shell程式設計(1)——shell程式設計簡介Linux程式設計
- Shell程式設計 --- Shell介紹程式設計
- 01 shell程式設計之變數定義程式設計變數
- 04 shell程式設計之迴圈語句程式設計
- 05 shell程式設計之正規表示式程式設計
- 02 shell程式設計之條件語句程式設計
- Linux的shell程式設計(一)(轉)Linux程式設計
- Windows Shell 程式設計Windows程式設計
- shell程式設計(轉)程式設計
- shell程式設計二程式設計
- shell程式設計五程式設計
- Shell程式設計-shell變數1程式設計變數
- Bourne Shell及shell程式設計(轉)程式設計
- zabbix一鍵安裝
- WDM驅動程式設計之編譯安裝篇 (轉)程式設計編譯
- Linux作業系統之Shell程式設計Linux作業系統程式設計
- 好程式設計師雲端計算教程分享Shell程式設計之for迴圈結構程式設計師
- Mandrake 宋體安裝shell程式(轉)
- Shell程式設計-02-Shell變數程式設計變數
- Linux Shell程式設計(27)——子shellLinux程式設計
- shell簡介之bash程式設計之引數說明(轉)程式設計