聆听未来

拥抱开源,无私分享,相互学习,共同进步!!

  • 博客访问: 711142
  • 博文数量: 133
  • 博客积分: 1991
  • 博客等级: 上尉
  • 技术积分: 4462
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-23 21:28
文章分类

全部博文(133)

文章存档

2012年(125)

2011年(8)

微信关注

IT168企业级官微



微信号:IT168qiye



系统架构师大会



微信号:SACC2013

订阅
热词专题

分类: 系统运维

     apache官方宣称apache 2.4在性能上提升了很多,所以就把第一版的LNAMP进行了升级,nginx、apache、mysql、php全部采用最新版本,php 5.4有很多扩展没有跟进,这个是比较大的遗憾,比如:Zend Guard Loade、accelerator、Suhosin
 
一、系统初始化

点击(此处)折叠或打开

  1. chmod +x /opt/init_system.sh
  2. /opt/init_system.sh
二、更新组件
#yum源修改

点击(此处)折叠或打开

  1. cd /etc/yum.repos.d/
  2. mv CentOS-Base.repo CentOS-Base.repo.backup
  3. wget http://mirrors.163.com/.help/CentOS5-Base-163.repo
  4. yum makecache

点击(此处)折叠或打开

  1. yum -y install gcc gcc-c++ bison patch unzip mlocate flex wget automake autoconf gd cpp gettext readline-devel libjpeg \
  2. libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 \
  3. glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel libidn libidn-devel openldap \
  4. openldap-devel openldap-clients openldap-servers nss_ldap expat-devel libtool libtool-ltdl-devel bison

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

点击(此处)折叠或打开

  1. cd /opt
  2. tar -zxvf libunwind-1.0.1.tar.gz
  3. cd libunwind-1.0.1
  4. ./configure
  5. make;make install

  6. cd ../
  7. tar -zxvf gperftools-2.0.tar.gz
  8. cd gperftools-2.0
  9. ./configure
  10. make;make install
  11. echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  12. /sbin/ldconfig

  13. cd ../
  14. tar -zxvf cmake-2.8.8.tar.gz
  15. cd cmake-2.8.8
  16. ./bootstrap
  17. gmake
  18. gmake install
  19. cd ../

  20. /usr/sbin/groupadd mysql
  21. /usr/sbin/useradd -g mysql mysql -s /sbin/nologin
  22. mkdir -p /data/mysql/{data,binlog,relaylog,mysql}
  23. chown -R mysql:mysql /data/mysql
  24. cd /opt
  25. tar zxvf mysql-5.5.23.tar.gz
  26. cd mysql-5.5.23/
  27. rm -rf CMakeCache.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;make install

  40. chmod +w /usr/local/mysql
  41. chown -R mysql: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
/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
 
#或者通sed添加
sed -i '/# executing mysqld_safe/a\export LD_PRELOAD=/usr/local/lib/libtcmalloc.so' /usr/local/mysql/bin/mysqld_safe
 
#设置mysql启动文件
cp support-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修改

点击(此处)折叠或打开

  1. sed -i '46 s#basedir=#basedir=/usr/local/mysql#' /etc/rc.d/init.d/mysqld
  2. sed -i '47 s#datadir=#datadir=/data/mysql/data#' /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld
/etc/rc.d/init.d/mysqld start
 
#使用lsof命令查看tcmalloc是否起效(如下图)
/usr/sbin/lsof -n | grep tcmalloc
 
 
#设置mysql开机启动

点击(此处)折叠或打开

  1. /sbin/chkconfig --add mysqld
  2. /sbin/chkconfig --level 2345 mysqld on
  3. ln -s /usr/local/mysql/bin/mysql /sbin/mysql
  4. ln -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中
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
#添加mysql管理帐户
#mysql -h localhost -u root -p753951
#msqyl> use mysql;
#msqyl> grant all on *.* to 'kerry'@'192.168.9.100' identified by '852741';
#msqyl> flush privileges;
#msqyl> exit;
 
