lvs keepalived nginx apache搭建高可用、高性能php集群.docx_第1页
lvs keepalived nginx apache搭建高可用、高性能php集群.docx_第2页
lvs keepalived nginx apache搭建高可用、高性能php集群.docx_第3页
lvs keepalived nginx apache搭建高可用、高性能php集群.docx_第4页
lvs keepalived nginx apache搭建高可用、高性能php集群.docx_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

LVS+keepalived+nginx+apache搭建高可用、高性能php集群2011-07-01 12:04:30标签:phpmysqlapache集群nginx原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处、作者信息和本声明。否则将追究法律责任。/172631/600590 基于PHP的运行环境大家用的比较多的是以apache做中间件的LAMP(linux+apache+mysql+php)环境和以nginx做中间件的LNMP(linux+nginx+mysql+php)环境,apache是世界排名第一的web服务器,apache可以整合大多数应用,比如jsp,php,cgi,python等等,但是apache过于臃肿以及对静态文件响应过于缓慢是让人很不满意的;而nginx作为后起之秀,大有超越前辈的势头,从最近很多门户网站选用nginx就可见一斑,nginx速度快,占用资源少,高性能转发,很高的稳定性,支持热部署,杀手级的proxy和rewrite,但nginx对于php处理依托于fastcgi,fastcgi不够稳定,经常出现502错误,生成相对复杂的页面没有优势,反而会使php-cgi进程变为僵尸进程,多用户多站点的安全性不高,对于其它开发语言的整合,apache表现的更好;综上述对比,为了搭建高性能的php运行环境,就要考虑对apache、nginx进行整合,各取所长,nginx在处理静态内容上的效率较apache强很大,那么就用nginx在前端处理静态文件,把基于php的动态文件转发到后端的apache来处理,接下来我们就开始布署LNAMP(linux+nginx+apache+mysql+php)环境一、网络拓扑:lvs-master: 21LVS-backup: 22LVS-VIP: 20web_server_1: 23web_server_2: 24nfs_server_1: 28nfs_server_1: 29nfs_vip: 30mysql_master: 26mysql_backup: 27mysql_vip: 25目的:搭建高可用、高性能的php集群二、初始化系统#init system系统环境: CentOS 5.5 (最小化安装)./init_system.sh #此脚本参见/172631/555535#更新组件sudo -sLANG=Cyum -y install gcc gcc-c+ bison patch unzip mlocate flex wget automake autoconf gd cpp gettext readline-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel libidn libidn-devel openldap openldap-devel openldap-clients openldap-servers nss_ldap expat-devel libtool libtool-ltdl-devel bison三、LVS+keeplived#关于LVS+keeplived的配置请参考我的另一篇博文CentOS5.5环境下布署LVS+keepalived /172631/401253四、web_server安装配置(nginx、apache整合)#download softwarecd /optwget/download/nginx-1.0.4.tar.gzwget/dist/httpd/httpd-2.2.19.tar.gzwget/files/v2.8/cmake-2.8.4.tar.gzwget/Downloads/MySQL-5.5/mysql-5.5.13.tar.gzwget/get/PDO_MYSQL-1.0.2.tgz#rpaf模块,该模块用于apache做后端时获取访客真实的IPwget/apache/rpaf/download/mod_rpaf-0.6.tar.gz#字符转换库libiconvwget/pub/gnu/libiconv/libiconv-1.13.1.tar.gzwget/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/downloadwget/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/downloadwget/projects/mhash/files/mhash//mhash-.tar.bz2/downloadwget/distributions/php-5.2.17.tar.bz2#php5-mail-header.patch为php被丁,有助于防止邮件发送被滥用wgethttp:/www.lancs.ac.uk/steveb/patches/php-mail-header-patch/php5-mail-header.patch#PHP的memcache扩展wget/get/memcache-2.2.6.tgz#eaccelerator加速wget/source//eaccelerator-.tar.bz2wget/pub/ImageMagick/ImageMagick.tar.bz2#PHP的imagick扩展wget/get/imagick-3.0.1.tgz#Suhosin是一个PHP程序的保护系统wget/suhosin-.tar.gzwget/loader_downloads/ioncube_loaders_lin_x86.tar.bz2wget/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz #32位wget/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz #64位wget/provos/libevent-2.0.11-stable.tar.gzwget/projects/pcre/files/pcre/8.12/pcre-8.12.tar.bz2/downloadwget/files/memcached-1.4.5.tar.gz#PHP的PDO扩展wget/get/PDO_MYSQL-1.0.2.tgz#Tcmalloc 优化nginx、mysqlwget/files/google-perftools-1.7.tar.gz#- 使用cmake编译安装mysql -#使用Tcmalloc 优化nginx、mysqlcd /opttar -zxvf google-perftools-1.7.tar.gzcd google-perftools-1.7/./configuremake;make installecho /usr/local/lib /etc/ld.so.conf.d/usr_local_lib.conf/sbin/ldconfigcd ./tar -zxvf cmake-2.8.4.tar.gzcd cmake-2.8.4./bootstrapgmakegmake installcd ./usr/sbin/groupadd mysql/usr/sbin/useradd -g mysql mysql -s /sbin/nologinmkdir -p /data/mysql/datamkdir -p /data/mysql/binlogmkdir -p /data/mysql/relaylogmkdir -p /data/mysql/mysqlchown -R mysql:mysql /data/mysqlcd /opttar zxvf mysql-5.5.13.tar.gzcd mysql-5.5.13/rm -rf CMakeCache.txtcmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/data -DMYSQL_TCP_PORT=3306make;make installchmod +w /usr/local/mysqlchown -R mysql:mysql /usr/local/mysqlln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18#编辑mysql配置文件vi /etc/f1. client 2. port=33063. socket=/data/mysql/mysql.sock 4. 5. mysqld 6. character_set_server=utf87. collation-server=utf8_general_ci8. replicate-ignore-db=mysql9. replicate-ignore-db=test10. replicate-ignore-db=information_schema11. user=mysql12. port=330613. 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=1024019. back_log=60020. max_connections=500021. max_connect_errors=600022. table_cache=51223. external-locking=FALSE24. max_allowed_packet=32M25. sort_buffer_size=6M26. join_buffer_size=8M27. thread_cache_size=30028. thread_concurrency=829. query_cache_size=512M30. query_cache_limit=2M31. query_cache_min_res_unit=2k32. default-storage-engine=MyISAM33. thread_stack=256K34. transaction_isolation=READ-COMMITTED 35. tmp_table_size=256M36. max_heap_table_size=256M37. long_query_time=338. log-slave-updates 39. log-bin=/data/mysql/binlog/binlog 40. binlog_cache_size=4M41. binlog_format=MIXED42. max_binlog_cache_size=8M43. max_binlog_size=100M44. 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=3048. key_buffer_size=384M49. read_buffer_size=4M50. read_rnd_buffer_size=16M51. bulk_insert_buffer_size=64M52. myisam_sort_buffer_size=128M53. myisam_max_sort_file_size=10G54. myisam_repair_threads=155. myisam_recover 56. 57. interactive_timeout=12058. wait_timeout=12059. 60. skip_external_locking 61. skip-name-resolve 62. #master-connect-retry=1063. slave-skip-errors=1032,1062,126,1114,1146,1048,1396 64. 65. #master-host= 66. #master-user=username67. #master-password=password 68. #master-port=330669. 70. server-id=171. 72. skip-innodb 73. 74. #log-slow-queries=/data/mysql/slow.log 75. #long_query_time=1076. 77. mysqldump 78. quick 79. max_allowed_packet=32M#初始化mysql/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#在# executing mysqld_safe的下一行,加上:export LD_PRELOAD=/usr/local/lib/libtcmalloc.so#使用lsof命令查看tcmalloc是否起效/usr/sbin/lsof -n | grep tcmalloc#设置mysql启动文件cp support-files/mysql.server /etc/rc.d/init.d/mysqldvi /etc/rc.d/init.d/mysqldbasedir=/usr/local/mysqldatadir=/data/mysql/datachmod 700 /etc/rc.d/init.d/mysqld/etc/rc.d/init.d/mysqld start/sbin/chkconfig -add mysqld/sbin/chkconfig -level 2345 mysqld onln -s /usr/local/mysql/bin/mysql /sbin/mysqlln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin#设置root密码(753951)/sbin/mysqladmin -u root password 753951#配置库文件搜索路径echo /usr/local/mysql/lib/mysql /etc/ld.so.conf/sbin/ldconfig#添加/usr/local/mysql/bin到环境变量PATH中export PATH=$PATH:/usr/local/mysql/bin#添加mysql管理帐户#mysql -h localhost -u root -p753951#msqyl use mysql;#msqyl grant all on *.* tokerry00identified by 852741;#msqyl flush privileges;#msqyl exit;#- 编译安装apache -/usr/sbin/groupadd www/usr/sbin/useradd -g www www -s /sbin/nologinmkdir -p /data/www/kerrymkdir -p /data/logs/kerrymkdir -p /data/www/kingmkdir -p /data/logs/kingchown -R www:www /data/wwwchown -R www:www /data/logscd /opttar -zxvf httpd-2.2.19.tar.gzcd httpd-2.2.19cd srclib/apr./configure -prefix=/usr/local/apr -enable-threads -enable-other-child -enable-staticmake;make installcd ./apr-util./configure -prefix=/usr/local/apr-util -with-apr=/usr/local/aprmake;make installcd ./././configure -prefix=/usr/local/apache -enable-deflate -enable-headers -enable-mime-magic -enable-proxy -enable-ssl -enable-so -enable-rewrite -enable-suexec -with-suexec-bin=/usr/sbin/suexec -with-suexec-caller=www -with-apr=/usr/local/apr -with-apr-util=/usr/local/apr-util -with-mpm=prefork -with-ssl=/usrmake;make installcp /usr/local/apache/bin/apachectl /etc/init.d/httpdvi /etc/init.d/httpd#在首行#!/bin/sh下添加# Startup script for the Apache Web Server# chkconfig: - 85 15# description: Apache is a World Wide Web server. It is used to serve # HTML files and CGI.# processname: httpd# pidfile: /usr/local/apache/logs/httpd.pid# config: /usr/local/apache/conf/httpd.conf#修改apache配置文件cd /usr/local/apache/conf/mv httpd.conf httpd.conf.bakvi httpd.conf1. PidFilelogs/httpd.pid 2. LockFilelogs/accept.lock 3. ServerRoot/usr/local/apache 4. Listen:81 5. Userwww 6. Groupwww 7. ServerAdminking_819163.com 8. ServerN 9. 10. Timeout300 11. KeepAliveOff 12. MaxKeepAliveRequests100 13. KeepAliveTimeout5 14. UseCanonicalNameOff 15. AccessFileName.htaccess 16. TraceEnableOff 17. ServerTokensProductOnly 18. FileETagNone 19. ServerSignatureOff 20. HostnameLookupsOff 21. 22. #LoadModuleperl_modulemodules/mod_perl.so 23. 24. DocumentRoot/usr/local/apache/htdocs 25. 26. 27. OptionsExecCGIFollowSymLinksIncludesIncludesNOEXEC-Indexes-MultiViewsSymLinksIfOwnerMatch 28. Orderallow,deny 29. Allowfromall 30. AllowOverrideAll 31. 32. 33. 34. OptionsIncludes-IndexesFollowSymLinks 35. AllowOverrideNone 36. Orderallow,deny 37. Allowfromall 38. 39. 40. DefaultTypetext/plain 41. RewriteEngineon 42. AddTypetext/html.shtml 43. AddHandlercgi-script.cgi.pl.plx.ppl.perl 44. AddHandlerserver-parsed.shtml 45. 46. 47. TypesConfigconf/mime.types 48. AddTypeapplication/perl.pl.plx.ppl.perl 49. AddTypeapplication/x-img.img 50. AddTypeapplication/x-httpd-php.php.php3.php4.php5.php6 51. AddTypeapplication/x-httpd-php-source.phps 52. AddTypeapplication/cgi.cgi 53. AddTypetext/x-sql.sql 54. AddTypetext/x-log.log 55. AddTypetext/fconf 56. AddTypetext/x-registry.reg 57. AddTypeapplication/x-compress.Z 58. AddTypeapplication/x-gzip.gz.tgz 59. AddTypetext/html.shtml 60. AddTypeapplication/x-tar.tgz 61. AddTypeapplication/rar.rar 62. AddTypeapplication/x-compressed.rar 63. AddTypeapplication/x-rar.rar 64. AddTypeapplication/x-rar-compressed.rar 65. AddTypetext/vnd.wap.wml.wml 66. AddTypeimage/vnd.wap.wbmp.wbmp 67. AddTypetext/vnd.wap.wmlscript.wmls 68. AddTypeapplication/vnd.wap.wmlc.wmlc 69. AddTypeapplication/vnd.wap.wmlscriptc.wmlsc 70. 71. 72. 73. DirectoryIndexindex.htmlindex.htmindex.shtmlindex.php 74. 75. 76. 77. Orderallow,deny 78. Denyfromall 79. 80. SatisfyAll 81. 82. 83. 84. Orderallow,deny 85. Denyfromall 86. SatisfyAll 87. 88. 89. ErrorLoglogs/error_log 90. LogLevelwarn 91. 92. 93. LogFormat%h%l%u%t%r%s%b%Refereri%User-Agenticombined 94. LogFormat%h%l%u%t%r%s%bcommon 95. 96. 97. 98. LogFormat%h%l%u%t%r%s%b%Refereri%User-Agenti%I%Ocombinedio 99. 100. CustomLoglogs/access_logcommon 101. 102. 103. 104. ScriptAlias/cgi-bin/usr/local/apache/cgi-bin/ 105. 106. 107. 108. AllowOverrideNone 109. OptionsNone 110. Orderallow,deny 111. Allowfromall 112. 113. 114. 115. StartServers3 116. MinSpareServers3 117. MaxSpareServers5 118. MaxClients150 119. MaxRequestsPerChild1024 120. 121. 122. 123. 124. 125. HeadersetCache-Controlmax-age=3600,must-revalidate 126. 127. 128. 129. ReadmeNameREADME.html 130. HeaderNameHEADER.html 131. 132. IndexIgnore.?*#HEADER*README*RCSCVS*,v*,t 133. 134. Includeconf/extra/httpd-languages.conf 135. 136. 137. SetHandlerserver-status 138. Orderdeny,allow 139. Denyfromall 140. Allowfrom 141. 142. ExtendedStatusOn 143. 144. 145. SetHandlerserver-info 146. Orderdeny,allow 147. Denyfromall 148. Allowfrom 149. 150. 151. 152. 153. Listen:443 154. AddTypeapplication/x-x509-ca-cert.crt 155. AddTypeapplication/x-pkcs7-crl.crl 156. SSLCipherSuiteALL:!ADH:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP 157. SSLPassPhraseDialogbuiltin 158. SSLSessionCachedbm:/usr/local/apache/logs/ssl_scache 159. SSLSessionCacheTimeout300 160. SSLMutexfile:/usr/local/apache/logs/ssl_mutex 161. SSLRandomSeedstartupbuiltin 162. SSLRandomSeedconnectbuiltin 163. 164. 165. #Vhosts 166. NameVirtualHost:81 167. 168. 169. ServerAdminking_819163.com 170. DocumentRoot/data/www/kerry 171. ServerN 172. ErrorLoglogs/kerry-error_log 173. CustomLog|/usr/local/apache/bin/rotatelogs/data/logs/kerry/%y_%m_%d.access_log86400common 174. 175. 176. ServerAdminking_819163.com 177. DocumentRoot/data/www/king 178. ServerN 179. ErrorLoglogs/king-error_log 180. CustomLog|/usr/local/apache/bin/rotatelogs/data/logs/king/%y_%m_%d.access_log86400common 181. 182. chmod 700 /etc/init.d/httpd/etc/init.d/httpd start/sbin/chkconfig -add httpd/sbin/chkconfig -level 2345 httpd on#- 编译安装PHP -#编译安装相关支持库cd /opttar -zxvf libiconv-1.13.1.tar.gzcd libiconv-1.13.1/./configuremake;make installcd /opttar -jxvf libmcrypt-2.5.8.tar.bz2cd libmcrypt-2.5.8/./configuremake;make install/sbin/ldconfigcd libltdl/./configure -enable-ltdl-installmake;make installcd /opttar -jxvf mhash-.tar.bz2cd mhash-/./configuremake;make installln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1cd /opttar -zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8/sbin/ldconfig./configuremake;make install#编译php,这里我们为php打入补丁.有助于防止邮件发送被滥用(多用户)以及在邮件中提供有价值的信息.补丁介绍信息请点击:http:/www.lancs.ac.uk/steveb/patches/php-mail-header-patch/cd /opttar -jxvf php-5.2.17.tar.gzpatch -d php-5.2.17 -p1 php5-mail-header.patchcd php-5.2.17./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-discard-path -enable-safe-mode -enable-bcmath -enable-shmop -enable-sysvsem -enable-inline-optimization -with-curl -with-curlwrappers -enable-mbregex -enable-force-cgi-redirect -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-soapmake ZEND_EXTRA_LIBS=-liconvmake installcp php.ini-dist /usr/local/php/etc/php.ini#安装php扩展模块cd /opttar -zxvf me

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论