LNAMP第二版(nginx 1.2.0+apache 2.4.2+php 5.4)

apache官方宣称apache2.4在性能上提升了很多,所以就把第一版的LNAMP进行了升级,nginx、apache、mysql、php全部采用最新版本,php5.4有很多扩展没有跟进,这个是比较大的遗憾,比如:ZendGuardLoade、accelerator、Suhosin

一、系统初始化

 
 
  1. chmod+x/opt/init_system.sh

  2. /opt/init_system.sh

二、更新组件
#yum源修改

 
 
  1. cd/etc/yum.repos.d/

  2. mvCentOS-Base.repoCentOS-Base.repo.backup

  3. wgethttp://mirrors.163.com/.help/CentOS5-Base-163.repo

  4. yummakecache

 
 
  1. yum-yinstallgccgcc-c++bisonpatchunzipmlocateflexwgetautomakeautoconfgdcppgettextreadline-devellibjpeg\

  2. libjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglibcglibc-develglib2\

  3. glib2-develbzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-devellibidnlibidn-developenldap\

  4. openldap-developenldap-clientsopenldap-serversnss_ldapexpat-devellibtoollibtool-ltdl-develbison

三、LANMP安装配置(nginx、apache整合)
#===============downloadsoftware=============#
cd/opt
wgethttp://nginx.org/download/nginx-1.2.0.tar.gz
#2.4.2分成两个包,把apr单独做成一个dep包
wgethttp://www.apache.org/dist/httpd/httpd-2.4.2.tar.bz2
wgethttp://mirror.bjtu.edu.cn/apache/httpd/httpd-2.4.2-deps.tar.bz2
wgethttp://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
wgethttp://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.23.tar.gz/from/http://mysql.he.net/
#rpaf模块,该模块用于apache做后端时获取访客真实的IP
wgethttp://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
#字符转换库libiconv
wgethttp://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wgethttp://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download
wgethttp://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
wgethttp://cn.php.net/get/php-5.4.0.tar.bz2/from/this/mirror
#php5-mail-header.patch为php被丁,有助于防止邮件发送被滥用
wgethttp://www.lancs.ac.uk/~steveb/patches/php-mail-header-patch/php5-mail-header.patch
#PHP的memcache扩展
wgethttp://pecl.php.net/get/memcache-3.0.6.tgz
wgethttps://launchpadlibrarian.net/103487645/libmemcached-1.0.2.tar.gz
wgethttp://pecl.php.net/get/memcached-2.0.1.tgz
#将eaccelerator换成xcache(xcache2.0支持php5.4)
wgethttp://xcache.lighttpd.net/pub/Releases/2.0.0/xcache-2.0.0.tar.gz
wgethttp://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
#ImageMagick完美代替GB类库处理图像
wgetftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.7.6-7.tar.bz2
wgethttp://pecl.php.net/get/imagick-3.1.0RC1.tgz
wgethttp://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.bz2
wgethttp://sourceforge.net/projects/pcre/files/pcre/8.30/pcre-8.30.tar.bz2/download
#memcached缓存
wgethttp://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
wgethttps://github.com/downloads/libevent/libevent/libevent-2.0.18-stable.tar.gz
#Tcmalloc优化nginx、mysql
#64位操作系统请先安装libunwind库,32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API
wgethttp://mirror.yongbok.net/nongnu/libunwind/libunwind-1.0.1.tar.gz
wgethttp://gperftools.googlecode.com/files/gperftools-2.0.tar.gz

#==============Installmysql5.5.23==================#
#使用Tcmalloc优化nginx、mysql
#64位操作系统请先安装libunwind库,32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API

 
 
  1. cd/opt

  2. tar-zxvflibunwind-1.0.1.tar.gz

  3. cdlibunwind-1.0.1

  4. ./configure

  5. make;makeinstall

  6. cd../

  7. tar-zxvfgperftools-2.0.tar.gz

  8. cdgperftools-2.0

  9. ./configure

  10. make;makeinstall

  11. echo"/usr/local/lib">/etc/ld.so.conf.d/usr_local_lib.conf

  12. /sbin/ldconfig

  13. cd../

  14. tar-zxvfcmake-2.8.8.tar.gz

  15. cdcmake-2.8.8

  16. ./bootstrap

  17. gmake

  18. gmakeinstall

  19. cd../

  20. /usr/sbin/groupaddmysql

  21. /usr/sbin/useradd-gmysqlmysql-s/sbin/nologin

  22. mkdir-p/data/mysql/{data,binlog,relaylog,mysql}

  23. chown-Rmysql:mysql/data/mysql

  24. cd/opt

  25. tarzxvfmysql-5.5.23.tar.gz

  26. cdmysql-5.5.23/

  27. rm-rfCMakeCache.txt

  28. cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\

  29. -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock\

  30. -DDEFAULT_CHARSET=utf8\

  31. -DDEFAULT_COLLATION=utf8_general_ci\

  32. -DEXTRA_CHARSETS=all\

  33. -DWITH_MYISAM_STORAGE_ENGINE=1\

  34. -DWITH_INNOBASE_STORAGE_ENGINE=1\

  35. -DWITH_READLINE=1\

  36. -DENABLED_LOCAL_INFILE=1\

  37. -DMYSQL_DATADIR=/data/mysql/data\

  38. -DMYSQL_TCP_PORT=3306

  39. make;makeinstall

  40. chmod+w/usr/local/mysql

  41. chown-Rmysql:mysql/usr/local/mysql

  42. ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/libmysqlclient.so.18