#================= Install apache 2.4.2 ==============#
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www -s /sbin/nologin
mkdir -p /data/www/{kerry,king}
mkdir -p /data/logs/{kerry,king}
chown -R www:www /data/www
chown -R www:www /data/logs

cd /opt
wget http://ftp.gnu.org/gnu/libtool/libtool-2.4.2.tar.gz
rpm -e libtool-1.5.22-7.el5_4
tar -zxvf libtool-2.4.2.tar.gz
cd libtool-2.4.2
./configure
make;make install
cd ../
 
tar -jxvf pcre-8.30.tar.bz2
cd pcre-8.30
./configure --prefix=/usr/local/pcre
make;make install
cd ../
 
tar -jxvf httpd-2.4.2.tar.bz2
tar -jxvf httpd-2.4.2-deps.tar.bz2
cd  httpd-2.4.2
 
#隐藏apache版本信息

  1. sed -i 's/#define AP_SERVER_BASEPRODUCT "Apache"/#define AP_SERVER_BASEPRODUCT "Microsoft-IIS 5.0"/' include/ap_release.h
  2. sed -i 's/#define PLATFORM "Unix"/#define PLATFORM "win32"/' os/unix/os.h
./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-pcre=/usr/local/pcre/bin/pcre-config \
--with-mpm=prefork \
--with-ssl=/usr
make;make install
 
#make的时候报错,“/usr/lib/libexpat.so: could not read symbols: File in wrong format”
#解决方法:
\cp /usr/lib64/libexpat.* /usr/lib/
 
#配置自启动文件
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
#在首行#!/bin/sh下添加
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: 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
 
#或者直接使用sed添加

点击(此处)折叠或打开

  1. sed -i '/#!\/bin\/sh/a\# chkconfig: - 85 15\n# description: web server\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/
mv httpd.conf httpd.conf.bak

