欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

LAMPLNMP自动化安装脚本

发布时间:2024/4/14 编程问答 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 LAMPLNMP自动化安装脚本 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

LAMP&LNMP自动化安装脚本

===================================

一、脚本的环境介绍

二、脚本的介绍

三、脚本的功能介绍

===================================

一、脚本的环境介绍

此脚本运行在RHEL 6.4版本上

运行此脚本需注意:

1)、主机需要能够上网,因为博主是搭建的搜狐的外网yum源,此yum源由两部分组成,一个是光盘里面的所有软件包,一个是epel源。

2)、需了解软件之间的相互依赖性。


二、脚本的介绍

脚本是由函数组成,每一个函数实现一个功能

1234567891011121314151617181920212223242526functioncreate_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自动化安装脚本的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。