#编辑mysql配置文件

 
 
  1. cat>>/etc/my.cnf<<EOF

  2. [client]

  3. port=3306

  4. socket=/data/mysql/mysql.sock

  5. [mysqld]

  6. character_set_server=utf8

  7. collation-server=utf8_general_ci

  8. replicate-ignore-db=mysql

  9. replicate-ignore-db=test

  10. replicate-ignore-db=information_schema

  11. user=mysql

  12. port=3306

  13. socket=/data/mysql/mysql.sock

  14. basedir=/usr/local/mysql

  15. datadir=/data/mysql/data

  16. log-error=/data/mysql/mysql_error.log

  17. pid-file=/data/mysql/mysql.pid

  18. open_files_limit=10240

  19. back_log=600

  20. max_connections=5000

  21. max_connect_errors=6000

  22. table_cache=512

  23. external-locking=FALSE

  24. max_allowed_packet=32M

  25. sort_buffer_size=6M

  26. join_buffer_size=8M

  27. thread_cache_size=300

  28. thread_concurrency=8

  29. query_cache_size=512M

  30. query_cache_limit=2M

  31. query_cache_min_res_unit=2k

  32. default-storage-engine=MyISAM

  33. thread_stack=256K

  34. transaction_isolation=READ-COMMITTED

  35. tmp_table_size=256M

  36. max_heap_table_size=256M

  37. long_query_time=3

  38. log-slave-updates

  39. log-bin=/data/mysql/binlog/binlog

  40. binlog_cache_size=4M

  41. binlog_format=MIXED

  42. max_binlog_cache_size=8M

  43. max_binlog_size=100M

  44. relay-log-index=/data/mysql/relaylog/relaylog

  45. relay-log-info-file=/data/mysql/relaylog/relaylog

  46. relay-log=/data/mysql/relaylog/relaylog

  47. expire_logs_days=30

  48. key_buffer_size=384M

  49. read_buffer_size=4M

  50. read_rnd_buffer_size=16M

  51. bulk_insert_buffer_size=64M

  52. myisam_sort_buffer_size=128M

  53. myisam_max_sort_file_size=10G

  54. myisam_repair_threads=1

  55. myisam_recover

  56. interactive_timeout=120

  57. wait_timeout=120

  58. skip_external_locking

  59. skip-name-resolve

  60. #master-connect-retry=10

  61. slave-skip-errors=1032,1062,126,1114,1146,1048,1396

  62. #master-host=192.168.1.2

  63. #master-user=username

  64. #master-password=password

  65. #master-port=3306

  66. server-id=1

  67. skip-innodb

  68. #log-slow-queries=/data/mysql/slow.log

  69. #long_query_time=10

  70. [mysqldump]

  71. quick

  72. max_allowed_packet=32M

  73. EOF

#初始化mysql

 
 
  1. /usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql--datadir=/data/mysql/data--user=mysql

#利用TCMalloc提高mysql在高并发下的性能
vi/usr/local/mysql/bin/mysqld_safe

#在#executingmysqld_safe的下一行,加上:
exportLD_PRELOAD=/usr/local/lib/libtcmalloc.so

#或者通sed添加
sed-i'/#executingmysqld_safe/a\exportLD_PRELOAD=/usr/local/lib/libtcmalloc.so'/usr/local/mysql/bin/mysqld_safe

#设置mysql启动文件
cpsupport-files/mysql.server/etc/rc.d/init.d/mysqld
vi/etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql/data

#或者通sed修改
sed-i'46s#basedir=#basedir=/usr/local/mysql#'/etc/rc.d/init.d/mysqld
sed-i'47s#datadir=#datadir=/data/mysql/data#'/etc/rc.d/init.d/mysqld

chmod700/etc/rc.d/init.d/mysqld
/etc/rc.d/init.d/mysqldstart

#使用lsof命令查看tcmalloc是否起效(如下图)
/usr/sbin/lsof-n|greptcmalloc

151250782.png

#设置mysql开机启动
/sbin/chkconfig--addmysqld
/sbin/chkconfig--level2345mysqldon
ln-s/usr/local/mysql/bin/mysql/sbin/mysql
ln-s/usr/local/mysql/bin/mysqladmin/sbin/mysqladmin

#设置root密码(753951)
/sbin/mysqladmin-urootpassword753951

#配置库文件搜索路径
echo"/usr/local/mysql/lib/mysql">>/etc/ld.so.conf
/sbin/ldconfig

#添加/usr/local/mysql/bin到环境变量PATH中
echo"exportPATH=$PATH:/usr/local/mysql/bin">>/etc/profile
source/etc/profile

#添加mysql管理帐户
#mysql-hlocalhost-uroot-p753951
#msqyl>usemysql;
#msqyl>grantallon*.*to'kerry'@'192.168.9.100'identifiedby'852741';
#msqyl>flushprivileges;
#msqyl>exit;

#=================Installapache2.4.2==============#

 
 
  1. /usr/sbin/groupaddwww

  2. /usr/sbin/useradd-gwwwwww-s/sbin/nologin

  3. mkdir-p/data/www/{kerry,king}

  4. mkdir-p/data/logs/{kerry,king}

  5. chown-Rwww:www/data/www

  6. chown-Rwww:www/data/logs

  7. cd/opt

  8. wgethttp://ftp.gnu.org/gnu/libtool/libtool-2.4.2.tar.gz

  9. rpm-elibtool-1.5.22-7.el5_4

  10. tar-zxvflibtool-2.4.2.tar.gz

  11. cdlibtool-2.4.2

  12. ./configure

  13. make;makeinstall

  14. tar-jxvfpcre-8.30.tar.bz2

  15. cdpcre-8.30

  16. ./configure--prefix=/usr/local/pcre

  17. make;makeinstall

  18. cd../

  19. tar-jxvfhttpd-2.4.2.tar.bz2

  20. tar-jxvfhttpd-2.4.2-deps.tar.bz2

  21. cdhttpd-2.4.2