点击(此处)折叠或打开

  1. cat >> httpd.conf <<EOF
  2. ServerRoot "/usr/local/apache"
  3. Listen 80
  4. Timeout 300
  5. KeepAlive Off
  6. MaxKeepAliveRequests 100
  7. KeepAliveTimeout 5
  8. UseCanonicalName Off
  9. AccessFileName .htaccess
  10. TraceEnable Off
  11. ServerTokens ProductOnly
  12. FileETag None
  13. ServerSignature Off
  14. HostnameLookups Off
  15. # LoadModule foo_module modules/mod_foo.so
  16. #
  17. LoadModule authn_file_module modules/mod_authn_file.so
  18. #LoadModule authn_dbm_module modules/mod_authn_dbm.so
  19. #LoadModule authn_anon_module modules/mod_authn_anon.so
  20. #LoadModule authn_dbd_module modules/mod_authn_dbd.so
  21. #LoadModule authn_socache_module modules/mod_authn_socache.so
  22. LoadModule authn_core_module modules/mod_authn_core.so
  23. LoadModule authz_host_module modules/mod_authz_host.so
  24. LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
  25. LoadModule authz_user_module modules/mod_authz_user.so
  26. #LoadModule authz_dbm_module modules/mod_authz_dbm.so
  27. #LoadModule authz_owner_module modules/mod_authz_owner.so
  28. #LoadModule authz_dbd_module modules/mod_authz_dbd.so
  29. LoadModule authz_core_module modules/mod_authz_core.so
  30. LoadModule access_compat_module modules/mod_access_compat.so
  31. LoadModule auth_basic_module modules/mod_auth_basic.so
  32. #LoadModule auth_form_module modules/mod_auth_form.so
  33. #LoadModule auth_digest_module modules/mod_auth_digest.so
  34. #LoadModule allowmethods_module modules/mod_allowmethods.so
  35. #LoadModule file_cache_module modules/mod_file_cache.so
  36. #LoadModule cache_module modules/mod_cache.so
  37. #LoadModule cache_disk_module modules/mod_cache_disk.so
  38. #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
  39. #LoadModule socache_dbm_module modules/mod_socache_dbm.so
  40. #LoadModule socache_memcache_module modules/mod_socache_memcache.so
  41. #LoadModule dbd_module modules/mod_dbd.so
  42. #LoadModule dumpio_module modules/mod_dumpio.so
  43. #LoadModule buffer_module modules/mod_buffer.so
  44. #LoadModule ratelimit_module modules/mod_ratelimit.so
  45. LoadModule reqtimeout_module modules/mod_reqtimeout.so
  46. #LoadModule ext_filter_module modules/mod_ext_filter.so
  47. #LoadModule request_module modules/mod_request.so
  48. #LoadModule include_module modules/mod_include.so
  49. LoadModule filter_module modules/mod_filter.so
  50. #LoadModule substitute_module modules/mod_substitute.so
  51. #LoadModule sed_module modules/mod_sed.so
  52. #LoadModule deflate_module modules/mod_deflate.so
  53. LoadModule mime_module modules/mod_mime.so
  54. LoadModule log_config_module modules/mod_log_config.so
  55. #LoadModule log_debug_module modules/mod_log_debug.so
  56. #LoadModule logio_module modules/mod_logio.so
  57. LoadModule env_module modules/mod_env.so
  58. #LoadModule mime_magic_module modules/mod_mime_magic.so
  59. #LoadModule expires_module modules/mod_expires.so
  60. LoadModule headers_module modules/mod_headers.so
  61. #LoadModule unique_id_module modules/mod_unique_id.so
  62. LoadModule setenvif_module modules/mod_setenvif.so
  63. LoadModule version_module modules/mod_version.so
  64. #LoadModule remoteip_module modules/mod_remoteip.so
  65. LoadModule proxy_module modules/mod_proxy.so
  66. LoadModule proxy_connect_module modules/mod_proxy_connect.so
  67. LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
  68. LoadModule proxy_http_module modules/mod_proxy_http.so
  69. LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
  70. LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
  71. LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
  72. #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
  73. LoadModule proxy_express_module modules/mod_proxy_express.so
  74. #LoadModule session_module modules/mod_session.so
  75. #LoadModule session_cookie_module modules/mod_session_cookie.so
  76. #LoadModule session_dbd_module modules/mod_session_dbd.so
  77. #LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
  78. #LoadModule ssl_module modules/mod_ssl.so
  79. LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
  80. LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
  81. LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
  82. LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
  83. LoadModule unixd_module modules/mod_unixd.so
  84. #LoadModule dav_module modules/mod_dav.so
  85. LoadModule status_module modules/mod_status.so
  86. LoadModule autoindex_module modules/mod_autoindex.so
  87. #LoadModule info_module modules/mod_info.so
  88. #LoadModule suexec_module modules/mod_suexec.so
  89. #LoadModule cgi_module modules/mod_cgi.so
  90. #LoadModule dav_fs_module modules/mod_dav_fs.so
  91. LoadModule vhost_alias_module modules/mod_vhost_alias.so
  92. #LoadModule negotiation_module modules/mod_negotiation.so
  93. LoadModule dir_module modules/mod_dir.so
  94. #LoadModule actions_module modules/mod_actions.so
  95. #LoadModule speling_module modules/mod_speling.so
  96. #LoadModule userdir_module modules/mod_userdir.so
  97. LoadModule alias_module modules/mod_alias.so
  98. LoadModule rewrite_module modules/mod_rewrite.so
  99. <IfModule unixd_module>
  100. User www
  101. Group www
  102. </IfModule>
  103. ServerAdmin king_819@163.com
  104. <Directory />
  105. AllowOverride none
  106. Require all denied
  107. </Directory>
  108. DocumentRoot "/usr/local/apache/htdocs"
  109. <Directory "/usr/local/apache/htdocs">
  110. Options Indexes FollowSymLinks
  111. AllowOverride None
  112. Require all granted
  113. </Directory>
  114. <IfModule dir_module>
  115. DirectoryIndex index.html index.php
  116. </IfModule>
  117. <Files ".ht*">
  118. Require all denied
  119. </Files>
  120. ErrorLog "logs/error_log"
  121. LogLevel warn
  122. <IfModule log_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. <IfModule logio_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. <IfModule alias_module>
  131. ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
  132. </IfModule>
  133. <IfModule cgid_module>
  134. #Scriptsock logs/cgisock
  135. </IfModule>
  136. <Directory "/usr/local/apache/cgi-bin">
  137. AllowOverride None
  138. Options None
  139. Require all granted
  140. </Directory>
  141. RewriteEngine on
  142. <IfModule mime_module>
  143. TypesConfig conf/mime.types
  144. AddType application/x-compress .Z
  145. AddType application/x-gzip .gz .tgz
  146. AddType application/x-httpd-php .php .php3 .php4 .php5 .php6
  147. AddType application/x-httpd-php-source .phps
  148. </IfModule>
  149. # Server-pool management (MPM specific)
  150. Include conf/extra/httpd-mpm.conf
  151. # Virtual hosts
  152. Include conf/extra/httpd-vhosts.conf
  153. # Configure mod_proxy_html to understand HTML4/XHTML1
  154. <IfModule proxy_html_module>
  155. Include conf/extra/proxy-html.conf
  156. </IfModule>
  157. # Secure (SSL/TLS) connections
  158. #Include conf/extra/httpd-ssl.conf
  159. <IfModule ssl_module>
  160. SSLRandomSeed startup builtin
  161. SSLRandomSeed connect builtin
  162. </IfModule>
  163. EOF

