shell脚本:一键安装LAMP、LNMP脚本
生活随笔
收集整理的這篇文章主要介紹了
shell脚本:一键安装LAMP、LNMP脚本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
歷時三天邊寫邊測試,終于完成目前最長代碼的腳本,總共253行,在2臺機器安裝LAMP,LNMP都順利通過,腳本可做為生產環境使用。
腳本需要注意的地方:
1:腳本適用于centos系統6.5以上,干凈系統;如安裝過其他環境需要修改腳本內容;
2:腳本適用于:apache 2.4.x 版本;mysql5.5.x以上版本;php5.5.x以上版本;
3:mysql 、php、 apache、 nginx 安裝包事先要下載到/usr/local/src目錄下,如名字不對需要更改腳本里的軟件包名稱;
腳本安裝的版本為以下,如需其他名稱,請自行修改軟件安裝包名稱和對應的目錄名即可;
httpd-2.4.7.tar.gz 、mysql-5.6.25.tar.gz 、nginx-1.6.2.tar.gz、 php-5.6.8.tar.gz
4:腳本沒有增加判斷,設定的環境為干凈系統;
腳本內容如下:
#!/bin/bash #written?by?mofansheng?@2015-11-06 #one?key?install?LAMP?or?LNMP?scripts;?apply?to?apache?2.4.x,mysql?5.6.x,nginx?1.6.x;.?/etc/init.d/functions#check?the?results?of?the?command?executionfunction?check_ok(){if?[?$??-eq?0?]thencontinueelseecho?"please?check?error"exitfi }function?yum_update(){#set?yum?reposecho?"===update?yum?repos,it?will?take?serval?mintinues==="yum?install?wget?-ymv?/etc/yum.repos.d/CentOS-Base.repo?/etc/yum.repos.d/CentOS-Base.repo.bakwget?-O?/etc/yum.repos.d/CentOS-Base.repo?http://mirrors.aliyun.com/repo/Centos-6.repo?&>/dev/nullwget?-O?/etc/yum.repos.d/epel.repo?http://mirrors.aliyun.com/repo/epel-6.repo?&>/dev/nullyum?clean?all?&>/dev/nullyum?makecache?&>/dev/nullcheck_okaction??"yum?repos?update?is?ok"?/bin/true }function?yum_depend(){#install?dependencies?packagesyum?install?wget?gcc?gcc-c++?make?re2c?curl?curl-devel?libxml2?libxml2-devel?libjpeg?libjpeg-devel?libpng?libpng-devel?libmcrypt?libmcrypt-devel?zlib?zlib-devel?openssl?openssl-devel?freetype?freetype-devel?gd?gd-devel?perl?perl-devel?ncurses?ncurses-devel?bison?bison-devel?libtool?gettext?gettext-devel?cmake?bzip2?bzip2-devel?pcre?pcre-devel?-y }function?install_mysql(){echo?"mysql5.6.25?will?be?installed,please?be?patient"cd?/usr/local/srctar?-zxf?mysql-5.6.25.tar.gzcd?mysql-5.6.25cmake?-DCMAKE_INSTALL_PREFIX=/usr/local/mysql?-DMYSQL_DATADIR=/data/mysql?-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock?-DSYSCONFDIR=/etc?-DWITH_MYISAM_STORAGE_ENGINE=1?-DWITH_ARCHIVE_STORAGE_ENGINE=1?-DWITH_BLACKHOLE_STORAGE_ENGINE=1?-DWITH_INNOBASE_STORAGE_ENGINE=1?-DWITH_MEMORY_STORAGE_ENGINE=1?-DWITH_READLINE=1?-DMYSQL_TCP_PORT=3306?-DENABLED_LOCAL_INFILE=1?-DWITH_PARTITION_STORAGE_ENGINE=1?-DEXTRA_CHARSETS=all?-DDEFAULT_CHARSET=utf8?-DDEFAULT_COLLATION=utf8_general_cicheck_okmake?&&?make?installcheck_okuseradd?-M?-s?/sbin/nologin?mysqlmkdir?-p?/data/mysqlchown?-R?mysql:mysql?/data/mysql/chown?-R?mysql:mysql?/usr/local/mysql/check_okcd?/usr/local/mysql/scripts/./mysql_install_db?--basedir=/usr/local/mysql/?--datadir=/data/mysql/?--user=mysqlcheck_ok/bin/cp?/usr/local/mysql/my.cnf?/etc/my.cnfsed?-i?'/^\[mysqld\]$/a\user?=?mysql\ndatadir?=?/data/mysql\ndefault_storage_engine?=?InnoDB\n'?/etc/my.cnfcheck_okcp?/usr/local/mysql/support-files/mysql.server?/etc/init.d/mysqldsed?-i?'s#^datadir=#datadir=/data/mysql#'?/etc/init.d/mysqldsed?-i?'s#^basedir=#basedir=/usr/local/mysql#'?/etc/init.d/mysqldservice?mysqld?startchkconfig?--add?mysqldchkconfig?mysqld?oncheck_okiptables?-A?INPUT?-m?state?--state?NEW?-m?tcp?-p?tcp?--dport?3306?-j?ACCEPT/etc/init.d/iptables?savecheck_okecho?"export?PATH=$PATH:/usr/local/mysql/bin"?>>/etc/profilesource?/etc/profilecheck_ok }function?install_apache(){echo?"apache2.4.7?will?be?installed,please?be?patient"cd?/usr/local/srcwget?http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gzwget?http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gzcheck_oktar?zxf?apr-1.5.2.tar.gzcd?apr-1.5.2./configure?--prefix=/usr/local/aprcheck_okmake?&&?make?installcheck_okcd?/usr/local/srctar?zxf?apr-util-1.5.4.tar.gzcd?apr-util-1.5.4./configure?--prefix=/usr/local/apr-util?--with-apr=/usr/local/aprcheck_okmake?&&?make?installcheck_okcd?/usr/local/srctar?zxf?httpd-2.4.7.tar.gz/bin/cp?-r?apr-1.5.2?/usr/local/src/httpd-2.4.7/srclib/apr/bin/cp?-r?apr-util-1.5.4?/usr/local/src/httpd-2.4.7/srclib/apr-utilcd?httpd-2.4.7./configure?--prefix=/usr/local/apache2?--with-apr=/usr/local/apr?--with-apr-util=/usr/local/apr-util/?--with-pcre?--enable-mods-shared=most?--enable-so?--with-included-aprcheck_okmake?&&?make?installcheck_okecho?"export?PATH=$PATH:/usr/local/apache2/bin"?>>/etc/profilesource?/etc/profilecheck_okiptables?-A?INPUT?-m?state?--state?NEW?-m?tcp?-p?tcp?--dport?80?-j?ACCEPT/etc/init.d/iptables?savecheck_ok/usr/local/apache2/bin/apachectlcheck_ok }function?install_php(){echo?"php5.6.8?will?be?installed,please?be?patient"cd?/usr/local/srctar?zxf?php-5.6.8.tar.gzcd?php-5.6.8./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-ipv6check_okmake?&&?make?installcheck_okcp?/usr/local/src/php-5.6.8/php.ini-production?/usr/local/php/etc/php.inised?-i?'s#^;date.timezone?=#date.timezone=Asia/Shanghai#'?/usr/local/php/etc/php.inicheck_ok}function?set_lamp(){sed?-i?'/AddType?application\/x-gzip?.gz?.tgz/a\????AddType?application/x-httpd-php?.php\n'?/usr/local/apache2/conf/httpd.confsed?-i?'s#index.html#index.html?index.php#'?/usr/local/apache2/conf/httpd.confsed?-i?'/#ServerName?www.example.com:80/a\ServerName?localhost:80\n'?/usr/local/apache2/conf/httpd.confcheck_ok cat?>>/usr/local/apache2/htdocs/test.php<<EOF <?php echo?"PHP?is?OK\n"; ?> EOF/usr/local/apache2/bin/apachectl?gracefulcheck_okcurl?localhost/test.phpcheck_okaction?"LAMP?is?install?success"?/bin/true }function?install_phpfpm(){echo?"php5.6.8?will?be?installed,please?be?patient"useradd?-s?/sbin/nologin?php-fpmcd?/usr/local/srctar?zxf?php-5.6.8.tar.gzcd?php-5.6.8./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=mysqlnd??--with-pdo-mysql=mysqlnd?--with-mysqli=mysqlnd?--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-exif?--disable-ipv6?--with-pear?--with-curl?--enable-bcmath?--enable-mbstring?--enable-sockets?--with-gettextcheck_okmake?&&?make?installcheck_okcp?/usr/local/src/php-5.6.8/php.ini-production?/usr/local/php-fpm/etc/php.inised?-i?'s#^;date.timezone?=#date.timezone=Asia/Shanghai#'?/usr/local/php-fpm/etc/php.inicd?/usr/local/php-fpm/etc/mv?php-fpm.conf.default?php-fpm.confcheck_okcp?/usr/local/src/php-5.6.8/sapi/fpm/init.d.php-fpm?/etc/init.d/php-fpmchmod?755?/etc/init.d/php-fpmchkconfig?--add?php-fpmchkconfig?php-fpm?onservice?php-fpm?startcheck_ok }function?install_nginx(){echo?"nginx1.6.2?will?be?installed,please?be?patient"cd?/usr/local/srctar?zxf?nginx-1.6.2.tar.gzcd?nginx-1.6.2./configure?--prefix=/usr/local/nginx?--with-pcre?--with-http_stub_status_module?--with-http_ssl_module?--with-http_gzip_static_modulecheck_okmake?&&?make?installcheck_ok/usr/local/nginx/sbin/nginxcheck_ok }function?set_lnmp(){sed?-i?'56a\location?~?\.php$?{\n\????root???????????html;\n\????fastcgi_pass???127.0.0.1:9000;\n\????fastcgi_index??index.php;\n\????fastcgi_param??SCRIPT_FILENAME??/usr/local/nginx/html$fastcgi_script_name;\n\????include????????fastcgi_params;\n\}\n'?/usr/local/nginx/conf/nginx.conf/usr/local/nginx/sbin/nginx?-s?reloadcheck_okecho?-e?'<?php\n?echo?"nginx?and?PHP?is?OK";\n?>\n'?>/usr/local/nginx/html/index.phpcurl?localhost/index.phpcheck_okaction?"LNMP?is?install?success"?/bin/true }function?install_lamp(){echo?"apache?2.4.7?mysql?5.6.24?php5.6.8?will?be?installed"echo?"===update?yum?repos?and?install?dependecies?packages,it?will?take?serval?mintinues==="yum_updatecheck_okyum_dependcheck_okinstall_mysqlcheck_okinstall_apachecheck_okinstall_phpcheck_okset_lamp }function?install_lnmp(){echo?"nginx1.6.2?mysql?5.6.24?php5.6.8?will?be?installed"echo?"===update?yum?repos?and?install?dependecies?packages,it?will?take?serval?mintinues==="yum_updatecheck_okyum_dependcheck_okinstall_mysqlcheck_okinstall_phpfpmcheck_okinstall_nginxcheck_okset_lnmp }cat?<<EOF1:[install?LAMP]2:[install?LNMP]3:[exit] EOF read?-t?10?-p?"please?input?the?num?you?want:"?input case?${input}?in1)install_lamp;;2)install_lnmp;;3)exit;;*)printf?"You?must?input?only?in?{1|2|3}\n" esac總結
以上是生活随笔為你收集整理的shell脚本:一键安装LAMP、LNMP脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java重载和重载的区别
- 下一篇: VC++ error C2248: “