#隐藏apache版本信息

 
 
  1. sed-i's/#defineAP_SERVER_BASEPRODUCT"Apache"/#defineAP_SERVER_BASEPRODUCT"Microsoft-IIS5.0"/'include/ap_release.h

  2. sed-i's/#definePLATFORM"Unix"/#definePLATFORM"win32"/'os/unix/os.h

 
 
  1. ./configure--prefix=/usr/local/apache\

  2. --enable-deflate\

  3. --enable-headers\

  4. --enable-mime-magic\

  5. --enable-proxy\

  6. --enable-ssl\

  7. --enable-so\

  8. --enable-rewrite\

  9. --enable-suexec\

  10. --with-suexec-bin=/usr/sbin/suexec\

  11. --with-suexec-caller=www\

  12. --with-pcre=/usr/local/pcre/bin/pcre-config\

  13. --with-mpm=prefork\

  14. --with-ssl=/usr

  15. make;makeinstall

#make的时候报错,“/usr/lib/libexpat.so:couldnotreadsymbols:Fileinwrongformat”
#解决方法:
\cp/usr/lib64/libexpat.*/usr/lib/

#配置自启动文件
cp/usr/local/apache/bin/apachectl/etc/init.d/httpd
vi/etc/init.d/httpd
#在首行#!/bin/sh下添加
#StartupscriptfortheApacheWebServer
#
#chkconfig:-8515
#description:webserver.Itisusedtoserve\
#HTMLfilesandCGI.
#processname:httpd
#pidfile:/usr/local/apache/logs/httpd.pid
#config:/usr/local/apache/conf/httpd.conf

#或者直接使用sed添加

 
 
  1. sed-i'/#!\/bin\/sh/a\#chkconfig:-8515\n#description:webserver\n#processname:httpd\n#pidfile:/usr/local/apache/logs/httpd.pid\n#config:/usr/local/apache/conf/httpd.conf'/etc/init.d/httpd