#配置mpm_prefork_module
mv extra/httpd-mpm.conf extra/httpd-mpm.conf.bak

点击(此处)折叠或打开

  1. cat >> extra/httpd-mpm.conf <<EOF
  2. <IfModule mpm_prefork_module>
  3. ServerLimit 10000
  4. StartServers 5
  5. MinSpareServers 5
  6. MaxSpareServers 10
  7. MaxRequestWorkers 10000
  8. MaxConnectionsPerChild 10000
  9. </IfModule>
  10. EOF

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

点击(此处)折叠或打开

  1. cat >> extra/httpd-vhosts.conf <<EOF
  2. #Vhosts
  3. <VirtualHost *:81>
  4. ServerAdmin king_819@163.com
  5. DocumentRoot "/usr/local/apache/htdocs"
  6. <Directory "/usr/local/apache/htdocs">
  7. Options Indexes FollowSymLinks
  8. AllowOverride None
  9. Require all granted
  10. </Directory>
  11. ServerName 127.0.0.1
  12. </VirtualHost>
  13. <VirtualHost *:81>
  14. ServerAdmin king_819@163.com
  15. DocumentRoot "/data/www/kerry"
  16. <Directory "/data/www/kerry">
  17. Options Indexes FollowSymLinks
  18. AllowOverride None
  19. Require all granted
  20. </Directory>
  21. ServerName www.kerry.com
  22. ErrorLog "logs/kerry-error_log"
  23. CustomLog "|/usr/local/apache/bin/rotatelogs /data/logs/kerry/%y_%m_%d.access_log 86400" common
  24. </VirtualHost>
  25. <VirtualHost *:81>
  26. ServerAdmin king_819@163.com
  27. DocumentRoot "/data/www/king"
  28. <Directory "/data/www/king">
  29. Options Indexes FollowSymLinks
  30. AllowOverride None
  31. Require all granted
  32. </Directory>
  33. ServerName www.king.com
  34. ErrorLog "logs/king-error_log"
  35. CustomLog "|/usr/local/apache/bin/rotatelogs /data/logs/king/%y_%m_%d.access_log 86400" common
  36. </VirtualHost>
  37. EOF

#设置apache自启动

点击(此处)折叠或打开

  1. chmod 700 /etc/init.d/httpd
  2. /etc/init.d/httpd start
  3. /sbin/chkconfig --add httpd
  4. /sbin/chkconfig --level 2345 httpd on
  5. cd ../

#=================== Install PHP 5.4.0 ===============#
#编译安装相关支持库
cd /opt
tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure
make;make install
cd ../
 
