LAMPLNMP自动化安装脚本
LAMP&LNMP自動化安裝腳本
===================================
一、腳本的環境介紹
二、腳本的介紹
三、腳本的功能介紹
===================================
一、腳本的環境介紹
此腳本運行在RHEL 6.4版本上
運行此腳本需注意:
1)、主機需要能夠上網,因為博主是搭建的搜狐的外網yum源,此yum源由兩部分組成,一個是光盤里面的所有軟件包,一個是epel源。
2)、需了解軟件之間的相互依賴性。
二、腳本的介紹
腳本是由函數組成,每一個函數實現一個功能
| 1234567891011121314151617181920212223242526 | functioncreate_yum #此函數是搭建sohu的yum倉庫functiondownload #此函數是下載全部所需的軟件包functioninstall_apache #此函數是安裝apache軟件包functionconfig_apache #此函數是修改apache的服務腳本和開啟apache服務 functioninstall_nginx #此函數是安裝nginx軟件包functioninstall_mysql #此函數是安裝mysql軟件包functionconfig_mysql #此函數是初始化mysql和開啟mysql的服務functioninstall_php #此函數是安裝php軟件包functionconfig_php #此函數提供php的配置文件functioninstall_php_fpm #此函數是安裝php-fpm軟件包提供fastcgi服務functionconfig_php_fpm #此函數是修改php-fpm的配置文件盒開啟php-fpm的服務functioninstall_xcache #此函數是安裝為php代碼加速的軟件包functioninstall_memcache #此函數是安裝連接memcached的軟件包functioninstall_memcached #此函數是安裝memcached軟件包functioninstall_lamp #此函數里面只包含了apache,mysql,php的函數functionconfig_lampfunctioninstall_lammp #此函數里面只包含了apache,mysql,memcached,php的函數functionconfig_lammpfunctioninstall_lnmp #此函數里面只包含了nginx,mysql,php的函數functionconfig_lnmpfunctioninstall_lnmmp #此函數里面只包含了nginx,mysql,memcached,php的函數functionconfig_lnmmp |
如果各位博友覺得配置文件的路徑存放數據的路徑與各位博友所要求的結果不一樣,那請各位博友只需小小的自行修改一下
三、腳本的功能介紹
1)、支持某臺機器單獨安裝某一個軟件,如apache、nginx、mysql、php-fpm,memcached
2)、支持某臺機器直接安裝lamp、lnmp、lammp、lnmmp架構
3)、如果想一個一個的安裝lamp(lnmp)架構,請注意安裝順序:apache(nginx)-->
mysql-->php
4)、php與php-fpm其實都是安裝php源碼軟件包,但是提供的功能不一樣
如果你的apache與php安裝在不同的機器上,那么php的那臺主機安裝的是
php-fpm;
如果你的php與mysql安裝在不同的機器上,那么php的那臺主機也是安裝
php-fpm;
php-fpm與memcached安裝在不同的機器上,那么php-fpm的那臺主機必須安裝memcache,用于連接memcached。
5)、安裝完每個腳本后,會把源碼包生成的文件與系統能識別的頭文件、庫文件、二進制中
6)、會為服務提供system V 腳本文件
7)、會自行的把服務開啟,并加入到開機自動啟動的服務列表中
整個腳本
| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 | #!/bin/bash#discripte:frist,you linux server must be surf Internet because we use http://mirrors.sohu.com/ yum source and epel sourcefunctioncreate_yum {dir=/etc/yum.repos.d/mv$dir/*.repo /tmpcat>> $dir/sohu.repo <<EOF[centos]name=sohu-centosbaseurl=http://mirrors.sohu.com/centos/\$releasever/os/\$basearchgpgcheck=1enable=0gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-6[epel]name=sohu-epelbaseurl=http://mirrors.sohu.com/fedora-epel/\$releasever/\$basearch/enable=1gpgcheck=0EOFyum clean all &>/dev/null}functiondownload {yum -y installwgetcd/rootecho-e "\033[32m=========download about web server source package==========\033[0m"wget http://mirror.esocc.com/apache/apr/apr-1.4.6.tar.bz2wget http://mirror.esocc.com/apache/apr/apr-util-1.5.2.tar.bz2wget http://mirror.esocc.com/apache/httpd/httpd-2.4.6.tar.bz2wget http://nginx.org/download/nginx-1.4.2.tar.gzecho-e "\033[32m=========download about php or php-fpm soure package========\033[0m"wget http://xcache.lighttpd.net/pub/Releases/3.0.3/xcache-3.0.3.tar.bz2wget http://pecl.php.net/get/memcache-2.2.7.tgzwget http://downloads.php.net/stas/php-5.4.19.tar.bz2echo-e "\033[32m======download about memcached source package========\033[0m"wget http://nchc.dl.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.21-stable.tar.gzwget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gzecho-e "\033[32m======download about mysql source package=========\033[0m"wget http://mysql.llarian.net/Downloads/MySQL-5.5/mysql-5.5.33.tar.gz}functioninstall_apache {cd/rootyum -y installpcre-develtarxf apr-1.4.6.tar.bz2tarxf apr-util-1.5.2.tar.bz2tarxf httpd-2.4.6.tar.bz2cd/root/apr-1.4.6./configure--prefix=/usr/local/apr&& make&& makeinstallecho-e "\033[32m=========apr is ok========\033[0m"cd/root/apr-util-1.5.2./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr&& make&& makeinstallecho-e "\033[32m=========apr-util is ok========\033[0m"cd/root/httpd-2.4.6./configure--prefix=/usr/local/apache--enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib \--with-pcre --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util--enable-modules=most \--enable-mpms-shared=all --with-mpm=event && make&& makeinstallecho-e "\033[32m=========httpd is ok========\033[0m"}functionconfig_apache {echo-e "\033[32m frist,Associated system path \033[0m"echo"PATH=/usr/local/apache/bin/:$PATH">/etc/profile.d/httpd.shsource/etc/profile.d/httpd.shln-sv /usr/local/apache/include//usr/include/httpdecho-e "\033[32m second,Modify configuration files and provided systemV scripts \033[0m"IP=`ifconfig| grep"inet addr"| grep-v"127.0.0.1"| awk-F: '{print $2}'| cut-d' '-f1`cp/root/httpd-2.4.6/build/rpm/httpd.init /etc/rc.d/init.d/httpdsed-i '/httpd/s/usr\/sbin\/httpd/usr\/local\/apache\/bin\/httpd/g'/etc/rc.d/init.d/httpdsed-i '/^httpd/a\prog=httpd'/etc/rc.d/init.d/httpdsed-i '/^pidfile/s/var\/run/usr\/local\/apache\/logs/g'/etc/rc.d/init.d/httpdsed-i 's/etc\/httpd\/conf\/httpd.conf/usr\/local\/apache\/conf\/httpd.conf/g'/etc/rc.d/init.d/httpdsed-i '$a ServerName '$IP':80'/usr/local/apache/conf/httpd.confchkconfig --add httpdchkconfig --level 35 httpd onservice httpd start}functioninstall_nginx {cd/rootyum -y installpcre-develtarxf nginx-1.4.2.tar.gzgroupadd nginxuseradd-r -g nginx nginxcd/root/nginx-1.4.2./configure\--prefix=/usr\--sbin-path=/usr/sbin/nginx\--conf-path=/etc/nginx/nginx.conf \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--pid-path=/var/run/nginx/nginx.pid \--lock-path=/var/lock/nginx.lock \--user=nginx \--group=nginx \--with-http_ssl_module \--with-http_flv_module \--with-http_stub_status_module \--with-http_gzip_static_module \--http-client-body-temp-path=/var/tmp/nginx/client/\--http-proxy-temp-path=/var/tmp/nginx/proxy/\--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/\--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\--http-scgi-temp-path=/var/tmp/nginx/scgi\--with-pcre && make&& makeinstallecho-e "\033[32m=========nginx is ok========\033[0m"}functioninstall_mysql {cd/rootyum -y installcmake bisonuseradd-r mysqltarxf mysql-5.5.33.tar.gzcd/root/mysql-5.5.33cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/mydata/data-DSYSCONFDIR=/etc\-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_cimake&& makeinstallecho-e "\033[32m=========mysqld is ok========\033[0m"}functionconfig_mysql {echo-e "\033[32m frist,Associated system path,and Initialization database \033[0m"cp/usr/local/mysql/support-files/my-large.cnf /etc/my.cnfcp/usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqldchown-R root.mysql /usr/local/mysql/mkdir-pv /mydata/datachown-R mysql:mysql /mydata/data/sed-i '/thread_concurrency/a\ datadir = /mydata/data'/etc/my.cnfsed-i '/datadir/a\ innodb_file_per_table = 1'/etc/my.cnf/usr/local/mysql/scripts/mysql_install_db--user=mysql --datadir=/mydata/data/--basedir=/usr/local/mysqlservice mysqld startecho"PATH=/usr/local/mysql/bin:$PATH">/etc/profile.d/mysqld.shsource/etc/profile.d/mysqld.shecho"/usr/local/mysql/lib">/etc/ld.so.conf.d/mysqld.confldconfig -v| grepmysqlln-sv /usr/local/mysql/include//usr/include/mysqldchkconfig --add mysqldchkconfig --level 35 mysqld on}functioninstall_php {yum -y installlibxml2-devel bzip2-devel curl-devel libmcrypt-devel mhash-develtarxf php-5.4.19.tar.bz2cd/root/php-5.4.19./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql--with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config\--enable-mbstring --with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib --with-libxml-dir=/usr\--enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs--with-mcrypt --with-curl \--with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-ztsmake&& makeinstallecho-e "\033[32m=========php is ok========\033[0m"}functionconfig_php {cp/root/php-5.4.19/php.ini-production /etc/php.ini}functioninstall_php_fpm {yum -y installlibxml2-devel bzip2-devel curl-devel libmcrypt-devel mhash-develtarxf php-5.4.19.tar.bz2cd/root/php-5.4.19./configure--prefix=/usr/local/php--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd \--with-openssl --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir--with-jpeg-dir--with-png-dir\--with-zlib-dir--with-libxml-dir=/usr--enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc\--with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --enable-maintainer-zts --enable-fpm && make&& makeinstallecho-e "\033[32m=========php-fpm is ok========\033[0m"}functionconfig_php_fpm {echo-e "\033[32m frist,Associated system path \033[0m"IP2=`ifconfig| grep"inet addr"| grep-v"127.0.0.1"| awk-F: '{print $2}'| cut-d' '-f1`cp/root/php-5.4.19/php.ini-production /etc/php.iniecho"PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH">/etc/profile.d/php-fpm.shsource/etc/profile.d/php-fpm.shecho-e "\033[32m second,Modify configuration files and provided systemV scripts \033[0m"mv/usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confsed-i 's/127\.0\.0\.1/'$IP2'/g'/usr/local/php/etc/php-fpm.confcp/root/php-5.4.19/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpmchmod+x /etc/rc.d/init.d/php-fpmservice php-fpm startchkconfig --add php-fpmchkconfig --level 35 php-fpm on}functioninstall_xcache {cd/roottarxf xcache-3.0.3.tar.bz2if[ -d /usr/local/php];thencd/root/xcache-3.0.3/usr/local/php/bin/phpize./configure--enable-xcache --with-php-config=/usr/local/php/bin/php-configmake&& makeinstallelseinstall_php_fpmcd/root/xcache-3.0.3/usr/local/php/bin/phpize./configure--enable-xcache --with-php-config=/usr/local/php/bin/php-configmake&& makeinstallecho-e "\033[32m=========xcache is ok========\033[0m"fi}functioninstall_memcache {cd/roottarxf memcache-2.2.7.tgzif[ -d /usr/local/php];thencd/root/memcache-2.2.7/usr/local/php/bin/phpize./configure--with-php-config=/usr/local/php/bin/php-config--enable-memcache && make&&makeinstallelseinstall_php_fpmcd/root/memcache-2.2.7/usr/local/php/bin/phpize./configure--with-php-config=/usr/local/php/bin/php-config--enable-memcache && make&&makeinstallecho-e "\033[32m=========memcache is ok========\033[0m"fi}functioninstall_memcached {cd/roottarxf libevent-2.0.21-stable.tar.gztarxf memcached-1.4.15.tar.gzcd/root/libevent-2.0.21-stable./configure--prefix=/usr/local/libevent&& make&& makeinstallecho-e "\033[32m=========libevent is ok========\033[0m"cd/usr/local/libevent/echo"/usr/local/libevent/lib">/etc/ld.so.conf.d/libevent.confldconfig -v| greplibeventln-sv /usr/local/libevent//usr/include/libeventcd/root/memcached-1.4.15./configure--prefix=/usr/local/memcached--with-libevent=/usr/local/libevent/make&& makeinstallecho-e "\033[32m=========memcached is ok========\033[0m"}functioninstall_lamp {install_apacheinstall_mysqlinstall_phpinstall_xcache}functionconfig_lamp {config_apacheconfig_mysqlconfig_php}functioninstall_lnmp {install_nginxinstall_mysqlinstall_phpinstall_xcache}functionconfig_lnmp {config_mysqlconfig_php}functioninstall_lammp {install_apacheinstall_mysqlinstall_phpinstall_xcacheinstall_memcacheinstall_memcached}functionconfig_lammp {config_apacheconfig_mysqlconfig_phpconfig_php_fpm}functioninstall_lnmmp {install_nginxinstall_mysqlinstall_phpinstall_xcacheinstall_memcacheinstall_memcached}functionconfig_lnmmp {config_mysqlconfig_phpconfig_php_fpm}echo-e "\033[32m====make sure yum is ok=========\033[0m"#create_yumecho-e "\033[32m====now,download all package====\033[0m"#downloadecho-e "\033[32m====install development packages====\033[0m"#yum -y groupinstall "Development tools" "Server Platform Development"echo-e "\033[32m=========you can choice you need install package==========\033[0m"cat<<EOFapache|A) installapache sourcepackage.nginx|N) installnginx sourcepackage.mysql|M) installmysql sourcepackage.php|P) installphp sourcepackage.php-fpm|PF) installphp-fpm sourcepackage.xcache|X) installxcahe sourcepackage.memcache|ME) installmemcache sourcepackage.memcached|MD) installmemcached sourcepackage.lamp) installlamp sourcepackage.lammp) installlammp sourcepackage.lnmp) installlnmp sourcepackage.lnmmp) installlnmmp sourcepackage.q|Q) quitEOFread-p "Please choose to install: "Choiceecho-e "\033[32m=====start install $Choice====\033[0m"until[ $Choice == q -o $Choice == Q ];docase$Choice inapache|A) install_apacheconfig_apache ;;nginx|N)install_nginx ;;mysql|M) install_mysqlconfig_mysql ;;php|P)install_phpconfig_php ;;php-fpm|PF)install_php_fpmconfig_php_fpm ;;xcache|X) install_xcache ;;memcache|ME) install_memcache ;;memcached|MD)install_memcached ;;lamp)install_lampconfig_lamp ;;lammp) install_lammpconfig_lammp ;;lnmp) install_lnmpconfig_lnmp ;;lnmmp) install_lnmmpconfig_lnmmp ;;q|Q) breakesacread-p "Have any choice agin, if you no,q|Q is quit: "Choicedone |
這個腳本和nginx systemV,memcached system V的腳本以附件的形式上傳了
缺陷:
1)、沒能為nginx提供自動化system V腳本,但是nginx的system V腳本我會以附件的方式上傳,各位博友需要 vim /etc/rc.d/init.d/nginx 然后copy我提供的system V腳本然后添加權限,就可以service nginx start了
2)、也沒能為memcached提供自動化system V腳本,但是memcached的system V腳本會以附件方式上傳,各位博友需要 vim /etc/rc.d/init.d/memcached 然后copy我提供的system V腳本然后添加權限,就可以service memcached start了
轉自http://litaotao.blog.51cto.com/6224470/1299117
轉載于:https://blog.51cto.com/jiangkun08/1300328
總結
以上是生活随笔為你收集整理的LAMPLNMP自动化安装脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java中如何将非整数保留到小数点后指定
- 下一篇: linux 设备驱动程序开发 第3版_C