#修改apache配置文件
cd/usr/local/apache/conf/
mvhttpd.confhttpd.conf.bak

 
 
  1. cat>>httpd.conf<<EOF

  2. ServerRoot"/usr/local/apache"

  3. Listen80

  4. Timeout300

  5. KeepAliveOff

  6. MaxKeepAliveRequests100

  7. KeepAliveTimeout5

  8. UseCanonicalNameOff

  9. AccessFileName.htaccess

  10. TraceEnableOff

  11. ServerTokensProductOnly

  12. FileETagNone

  13. ServerSignatureOff

  14. HostnameLookupsOff

  15. #LoadModulefoo_modulemodules/mod_foo.so

  16. #

  17. LoadModuleauthn_file_modulemodules/mod_authn_file.so

  18. #LoadModuleauthn_dbm_modulemodules/mod_authn_dbm.so

  19. #LoadModuleauthn_anon_modulemodules/mod_authn_anon.so

  20. #LoadModuleauthn_dbd_modulemodules/mod_authn_dbd.so

  21. #LoadModuleauthn_socache_modulemodules/mod_authn_socache.so

  22. LoadModuleauthn_core_modulemodules/mod_authn_core.so

  23. LoadModuleauthz_host_modulemodules/mod_authz_host.so

  24. LoadModuleauthz_groupfile_modulemodules/mod_authz_groupfile.so

  25. LoadModuleauthz_user_modulemodules/mod_authz_user.so

  26. #LoadModuleauthz_dbm_modulemodules/mod_authz_dbm.so

  27. #LoadModuleauthz_owner_modulemodules/mod_authz_owner.so

  28. #LoadModuleauthz_dbd_modulemodules/mod_authz_dbd.so

  29. LoadModuleauthz_core_modulemodules/mod_authz_core.so

  30. LoadModuleaccess_compat_modulemodules/mod_access_compat.so

  31. LoadModuleauth_basic_modulemodules/mod_auth_basic.so

  32. #LoadModuleauth_form_modulemodules/mod_auth_form.so

  33. #LoadModuleauth_digest_modulemodules/mod_auth_digest.so

  34. #LoadModuleallowmethods_modulemodules/mod_allowmethods.so

  35. #LoadModulefile_cache_modulemodules/mod_file_cache.so

  36. #LoadModulecache_modulemodules/mod_cache.so

  37. #LoadModulecache_disk_modulemodules/mod_cache_disk.so

  38. #LoadModulesocache_shmcb_modulemodules/mod_socache_shmcb.so

  39. #LoadModulesocache_dbm_modulemodules/mod_socache_dbm.so

  40. #LoadModulesocache_memcache_modulemodules/mod_socache_memcache.so

  41. #LoadModuledbd_modulemodules/mod_dbd.so

  42. #LoadModuledumpio_modulemodules/mod_dumpio.so

  43. #LoadModulebuffer_modulemodules/mod_buffer.so

  44. #LoadModuleratelimit_modulemodules/mod_ratelimit.so

  45. LoadModulereqtimeout_modulemodules/mod_reqtimeout.so

  46. #LoadModuleext_filter_modulemodules/mod_ext_filter.so

  47. #LoadModulerequest_modulemodules/mod_request.so

  48. #LoadModuleinclude_modulemodules/mod_include.so

  49. LoadModulefilter_modulemodules/mod_filter.so

  50. #LoadModulesubstitute_modulemodules/mod_substitute.so

  51. #LoadModulesed_modulemodules/mod_sed.so

  52. #LoadModuledeflate_modulemodules/mod_deflate.so

  53. LoadModulemime_modulemodules/mod_mime.so

  54. LoadModulelog_config_modulemodules/mod_log_config.so

  55. #LoadModulelog_debug_modulemodules/mod_log_debug.so

  56. #LoadModulelogio_modulemodules/mod_logio.so

  57. LoadModuleenv_modulemodules/mod_env.so

  58. #LoadModulemime_magic_modulemodules/mod_mime_magic.so

  59. #LoadModuleexpires_modulemodules/mod_expires.so

  60. LoadModuleheaders_modulemodules/mod_headers.so

  61. #LoadModuleunique_id_modulemodules/mod_unique_id.so

  62. LoadModulesetenvif_modulemodules/mod_setenvif.so

  63. LoadModuleversion_modulemodules/mod_version.so

  64. #LoadModuleremoteip_modulemodules/mod_remoteip.so

  65. LoadModuleproxy_modulemodules/mod_proxy.so

  66. LoadModuleproxy_connect_modulemodules/mod_proxy_connect.so

  67. LoadModuleproxy_ftp_modulemodules/mod_proxy_ftp.so

  68. LoadModuleproxy_http_modulemodules/mod_proxy_http.so

  69. LoadModuleproxy_fcgi_modulemodules/mod_proxy_fcgi.so

  70. LoadModuleproxy_scgi_modulemodules/mod_proxy_scgi.so

  71. LoadModuleproxy_ajp_modulemodules/mod_proxy_ajp.so

  72. #LoadModuleproxy_balancer_modulemodules/mod_proxy_balancer.so

  73. LoadModuleproxy_express_modulemodules/mod_proxy_express.so

  74. #LoadModulesession_modulemodules/mod_session.so

  75. #LoadModulesession_cookie_modulemodules/mod_session_cookie.so

  76. #LoadModulesession_dbd_modulemodules/mod_session_dbd.so

  77. #LoadModuleslotmem_shm_modulemodules/mod_slotmem_shm.so

  78. #LoadModulessl_modulemodules/mod_ssl.so

  79. LoadModulelbmethod_byrequests_modulemodules/mod_lbmethod_byrequests.so

  80. LoadModulelbmethod_bytraffic_modulemodules/mod_lbmethod_bytraffic.so

  81. LoadModulelbmethod_bybusyness_modulemodules/mod_lbmethod_bybusyness.so

  82. LoadModulelbmethod_heartbeat_modulemodules/mod_lbmethod_heartbeat.so

  83. LoadModuleunixd_modulemodules/mod_unixd.so

  84. #LoadModuledav_modulemodules/mod_dav.so

  85. LoadModulestatus_modulemodules/mod_status.so

  86. LoadModuleautoindex_modulemodules/mod_autoindex.so

  87. #LoadModuleinfo_modulemodules/mod_info.so

  88. #LoadModulesuexec_modulemodules/mod_suexec.so

  89. #LoadModulecgi_modulemodules/mod_cgi.so

  90. #LoadModuledav_fs_modulemodules/mod_dav_fs.so

  91. LoadModulevhost_alias_modulemodules/mod_vhost_alias.so

  92. #LoadModulenegotiation_modulemodules/mod_negotiation.so

  93. LoadModuledir_modulemodules/mod_dir.so

  94. #LoadModuleactions_modulemodules/mod_actions.so

  95. #LoadModulespeling_modulemodules/mod_speling.so

  96. #LoadModuleuserdir_modulemodules/mod_userdir.so

  97. LoadModulealias_modulemodules/mod_alias.so

  98. LoadModulerewrite_modulemodules/mod_rewrite.so

  99. <IfModuleunixd_module>

  100. Userwww

  101. Groupwww

  102. </IfModule>

  103. [email protected]

  104. <Directory/>

  105. AllowOverridenone

  106. Requirealldenied

  107. </Directory>

  108. DocumentRoot"/usr/local/apache/htdocs"

  109. <Directory"/usr/local/apache/htdocs">

  110. OptionsIndexesFollowSymLinks

  111. AllowOverrideNone

  112. Requireallgranted

  113. </Directory>

  114. <IfModuledir_module>

  115. DirectoryIndexindex.htmlindex.php

  116. </IfModule>

  117. <Files".ht*">

  118. Requirealldenied

  119. </Files>

  120. ErrorLog"logs/error_log"

  121. LogLevelwarn

  122. <IfModulelog_config_module>

  123. LogFormat"%h%l%u%t\"%r\"%>s%b\"%{Referer}i\"\"%{User-Agent}i\""combined

  124. LogFormat"%h%l%u%t\"%r\"%>s%b"common

  125. <IfModulelogio_module>

  126. LogFormat"%h%l%u%t\"%r\"%>s%b\"%{Referer}i\"\"%{User-Agent}i\"%I%O"combinedio

  127. </IfModule>

  128. CustomLog"logs/access_log"common

  129. </IfModule>

  130. <IfModulealias_module>

  131. ScriptAlias/cgi-bin/"/usr/local/apache/cgi-bin/"

  132. </IfModule>

  133. <IfModulecgid_module>

  134. #Scriptsocklogs/cgisock

  135. </IfModule>

  136. <Directory"/usr/local/apache/cgi-bin">

  137. AllowOverrideNone

  138. OptionsNone

  139. Requireallgranted

  140. </Directory>

  141. RewriteEngineon

  142. <IfModulemime_module>

  143. TypesConfigconf/mime.types

  144. AddTypeapplication/x-compress.Z

  145. AddTypeapplication/x-gzip.gz.tgz

  146. AddTypeapplication/x-httpd-php.php.php3.php4.php5.php6

  147. AddTypeapplication/x-httpd-php-source.phps

  148. </IfModule>

  149. #Server-poolmanagement(MPMspecific)

  150. Includeconf/extra/httpd-mpm.conf

  151. #Virtualhosts

  152. Includeconf/extra/httpd-vhosts.conf

  153. #Configuremod_proxy_htmltounderstandHTML4/XHTML1

  154. <IfModuleproxy_html_module>

  155. Includeconf/extra/proxy-html.conf

  156. </IfModule>

  157. #Secure(SSL/TLS)connections

  158. #Includeconf/extra/httpd-ssl.conf

  159. <IfModulessl_module>

  160. SSLRandomSeedstartupbuiltin

  161. SSLRandomSeedconnectbuiltin

  162. </IfModule>

  163. EOF