tar -jxvf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8/
./configure
make;make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make;make install
 
cd /opt
tar -jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9/
./configure
make;make install
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 -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make;make install
 
#编译php,这里我们为php打入补丁.有助于防止邮件发送被滥用(多用户)以及在邮件中提供有价值的信息.补丁介绍信息请点击:http://www.lancs.ac.uk/~steveb/patches/php-mail-header-patch/
cd /opt
tar -jxvf php-5.4.0.tar.gz
patch -d php-5.4.0 -p1 < php5-mail-header.patch
cd php-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
 
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/php/etc/php.ini
cd ../
 
#安装php扩展模块
cd /opt
tar -zxvf memcache-3.0.6.tgz
cd memcache-3.0.6/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir --enable-memcache
make;make install
cd ../
 
#make时出错(如下图)
 

#解决办法:修改memcache.c
将721行:
zend_list_insert(mmc, le_memcache_server);
改为:
zend_list_insert(mmc TSRMLS_CC, le_memcache_server);
将738行:
zend_list_insert(mmc, le_memcache_server);
改为:
zend_list_insert(mmc TSRMLS_CC, le_memcache_server);
将778行:
list_id = zend_list_insert(pool, le_memcache_pool);
改为:
list_id = zend_list_insert(pool TSRMLS_CC, le_memcache_pool);
将839行:
list_id = zend_list_insert(pool TSRMLS_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(mmc TSRMLS_CC, le_memcache_server);#' memcache.c
  2. sed -i 's#list_id = zend_list_insert(pool, le_memcache_pool);#list_id = zend_list_insert(pool TSRMLS_CC, le_memcache_pool);#' memcache.c

#php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached
 
#安装memcached的服务端支持库
cd /opt
tar -xzf libevent-2.0.18-stable.tar.gz
cd libevent-2.0.18-stable
./configure
make;make install
ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib
 
#安装Memcached服务端
cd /opt
tar -xzf memcached-1.4.13.tar.gz
cd memcached-1.4.13
./configure --prefix=/usr/local/memcached --with-libevent=/usr
make;make install
 
cd /opt
tar -zxvf libmemcached-1.0.2.tar.tar
cd libmemcached-1.0.2
./configure --prefix=/usr/local/libmemcached  --with-memcached
 make;make install
 
#安装php的memcached扩展库
cd /opt
tar -zxvf memcached-2.0.1.tgz
cd memcached-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;make install
 
#因eaccelerator-0.9.6.1不支持php 5.4.0,所以就改用XCache 2.0.0
cd /opt
tar -zxvf xcache-2.0.0.tar.gz
cd xcache-2.0.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make;make install
 
#安装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;make install
 
cd /opt
tar -jxvf ImageMagick-6.7.6-7.tar.bz2
cd ImageMagick-6.7.6-7
./configure --prefix=/usr/local/imagemagick
make;make install
 
#imagick最新正式版为imagick-3.0.1.tgz,但imagick-3.0.1.tgz在make的时候会出现大量的报错信息,所以就改用imagick-3.1.0RC1.tgz
cd /opt
tar -zxvf imagick-3.1.0RC1.tgz
cd imagick-3.1.0RC1/
export  PKG_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;make install
 
cd /opt
tar -jxf ioncube_loaders_lin_x86.tar.bz2
cd ioncube
mkdir /usr/local/ioncube
mv ioncube_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版本

点击(此处)折叠或打开

  1. sed -i 's#expose_php = On#expose_php = Off#' /usr/local/php/etc/php.ini
#php安全设置,禁用函数 

点击(此处)折叠或打开

  1. 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/httpd restart

#============= Install Nginx ===================#
cd /opt
tar -zxvf nginx-1.2.0.tar.gz
cd nginx-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;make install
cd ../
 
#添加nginx启动脚本

点击(此处)折叠或打开

  1. cat >> /etc/init.d/nginx <<EOF
  2. #! /bin/sh
  3. ulimit -n 65535
  4. # Description: Startup script for nginx
  5. # chkconfig: 2345 55 25
  6. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  7. DESC="nginx daemon"
  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" ] || exit 0
  15. do_start() {
  16. $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
  17. }
  18. do_stop() {
  19. kill -QUIT `cat $PIDFILE` || echo -n "nginx not running"
  20. }
  21. do_reload() {
  22. kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
  23. }
  24. case "$1" in
  25. start)
  26. echo -n "Starting $DESC: $NAME"
  27. do_start
  28. echo "."
  29. /etc/init.d/httpd start
  30. ;;
  31. stop)
  32. echo -n "Stopping $DESC: $NAME"
  33. do_stop
  34. echo "."
  35. /etc/init.d/httpd stop
  36. ;;
  37. reload)
  38. echo -n "Reloading $DESC configuration..."
  39. do_reload
  40. echo "."
  41. /etc/init.d/httpd restart
  42. ;;
  43. restart)
  44. echo -n "Restarting $DESC: $NAME"
  45. do_stop
  46. sleep 1
  47. do_start
  48. echo "."
  49. /etc/init.d/httpd restart
  50. ;;
  51. *)
  52. echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
  53. exit 3
  54. ;;
  55. esac
  56. exit 0
  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. user www www;
  3. worker_processes 8;
  4. error_log /usr/local/nginx/logs/nginx_error.log crit;
  5. pid /usr/local/nginx/logs/nginx.pid;
  6. #使用Tcmalloc优化nginx性能
  7. google_perftools_profiles /var/tmp/tcmalloc;
  8. #Specifies the value for maximum file descriptors that can be opened by this process.
  9. worker_rlimit_nofile 65535;
  10. #工作模式及连接数上限
  11. events
  12. {
  13. use epoll;
  14. worker_connections 65535;
  15. }
  16. #设定http服务器,利用它的反向代理功能提供负载均衡支持
  17. http
  18. {
  19. #设定mime类型
  20. include mime.types;
  21. default_type application/octet-stream;
  22. #charset gb2312;
  23. #设定请求缓冲
  24. server_names_hash_bucket_size 128;
  25. client_header_buffer_size 32k;
  26. large_client_header_buffers 4 32k;
  27. client_max_body_size 30m;
  28. sendfile on;
  29. tcp_nopush on;
  30. keepalive_timeout 60;
  31. tcp_nodelay on;
  32. server_tokens off;
  33. client_body_buffer_size 512k;
  34. proxy_connect_timeout 5;
  35. proxy_send_timeout 60;
  36. proxy_read_timeout 5;
  37. proxy_buffer_size 16k;
  38. proxy_buffers 4 64k;
  39. proxy_busy_buffers_size 128k;
  40. proxy_temp_file_write_size 128k;
  41. # fastcgi_connect_timeout 300;
  42. # fastcgi_send_timeout 300;
  43. # fastcgi_read_timeout 300;
  44. # fastcgi_buffer_size 64k;
  45. # fastcgi_buffers 4 64k;
  46. # fastcgi_busy_buffers_size 128k;
  47. # fastcgi_temp_file_write_size 128k;
  48. gzip on;
  49. gzip_min_length 1k;
  50. gzip_buffers 4 16k;
  51. gzip_http_version 1.1;
  52. gzip_comp_level 2;
  53. gzip_types text/plain application/x-javascript text/css application/xml;
  54. gzip_vary on;
  55. #limit_zone crawler $binary_remote_addr 10m;
  56. #定义访问日志的写入格式
  57. log_format wwwlog '$remote_addr - $remote_user [$time_local] "$request" '
  58. '$status $body_bytes_sent "$http_referer" '
  59. '"$http_user_agent" $http_x_forwarded_for';
  60. log_format bbslog '$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. return 404;
  67. }
  68. server
  69. {
  70. listen 80;
  71. server_name www.kerry.com;
  72. index index.html index.htm index.php;#设定访问的默认首页地址
  73. root /data/www/kerry;#设定网站的资源存放路径
  74. #limit_conn crawler 20;
  75. if (-d $request_filename)
  76. {
  77. rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  78. }
  79. #所有jsp的页面均交由tomcat处理
  80. location ~ \.(php)?$ {
  81. proxy_set_header Host $host;
  82. proxy_set_header X-Real-IP $remote_addr;
  83. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  84. proxy_pass http://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. expires 30d;
  89. }
  90. location ~ .*\.(js|css)?$
  91. {
  92. expires 1h;
  93. }
  94. access_log /data/logs/kerry/kerry_nginx.log wwwlog;#设定访问日志的存放路径
  95. }
  96. server
  97. {
  98. listen 80;
  99. server_name www.king.com;
  100. index index.html index.htm index.php;#设定访问的默认首页地址
  101. root /data/www/king;#设定网站的资源存放路径
  102. #limit_conn crawler 20;
  103. if (-d $request_filename)
  104. {
  105. rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  106. }
  107. #所有jsp的页面均交由tomcat处理
  108. location ~ \.(php)?$ {
  109. proxy_set_header Host $host;
  110. proxy_set_header X-Real-IP $remote_addr;
  111. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  112. proxy_pass http://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. expires 30d;
  117. }
  118. location ~ .*\.(js|css)?$
  119. {
  120. expires 1h;
  121. }
  122. access_log /data/logs/king/king_nginx.log bbslog;#设定访问日志的存放路径
  123. }
  124. server
  125. {
  126. listen 80;
  127. server_name status.www.kerry.com;
  128. location / {
  129. stub_status on;
  130. access_log off;
  131. }
  132. }
  133. }
  134. EOF

