说明:

1.官网采用LAMP框架,nginx做前端轮询代理

2、移除系统自带的rpm包的http mysql php

yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd  -y

3 安装必备的开发包

/usr/bin/yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel \

ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel \

gettext-devel  pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel \

libxml2-devel curl-devel  libicu libicu-devel libmcrypt libmcrypt-devel libmhash  libxml2 \

libmhash-devel  mysql-devel   libxslt libxslt-devel curl tcl expect

4.同步系统时间:

vim /etc/ntp.conf

server 3.cn.pool.ntp.org

server 3.asia.pool.ntp.org

server 0.asia.pool.ntp.org

chkconfig ntpd on

service ntpd restart

5.IP分配

    nginx:192.168.201.4  192.168.201.5  192.168.201.6  192.168.201.7  

    apache:192.168.201.123---192.168.201.138

  1. 一.nginx搭建

  2. 1.下载源码包nginx-1.4.2

  3. 2.安装nginx

  4. ./configuer  --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module & make & make install

  5. 3.配置文件如下

  6. user  nobody;

  7. worker_processes  8;

  8. pid               logs/nginx.pid;


  9. events {

  10.         use epoll;

  11.         worker_connections  65535;

  12.         }


  13. http {


  14. #       设置一个共享内存区域reqnum,以用于限制每个客户端IP可以并发连接的请求数

  15. #        limit_conn_zone $binary_remote_addr zone=reqnum:10m;

  16. #       每个客户端IP每分钟只允许5个连接

  17. #        limit_req_zone $binary_remote_addr zone=reqone:10m rate=10r/m;

  18.         include       mime.types;

  19.         default_type  application/octet-stream;


  20.         sendfile              on;  

  21.         tcp_nopush            on;   

  22.         tcp_nodelay           on; 

  23.         keepalive_timeout     60; 

  24.         server_tokens         off;


  25.         log_format    wwwlog  '$remote_addr - $remote_user [$time_local] "$request" '              

  26.                               '$status $body_bytes_sent "$http_referer" '             

  27.                               '"$http_user_agent" $http_x_forwarded_for';    

  28.         access_log    /usr/local/nginx/logs/access.log wwwlog;


  29.         gzip                    on; 

  30.         gzip_min_length         1k; 

  31.         gzip_buffers            4 16k; 

  32.         gzip_http_version       1.1; 

  33.         gzip_comp_level         3; 

  34.         gzip_types              text/plain application/x-javascript text/css applicati

  35. on/xml; 

  36.         gzip_vary on;


  37.         server_names_hash_bucket_size   128;   

  38.         client_header_buffer_size       32k;  

  39.         client_max_body_size            300m; 

  40.         client_body_buffer_size         512k; 

  41.         large_client_header_buffers     4   32k;  


  42.         proxy_connect_timeout           60; 

  43.         proxy_send_timeout              120; 

  44.         proxy_read_timeout              120; 

  45.         proxy_buffer_size               16k; 

  46.         proxy_buffers                   4   64k; 

  47.         proxy_busy_buffers_size         128k; 

  48.         proxy_temp_file_write_size      128k; 


  49.         index           index.php  index.htm index.html default.php default.htm defaul

  50. t.html index.php3;


  51. upstream os_server {

  52. #                       ip_hash;

  53. #                       server 192.168.201.122:80 weight=1;

  54.                         server 192.168.201.123:80 weight=1;

  55.                         server 192.168.201.124:80 weight=1;

  56.                         server 192.168.201.125:80 weight=1;

  57.                         server 192.168.201.126:80 weight=1;

  58.                         server 192.168.201.127:80 weight=1;

  59.                         server 192.168.201.128:80 weight=1;

  60.                         server 192.168.201.129:80 weight=1;

  61.                         server 192.168.201.130:80 weight=1;

  62.                         server 192.168.201.131:80 weight=1;

  63.                         server 192.168.201.132:80 weight=1;

  64.                         server 192.168.201.133:80 weight=1;

  65.                         server 192.168.201.134:80 weight=1;

  66.                         server 192.168.201.136:80 weight=1;

  67.                         server 192.168.201.137:80 weight=1;

  68.                         server 192.168.201.138:80 weight=1;

  69.                                      }  

  70. upstream m_server {

  71. #                       ip_hash;

  72. #                       server 192.168.201.122:80 weight=1;

  73.                         server 192.168.201.123:80 weight=1;

  74.                         server 192.168.201.124:80 weight=1;

  75.                         server 192.168.201.125:80 weight=1;

  76.                         server 192.168.201.126:80 weight=1;

  77.                         server 192.168.201.127:80 weight=1;

  78.                         server 192.168.201.128:80 weight=1;

  79.                         server 192.168.201.129:80 weight=1;

  80.                         server 192.168.201.130:80 weight=1;

  81.                         server 192.168.201.131:80 weight=1;

  82.                         server 192.168.201.132:80 weight=1;

  83.                         server 192.168.201.133:80 weight=1;

  84.                         server 192.168.201.134:80 weight=1;

  85.                         server 192.168.201.136:80 weight=1;

  86.                         server 192.168.201.137:80 weight=1;

  87.                         server 192.168.201.138:80 weight=1;

  88.                         }

  89. upstream weixin_server {

  90. #                       ip_hash;

  91.                         server 192.168.201.35:80 weight=1;

  92.                         server 192.168.201.34:80 weight=1;

  93.                         }


  94. upstream op_server {    

  95. #                       ip_hash;

  96.                         server 192.168.201.35:80 weight=1;

  97. #                       server 192.168.201.34:80 weight=1;

  98.                         }

  99. #---------------------------www.lqxshop.com-----------------------

  100. server {

  101.          listen 80;

  102.          server_name    www.shop.com www.ilqx.cn www.chenggongfang.com wx.lqxshop.c

  103. om;

  104.          #限制每个连接的带宽大小

  105.          #limit_rate 40k;

  106.          #限制每个客户端ip在指定时间内容允许连接的请求数,且超过限制连接频率的连接数不

  107. 得超过burst指定

  108.          #limit_req zone=reqone burst=50;

  109.          #使用前面定义的共享内存区域,限制每个客户端IP并发连接的最大数

  110.          #limit_conn    reqnum   20;

  111. location / {

  112.              proxy_set_header HTTP_REFERER  $http_referer;

  113.              proxy_pass http://os_server;

  114.              proxy_set_header Host   $host;

  115.              proxy_set_header X-Real-IP      $remote_addr;

  116.              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  117.              index  index.html index.php index.htm index.jsp;

  118.            }

  119. }


  120. #--------------------------------m.lqxshop.com----------------------

  121. server {

  122.          listen 80;

  123.          #限制每个连接的带宽大小

  124.          #limit_rate 40k;

  125.          #限制每个客户端ip在指定时间内容允许连接的请求数,且超过限制连接频率的连接数不

  126. 得超过burst指定

  127.          #limit_req zone=reqone burst=50;

  128.          #使用前面定义的共享内存区域,限制每个客户端IP并发连接的最大数

  129.          #limit_conn    reqnum   20;

  130.          server_name    m.shop.com m1.shop.com m2.shop.com;

  131. location / {

  132.              proxy_pass http://m_server;

  133.              proxy_set_header HTTP_REFERER  $http_referer;

  134.              proxy_set_header Host   $host;

  135.              proxy_set_header X-Real-IP      $remote_addr;

  136.              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  137.              index  index.html index.htm index.jsp;

  138.   }

  139. }


  140. #--------------------------------weixin.lqxshop.com----------------------

  141. server {

  142.          listen 80;

  143.           #限制每个连接的带宽大小

  144.           #limit_rate 40k;

  145.           #限制每个客户端ip在指定时间内容允许连接的请求数,且超过限制连接频率的连接数

  146. 得超过burst指定

  147.           #limit_req zone=reqone burst=50;

  148.           #使用前面定义的共享内存区域,限制每个客户端IP并发连接的最大数

  149.          #limit_conn    reqnum   20;

  150.          server_name    weixin.shop.com;

  151. location / {

  152.              proxy_pass http://weixin_server;

  153.              proxy_set_header HTTP_REFERER  $http_referer;

  154.              proxy_set_header Host   $host;

  155.              proxy_set_header X-Real-IP      $remote_addr;

  156.              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  157.              index  index.html index.htm index.jsp;

  158.   }

  159. }



  160. #--------------------------------op.lqxshop.com----------------------

  161. server {

  162.          listen 80;

  163.           #限制每个连接的带宽大小

  164.          #limit_rate 30k;

  165.           #限制每个客户端ip在指定时间内容允许连接的请求数,且超过限制连接频率的连接数

  166. 得超过burst指定

  167.           #limit_req zone=reqone burst=50;

  168.            #使用前面定义的共享内存区域,限制每个客户端IP并发连接的最大数

  169.          #limit_conn    reqnum   20;

  170.          server_name    op.shop.com;

  171. location / {

  172.              proxy_pass http://op_server;

  173.              proxy_set_header HTTP_REFERER  $http_referer;

  174.              proxy_set_header Host   $host;

  175.              proxy_set_header X-Real-IP      $remote_addr;

  176.              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  177.              index  index.html index.htm index.jsp;

  178.   }

  179. }


  180. }



  181. 二.APP(Apache+php)搭建

  182. 1、移除系统自带的rpm包的http mysql php

  183. yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd  -y

  184. 2 安装必备的开发包

  185. /usr/bin/yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel \

  186. ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel \

  187. gettext-devel  pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel \

  188. libxml2-devel curl-devel  libicu libicu-devel libmcrypt libmcrypt-devel libmhash  libxml2 \

  189. libmhash-devel  mysql-devel   libxslt libxslt-devel curl tcl expect

    3.同步系统时间:

  190. vim /etc/ntp.conf

  191. server 3.cn.pool.ntp.org

  192. server 3.asia.pool.ntp.org

  193. server 0.asia.pool.ntp.org

  194. chkconfig ntpd on

  195. service ntpd restart

  196. 4.安装Apache:

  197. ##############安装需要的插件:apr、apr-util、pcre、libmcrypt######################################

  198. cd /usr/local/src/

  199. cd apr-1.4.8################(rm: cannot remove `libtoolT': No such file or directory///////修改configure文件,+++++把RM='$RM'改为RM='$RM  -f'+++++)

  200. ./configure --prefix=/usr/local/apr && make && make install

  201. cd ../apr-util-1.5.2/

  202. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ && make && make install

  203. cd ../pcre-8.33/

  204. ./configure --prefix=/usr/local/pcre --enable-utf8 && make && make install

  205. cd ../libmcrypt-2.5.8/

  206. ./configure --prefix=/usr/local/libmcrypt && make && make install

  207. ###################开始安装Apache,并修改开启启动##################################################

  208. cd ../httpd-2.4.6/

  209. ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-mods-shared=most --with-mpm=worker --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/

  210. make && make install 

  211. /usr/local/apache/bin/apachectl start

  212. cp /usr/local/apache/bin/apachectl  /etc/init.d/httpd

  213. vim /etc/init.d/httpd(第二行添加注释信息,添加为系统服务)

  214. # chkconfig: 35 61 61

  215. # description: Apache

  216. chkconfig --add httpd

  217. chkconfig httpd on

  218. 5.安装php:

  219. cd ../php-5.5.3/

  220. ./configure --prefix=/usr/local/php --mandir=/usr/local/share/man --infodir=/usr/local/share/info --with-apxs2=/usr/local/apache/bin/apxs --enable-cgi --with-mysql --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-mysqli --enable-zip  -enable-sockets --enable-soap --enable-pcntl --enable-mbstring --enable-intl --enable-calendar --enable-bcmath --enable-exif --with-mcrypt --with-mhash --with-gd --with-png-dir --with-jpeg-dir --with-freetype-dir --with-libxml-dir --with-curl --with-zlib   --with-openssl --with-kerberos=shared --with-gettext=shared --with-xmlrpc=shared --with-mcrypt=/usr/local/libmcrypt 

  221. make && make install


  222. 装载XXX模块 



  223. cd /usr/local/httpd-2.2.22/modules/generators/

  224. /usr/local/apache/bin/apxs -i -a -c mod_cgi.c


  225. 6.apache和php结合:

  226. vim /usr/local/apache/conf/httpd.conf

  227. 查找AddType application/x-gzip .gz .tgz,在该行下面添加

  228. AddType application/x-httpd-php .php

  229. 查找DirectoryIndex index.html 把该行修改成

  230. DirectoryIndex index.html index.htm index.php

  231. 测试apache和php是否整合成功,下面我们测试apache和php是否整合成功,在apache文档跟目录下新建一个小小的php程序

  232. cd /usr/local/apache/htdocs

  233. vi index.php  //在index.php文件中写入下面三行

  234. <?php

  235. phpinfo();

  236. ?>

  237. 重启apache服务

  238. /sbin/service  httpd restart

  239. 访问,在浏览器中输入http://localhost(ip地址)/index.php 出现php信息界面则说明整合成功

  240. elinks http://localhost/index.php

  241. 成功的页面



  1. 三.mysql搭建


  2. 10    11

  3. 软件源代码包存放位置               /opt

  4. 软件解压位置   /usr/local/src

  5. 源码包编译安装位置(prefix)         /usr/local/

  6. 脚本以及维护程序存放位置           /script

  7. 数据库文件位置:           /data/mysql/

  8. 数据库日志位置:   /data/log

  9. 数据库备份目录:   /data/backup


  10. 1.卸载默认的mysql及apache的rpm包

  11. yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd  -y

  12. yum install ntp

  13. service ntpd stop

  14. ntpdate cn.pool.ntp.org

  15. service ntpd start

  16. chkconfig --level 2345 ntpd on


  17. 2.安装依赖包

  18. yum install gcc gcc-c++ make cmake ncurses-devel vim -y

  19. cd /opt

  20.  tar zxvf cmake-2.8.5.tar.gz -C /usr/local/src

  21.  cd /usr/local/src

  22. cd cmake-2.8.5/

  23. ./configure

  24. make && make install

  25. cd /opt


  26. 3.编译安装mysql

  27. tar zxvf mysql-5.5.23.tar.gz -C /usr/local/src/

  28. cd /usr/local/src/mysql-5.5.23

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

  30.          -DMYSQL_DATADIR=/data/mysql \

  31.          -DWITH_MYISAM_STORAGE_ENGINE=1 \

  32.          -DWITH_INNOBASE_STORAGE_ENGINE=1 \

  33.          -DWITH_ARCHIVE_STORAGE_ENGINE=1 \

  34.          -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

  35.          -DENABLED_LOCAL_INFILE=1 \

  36.          -DDEFAULT_CHARSET=utf8 \

  37.          -DDEFAULT_COLLATION=utf8_general_ci \

  38.          -DEXTRA_CHARSETS=all  

  39.   make && make install

  40. groupadd -r -g 3306 mysql

  41. useradd -u 3306 -g mysql -r -M -s /sbin/nologin mysql

  42. mkdir -p /data/mysql/

  43. mkdir -p /data/log/

  44. chown -R mysql:mysql /data/

  45. chown -R mysql:mysql /usr/local/mysql/*

  46. cp support-files/my-huge.cnf /etc/my.cnf 


  47. 4.初始化

  48. /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql &   //初始化数据库


  49. 5.启动项

  50. cp support-files/mysql.server /etc/init.d/mysqld

  51. chmod +x /etc/init.d/mysqld

  52. /chkconfig --add mysqld

  53. chkconfig  --level 2345 mysqld on

  54. service  mysqld start

  55. netstat -tnlp |grep 3306


  56. 6.相关命令

  57. # cd /usr/local/bin //进入用户的默认搜索路径下建立mysql命令的软连接,可以直接执行mysql命令

  58.  #  ln -s /usr/local/mysql/bin/mysql mysql

  59.  #  ln -s /usr/local/mysql/bin/mysqldump mysqldump

  60.  #  ln -s /usr/local/mysql/bin/mysqladmin  mysqladmin

  61.  #  ln -s /usr/local/mysql/bin/mysqlbinlog

  62. vim /etc/my.cnf  ,在[mysqld]配置参数下面添加下面几行(大概37行下面),根据服务

  63. skip-external-locking

  64. key_buffer_size = 256M

  65. max_allowed_packet = 500M

  66. table_open_cache = 2048

  67. sort_buffer_size = 8M

  68. read_buffer_size = 4M

  69. read_rnd_buffer_size = 16M

  70. myisam_sort_buffer_size = 128M


  71. ###添加

  72. log-error=/data/log/mysql.err.log 

  73. skip-name-resolv 

  74. max_connections = 3000

  75. max_connect_errors = 2000


  76. slow_query_log

  77. long_query_time = 2

  78. slow_query_log_file = /data/log/slow.log 


  79. bulk_insert_buffer_size = 64M

  80. query_cache_type = 1

  81. query_cache_size =256M

  82. query_cache_limit = 4M

  83. ft_min_word_len = 2

  84. join_buffer_size = 16M

  85. innodb_file_per_table  

  86. log-bin-trust-function-creators=1

  87. myisam_repair_threads = 1

  88. innodb_log_files_in_group = 3

  89. thread_cache_size = 8

  90. # Try number of CPU's*2 for thread_concurrency

  91. thread_concurrency = 8


  92. innodb_buffer_pool_size = 2G //修改这个参数为物理内存的80%


  93. :wq //保存退出

  94. rm -rvf  /data/mysql/ib* myslq-bin* //删除原来的默认文件

  95. service mysqld restart

  96. mysql -u root

  97. Mysql> grant all privileges on *.* to lqx@'%' identified by 'shlqx1!';

  98. Mysql>flush privileges;