#配置mpm_prefork_module
mvextra/httpd-mpm.confextra/httpd-mpm.conf.bak

 
 
  1. cat>>extra/httpd-mpm.conf<<EOF

  2. <IfModulempm_prefork_module>

  3. ServerLimit10000

  4. StartServers5

  5. MinSpareServers5

  6. MaxSpareServers10

  7. MaxRequestWorkers10000

  8. MaxConnectionsPerChild10000

  9. </IfModule>

  10. EOF

#配置虚拟主机(apache虚拟主机,通过IP访问默认会访问到第一个虚拟主机上,那么就第一个虚拟主机定义为127.0.0.1,目录指到/usr/local/apache/htdocs)
mvextra/httpd-vhosts.confextra/httpd-vhosts.conf.bak

 
 
  1. cat>>extra/httpd-vhosts.conf<<EOF

  2. #Vhosts

  3. <VirtualHost*:81>

  4. [email protected]

  5. DocumentRoot"/usr/local/apache/htdocs"

  6. <Directory"/usr/local/apache/htdocs">

  7. OptionsIndexesFollowSymLinks

  8. AllowOverrideNone

  9. Requireallgranted

  10. </Directory>

  11. ServerName127.0.0.1

  12. </VirtualHost>

  13. <VirtualHost*:81>

  14. [email protected]

  15. DocumentRoot"/data/www/kerry"

  16. <Directory"/data/www/kerry">

  17. OptionsIndexesFollowSymLinks

  18. AllowOverrideNone

  19. Requireallgranted

  20. </Directory>

  21. ServerNamewww.kerry.com

  22. ErrorLog"logs/kerry-error_log"

  23. CustomLog"|/usr/local/apache/bin/rotatelogs/data/logs/kerry/%y_%m_%d.access_log86400"common

  24. </VirtualHost>

  25. <VirtualHost*:81>

  26. [email protected]

  27. DocumentRoot"/data/www/king"

  28. <Directory"/data/www/king">

  29. OptionsIndexesFollowSymLinks

  30. AllowOverrideNone

  31. Requireallgranted

  32. </Directory>

  33. ServerNamewww.king.com

  34. ErrorLog"logs/king-error_log"

  35. CustomLog"|/usr/local/apache/bin/rotatelogs/data/logs/king/%y_%m_%d.access_log86400"common

  36. </VirtualHost>

  37. EOF

#设置apache自启动
chmod700/etc/init.d/httpd
/etc/init.d/httpdstart
/sbin/chkconfig--addhttpd
/sbin/chkconfig--level2345httpdon
cd../


#===================InstallPHP5.4.0===============#
#编译安装相关支持库
cd/opt
tar-zxvflibiconv-1.14.tar.gz
cdlibiconv-1.14/
./configure
make;makeinstall
cd../

tar-jxvflibmcrypt-2.5.8.tar.bz2
cdlibmcrypt-2.5.8/
./configure
make;makeinstall
/sbin/ldconfig

cdlibltdl/
./configure--enable-ltdl-install
make;makeinstall

cd/opt
tar-jxvfmhash-0.9.9.9.tar.bz2
cdmhash-0.9.9.9/
./configure
make;makeinstall
ln-s/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.la
ln-s/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.so
ln-s/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4
ln-s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8
ln-s/usr/local/lib/libmhash.a/usr/lib/libmhash.a
ln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.la
ln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.so
ln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2
ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1

cd/opt
tar-zxvfmcrypt-2.6.8.tar.gz
cdmcrypt-2.6.8/
/sbin/ldconfig
./configure
make;makeinstall

#编译php,这里我们为php打入补丁.有助于防止邮件发送被滥用(多用户)以及在邮件中提供有价值的信息.补丁介绍信息请点击:http://www.lancs.ac.uk/~steveb/patches/php-mail-header-patch/
cd/opt
tar-jxvfphp-5.4.0.tar.gz
patch-dphp-5.4.0-p1<php5-mail-header.patch
cdphp-5.4.0
./configure--prefix=/usr/local/php\
--with-config-file-path=/usr/local/php/etc\
--with-apxs2=/usr/local/apache/bin/apxs\
--with-mysql=/usr/local/mysql\
--with-mysqli=/usr/local/mysql/bin/mysql_config\
--with-iconv-dir=/usr/local\
--with-freetype-dir\
--with-jpeg-dir\
--with-png-dir\
--with-zlib\
--with-libxml-dir=/usr\
--enable-xml\
--disable-rpath\
--enable-bcmath\
--enable-shmop\
--enable-sysvsem\
--enable-inline-optimization\
--with-curl\
--with-curlwrappers\
--enable-mbregex\
--enable-mbstring\
--with-mcrypt\
--with-gd\
--enable-gd-native-ttf\
--with-openssl\
--with-mhash\
--enable-pcntl\
--enable-sockets\
--with-ldap\
--with-ldap-sasl\
--with-xmlrpc\
--enable-zip\
--enable-soap