#将nginx添加到启动服务中
chmod 700 /etc/init.d/nginx
/etc/init.d/nginx start
/sbin/chkconfig --add nginx
/sbin/chkconfig --level 2345 nginx on

#每天定时切割Nginx日志

点击(此处)折叠或打开

  1. cat >> /usr/local/nginx/sbin/cut_nginx_log.sh <<EOF
  2. #!/bin/bash
  3. # This script run at 00:00
  4. # The Nginx logs path
  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
00 00 * * * /bin/bash  /usr/local/nginx/sbin/cut_nginx_log.sh
 
#为apache安装rpaf模块,该模块用于apache做后端时获取访客真实的IP
#使用apxs安装模块.这里要使用此前apache编译安装后的apxs
cd /opt
tar -zxf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
/usr/local/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
#错误提示:
mod_rpaf-2.0.c: In function 'rpaf_cleanup':
mod_rpaf-2.0.c:150: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:151: error: 'conn_rec' has no member named 'remote_addr'
mod_rpaf-2.0.c:151: warning: implicit declaration of function 'inet_addr'
mod_rpaf-2.0.c:151: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c: In function 'change_remote_ip':
mod_rpaf-2.0.c:164: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:183: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:186: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:187: error: 'conn_rec' has no member named 'remote_addr'
mod_rpaf-2.0.c:187: error: 'conn_rec' has no member named 'remote_ip'
apxs:Error: Command failed with rc=65536
 
 
#解决办法:
#http://httpd.apache.org/docs/trunk/developer/new_api_2_4.html
 

#将150、151、164、183、186、187这几行的remote_ip修改成client_ip,remote_addr修改成client_addr
#编辑/usr/local/apache/conf/httpd.conf,添加模块参数,查找LoadModule php5_module modules/libphp5.so,在下方添加:
 

点击(此处)折叠或打开

  1. LoadModule rpaf_module modules/mod_rpaf-2.0.so
  2. #Mod_rpaf settings
  3. RPAFenable On
  4. #上面出现的192.168.9.9请修改为你本机所监听web服务的ip.多个IP用空格空开
  5. RPAFproxy_ips 127.0.0.1 192.168.9.9
  6. RPAFsethostname On
  7. RPAFheader X-Forwarded-For
阅读(5164) | 评论(1) | 转发(7) |
给主人留下些什么吧!~~

ops9112014-04-17 17:12:44

谢谢博主无私分享

评论热议
请登录后评论。

登录 注册