makeZEND_EXTRA_LIBS='-liconv'
makeinstall
cpphp.ini-production/usr/local/php/etc/php.ini
cd../

#安装php扩展模块
cd/opt
tar-zxvfmemcache-3.0.6.tgz
cdmemcache-3.0.6/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--with-zlib-dir--enable-memcache
make;makeinstall
cd../

#make时出错(如下图)

152729862.png


#解决办法:修改memcache.c
将721行:
zend_list_insert(mmc,le_memcache_server);
改为:
zend_list_insert(mmcTSRMLS_CC,le_memcache_server);

将738行:
zend_list_insert(mmc,le_memcache_server);
改为:
zend_list_insert(mmcTSRMLS_CC,le_memcache_server);

将778行:
list_id=zend_list_insert(pool,le_memcache_pool);
改为:
list_id=zend_list_insert(poolTSRMLS_CC,le_memcache_pool);

将839行:
list_id=zend_list_insert(poolTSRMLS_CC,le_memcache_pool);
改为:
list_id=zend_list_insert(pool,le_memcache_pool);

#用sed修改

 
 
  1. sed-i's#zend_list_insert(mmc,le_memcache_server);#zend_list_insert(mmcTSRMLS_CC,le_memcache_server);#'memcache.c

  2. sed-i's#list_id=zend_list_insert(pool,le_memcache_pool);#list_id=zend_list_insert(poolTSRMLS_CC,le_memcache_pool);#'memcache.c

#php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached

#安装memcached的服务端支持库
cd/opt
tar-xzflibevent-2.0.18-stable.tar.gz
cdlibevent-2.0.18-stable
./configure
make;makeinstall
ln-s/usr/local/lib/libevent-2.0.so.5/usr/lib

#安装Memcached服务端
cd/opt
tar-xzfmemcached-1.4.13.tar.gz
cdmemcached-1.4.13
./configure--prefix=/usr/local/memcached--with-libevent=/usr
make;makeinstall

cd/opt
tar-zxvflibmemcached-1.0.2.tar.tar
cdlibmemcached-1.0.2
./configure--prefix=/usr/local/libmemcached--with-memcached
make;makeinstall

#安装php的memcached扩展库
cd/opt
tar-zxvfmemcached-2.0.1.tgz
cdmemcached-2.0.1
/usr/local/php/bin/phpize
./configure--enable-memcached--with-php-config=/usr/local/php/bin/php-config--with-libmemcached-dir=/usr/local/libmemcached--with-memcached--with-zlib
make;makeinstall

#因eaccelerator-0.9.6.1不支持php5.4.0,所以就改用XCache2.0.0
cd/opt
tar-zxvfxcache-2.0.0.tar.gz
cdxcache-2.0.0
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
make;makeinstall

#安装pdo扩展
cd/opt
php-5.4.0/ext/pdo_mysql
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--with-pdo-mysql=/usr/local/mysql
make;makeinstall

cd/opt
tar-jxvfImageMagick-6.7.6-7.tar.bz2
cdImageMagick-6.7.6-7
./configure--prefix=/usr/local/imagemagick
make;makeinstall

#imagick最新正式版为imagick-3.0.1.tgz,但imagick-3.0.1.tgz在make的时候会出现大量的报错信息,所以就改用imagick-3.1.0RC1.tgz
cd/opt
tar-zxvfimagick-3.1.0RC1.tgz
cdimagick-3.1.0RC1/
exportPKG_CONFIG_PATH=/usr/local/imagemagick/lib/pkgconfig
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--with-imagick=/usr/local/imagemagick
make;makeinstall

cd/opt
tar-jxfioncube_loaders_lin_x86.tar.bz2
cdioncube
mkdir/usr/local/ioncube
mvioncube_loader_lin_5.2.so/usr/local/ioncube/

#修改php.ini添加php扩展

 
 
  1. sed-i's#;extension_dir="./"#extension_dir="/usr/local/php/lib/php/extensions/no-debug-zts-20100525/"\nextension="memcache.so"\nextension="pdo_mysql.so"\nextension="memcached.so"\nextension="imagick.so"\n#'/usr/local/php/etc/php.ini

 
 
  1. cat>>/usr/local/php/etc/php.ini<<EOF

  2. [xcache-common]

  3. extension=xcache.so

  4. [xcache]

  5. xcache.shm_scheme="mmap"

  6. xcache.size=256M

  7. xcache.count=8

  8. xcache.slots=8K

  9. xcache.ttl=0

  10. xcache.gc_interval=0

  11. xcache.var_size=8M

  12. xcache.var_count=8

  13. xcache.var_slots=8K

  14. xcache.var_ttl=0

  15. xcache.var_maxttl=0

  16. xcache.var_gc_interval=300

  17. xcache.test=Off

  18. xcache.readonly_protection=Off

  19. xcache.mmap_path="/dev/zero"

  20. xcache.coredump_directory=""

  21. xcache.cacher=On

  22. xcache.stat=On

  23. xcache.optimizer=Off

  24. [xcache.coverager]

  25. xcache.coverager=Off

  26. xcache.coveragedump_directory=""

  27. EOF

#隐藏php版本
sed-i's#expose_php=On#expose_php=Off#'/usr/local/php/etc/php.ini

#php安全设置,禁用函数
sed-i's#disable_functions=#disable_functions=phpinfo,exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source#'/usr/local/php/etc/php.ini

#重启apache,查看php扩展加载的情况
/etc/init.d/httpdrestart


#=============InstallNginx===================#
cd/opt
tar-zxvfnginx-1.2.0.tar.gz
cdnginx-1.2.0
./configure--user=www--group=www--prefix=/usr/local/nginx--with-pcre=/opt/pcre-8.30--with-http_stub_status_module--with-http_ssl_module--with-http_flv_module--with-http_gzip_static_module--with-google_perftools_module
make;makeinstall

cd../

#添加nginx启动脚本

 
 
  1. cat>>/etc/init.d/nginx<<EOF

  2. #!/bin/sh

  3. ulimit-n65535

  4. #Description:Startupscriptfornginx

  5. #chkconfig:23455525

  6. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

  7. DESC="nginxdaemon"

  8. NAME=nginx

  9. DAEMON=/usr/local/nginx/sbin/$NAME

  10. CONFIGFILE=/usr/local/nginx/conf/nginx.conf

  11. PIDFILE=/usr/local/nginx/logs/$NAME.pid

  12. SCRIPTNAME=/etc/init.d/$NAME

  13. set-e

  14. [-x"$DAEMON"]||exit0

  15. do_start(){

  16. $DAEMON-c$CONFIGFILE||echo-n"nginxalreadyrunning"

  17. }

  18. do_stop(){

  19. kill-QUIT`cat$PIDFILE`||echo-n"nginxnotrunning"

  20. }

  21. do_reload(){

  22. kill-HUP`cat$PIDFILE`||echo-n"nginxcan'treload"

  23. }

  24. case"$1"in

  25. start)

  26. echo-n"Starting$DESC:$NAME"

  27. do_start

  28. echo"."

  29. /etc/init.d/httpdstart

  30. ;;

  31. stop)

  32. echo-n"Stopping$DESC:$NAME"

  33. do_stop

  34. echo"."

  35. /etc/init.d/httpdstop

  36. ;;

  37. reload)

  38. echo-n"Reloading$DESCconfiguration..."

  39. do_reload

  40. echo"."

  41. /etc/init.d/httpdrestart

  42. ;;

  43. restart)

  44. echo-n"Restarting$DESC:$NAME"

  45. do_stop

  46. sleep1

  47. do_start

  48. echo"."

  49. /etc/init.d/httpdrestart

  50. ;;

  51. *)

  52. echo"Usage:$SCRIPTNAME{start|stop|reload|restart}">&2

  53. exit3

  54. ;;

  55. esac

  56. exit0

  57. EOF

#添加nginx配置文件
mv/usr/local/nginx/conf/nginx.conf/usr/local/nginx/conf/nginx.conf.bak

 
 
  1. cat>>/usr/local/nginx/conf/nginx.conf<<EOF

  2. userwwwwww;

  3. worker_processes8;

  4. error_log/usr/local/nginx/logs/nginx_error.logcrit;

  5. pid/usr/local/nginx/logs/nginx.pid;

  6. #使用Tcmalloc优化nginx性能

  7. google_perftools_profiles/var/tmp/tcmalloc;

  8. #Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.

  9. worker_rlimit_nofile65535;

  10. #工作模式及连接数上限

  11. events

  12. {

  13. useepoll;

  14. worker_connections65535;

  15. }

  16. #设定http服务器,利用它的反向代理功能提供负载均衡支持

  17. http

  18. {

  19. #设定mime类型

  20. includemime.types;

  21. default_typeapplication/octet-stream;

  22. #charsetgb2312;

  23. #设定请求缓冲

  24. server_names_hash_bucket_size128;

  25. client_header_buffer_size32k;

  26. large_client_header_buffers432k;

  27. client_max_body_size30m;

  28. sendfileon;

  29. tcp_nopushon;

  30. keepalive_timeout60;

  31. tcp_nodelayon;

  32. server_tokensoff;

  33. client_body_buffer_size512k;

  34. proxy_connect_timeout5;

  35. proxy_send_timeout60;

  36. proxy_read_timeout5;

  37. proxy_buffer_size16k;

  38. proxy_buffers464k;

  39. proxy_busy_buffers_size128k;

  40. proxy_temp_file_write_size128k;

  41. #fastcgi_connect_timeout300;

  42. #fastcgi_send_timeout300;

  43. #fastcgi_read_timeout300;

  44. #fastcgi_buffer_size64k;

  45. #fastcgi_buffers464k;

  46. #fastcgi_busy_buffers_size128k;

  47. #fastcgi_temp_file_write_size128k;

  48. gzipon;

  49. gzip_min_length1k;

  50. gzip_buffers416k;

  51. gzip_http_version1.1;

  52. gzip_comp_level2;

  53. gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;

  54. gzip_varyon;

  55. #limit_zonecrawler$binary_remote_addr10m;

  56. #定义访问日志的写入格式

  57. log_formatwwwlog'$remote_addr-$remote_user[$time_local]"$request"'

  58. '$status$body_bytes_sent"$http_referer"'

  59. '"$http_user_agent"$http_x_forwarded_for';

  60. log_formatbbslog'$remote_addr-$remote_user[$time_local]"$request"'

  61. '$status$body_bytes_sent"$http_referer"'

  62. '"$http_user_agent"$http_x_forwarded_for';

  63. ###禁止通过ip访问站点

  64. server{

  65. server_name_;

  66. return404;

  67. }

  68. server

  69. {

  70. listen80;

  71. server_namewww.kerry.com;

  72. indexindex.htmlindex.htmindex.php;#设定访问的默认首页地址

  73. root/data/www/kerry;#设定网站的资源存放路径

  74. #limit_conncrawler20;

  75. if(-d$request_filename)

  76. {

  77. rewrite^/(.*)([^/])$http://$host/$1$2/permanent;

  78. }

  79. #所有jsp的页面均交由tomcat处理

  80. location~\.(php)?${

  81. proxy_set_headerHost$host;

  82. proxy_set_headerX-Real-IP$remote_addr;

  83. proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

  84. proxy_passhttp://127.0.0.1:81;#转向tomcat处理

  85. }

  86. location~.*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$#设定访问静态文件直接读取不经过apache

  87. {

  88. expires30d;

  89. }

  90. location~.*\.(js|css)?$

  91. {

  92. expires1h;

  93. }

  94. access_log/data/logs/kerry/kerry_nginx.logwwwlog;#设定访问日志的存放路径

  95. }

  96. server

  97. {

  98. listen80;

  99. server_namewww.king.com;

  100. indexindex.htmlindex.htmindex.php;#设定访问的默认首页地址

  101. root/data/www/king;#设定网站的资源存放路径

  102. #limit_conncrawler20;

  103. if(-d$request_filename)

  104. {

  105. rewrite^/(.*)([^/])$http://$host/$1$2/permanent;

  106. }

  107. #所有jsp的页面均交由tomcat处理

  108. location~\.(php)?${

  109. proxy_set_headerHost$host;

  110. proxy_set_headerX-Real-IP$remote_addr;

  111. proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

  112. proxy_passhttp://127.0.0.1:81;#转向tomcat处理

  113. }

  114. location~.*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$#设定访问静态文件直接读取不经过apache

  115. {

  116. expires30d;

  117. }

  118. location~.*\.(js|css)?$

  119. {

  120. expires1h;

  121. }

  122. access_log/data/logs/king/king_nginx.logbbslog;#设定访问日志的存放路径

  123. }

  124. server

  125. {

  126. listen80;

  127. server_namestatus.www.kerry.com;

  128. location/{

  129. stub_statuson;

  130. access_logoff;

  131. }

  132. }

  133. }

  134. EOF

#将nginx添加到启动服务中
chmod700/etc/init.d/nginx
/etc/init.d/nginxstart
/sbin/chkconfig--addnginx
/sbin/chkconfig--level2345nginxon


#每天定时切割Nginx日志

 
 
  1. cat>>/usr/local/nginx/sbin/cut_nginx_log.sh<<EOF

  2. #!/bin/bash

  3. #Thisscriptrunat00:00

  4. #TheNginxlogspath

  5. logs_path_kerry="/data/logs/kerry/"

  6. logs_path_kerry="/data/logs/king/"

  7. mv${logs_path_kerry}kerry_nginx.log${logs_path_kerry}$kerry_nginx_$(date-d"yesterday"+"%Y%m%d").log

  8. mv${logs_path_king}king_nginx.log${logs_path_king}king_nginx_$(date-d"yesterday"+"%Y%m%d").log

  9. kill-USR1`cat/usr/local/nginx/nginx.pid`

  10. EOF

chmod+x/usr/local/nginx/sbin/cut_nginx_log.sh
#添加计划任务,每天凌晨00:00切割nginx访问日志
crontab-e
0000***/bin/bash/usr/local/nginx/sbin/cut_nginx_log.sh

#为apache安装rpaf模块,该模块用于apache做后端时获取访客真实的IP
#使用apxs安装模块.这里要使用此前apache编译安装后的apxs
cd/opt
tar-zxfmod_rpaf-0.6.tar.gz
cdmod_rpaf-0.6
/usr/local/apache/bin/apxs-i-c-nmod_rpaf-2.0.somod_rpaf-2.0.c

#错误提示:
mod_rpaf-2.0.c:Infunction'rpaf_cleanup':
mod_rpaf-2.0.c:150:error:'conn_rec'hasnomembernamed'remote_ip'
mod_rpaf-2.0.c:151:error:'conn_rec'hasnomembernamed'remote_addr'
mod_rpaf-2.0.c:151:warning:implicitdeclarationoffunction'inet_addr'
mod_rpaf-2.0.c:151:error:'conn_rec'hasnomembernamed'remote_ip'
mod_rpaf-2.0.c:Infunction'change_remote_ip':
mod_rpaf-2.0.c:164:error:'conn_rec'hasnomembernamed'remote_ip'
mod_rpaf-2.0.c:183:error:'conn_rec'hasnomembernamed'remote_ip'
mod_rpaf-2.0.c:186:error:'conn_rec'hasnomembernamed'remote_ip'
mod_rpaf-2.0.c:187:error:'conn_rec'hasnomembernamed'remote_addr'
mod_rpaf-2.0.c:187:error:'conn_rec'hasnomembernamed'remote_ip'
apxs:Error:Commandfailedwithrc=65536

152532364.png

#解决办法:
#http://httpd.apache.org/docs/trunk/developer/new_api_2_4.html

152555243.png
#将150、151、164、183、186、187这几行的remote_ip修改成client_ip,remote_addr修改成client_addr

#编辑/usr/local/apache/conf/httpd.conf,添加模块参数,查找LoadModulephp5_modulemodules/libphp5.so,在下方添加:

 
 
  1. LoadModulerpaf_modulemodules/mod_rpaf-2.0.so

  2. #Mod_rpafsettings

  3. RPAFenableOn

  4. #上面出现的192.168.9.9请修改为你本机所监听web服务的ip.多个IP用空格空开

  5. RPAFproxy_ips127.0.0.1192.168.9.9

  6. RPAFsethostnameOn

  7. RPAFheaderX-Forwarded-For

你可能感兴趣的:(apache,nginx,linux,mysql,PHP,lnamp)