centos LAMP环境搭建

前端之家收集整理的这篇文章主要介绍了centos LAMP环境搭建前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

说明:

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. @H_404_158@


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

  27. '$status $body_bytes_sent "$http_referer" '

  28. '"$http_user_agent" $http_x_forwarded_for';

  29. access_log /usr/local/Nginx/logs/access.log wwwlog;


  30. gzip on;

  31. gzip_min_length 1k;

  32. gzip_buffers 4 16k;

  33. gzip_http_version 1.1;

  34. gzip_comp_level 3;

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

  36. on/xml;

  37. gzip_vary on;


  38. server_names_hash_bucket_size 128;

  39. client_header_buffer_size 32k;

  40. client_max_body_size 300m;

  41. client_body_buffer_size 512k;

  42. large_client_header_buffers 4 32k;


  43. proxy_connect_timeout 60;

  44. proxy_send_timeout 120;

  45. proxy_read_timeout 120;

  46. proxy_buffer_size 16k;

  47. proxy_buffers 4 64k;

  48. proxy_busy_buffers_size 128k;

  49. proxy_temp_file_write_size 128k;


  50. index index.PHP index.htm index.html default.PHP default.htm defaul

  51. t.html index.PHP3;


  52. upstream os_server {

  53. # ip_hash;

  54. # server 192.168.201.122:80 weight=1;

  55. server 192.168.201.123:80 weight=1;

  56. server 192.168.201.124:80 weight=1;

  57. server 192.168.201.125:80 weight=1;

  58. server 192.168.201.126:80 weight=1;

  59. server 192.168.201.127:80 weight=1;

  60. server 192.168.201.128:80 weight=1;

  61. server 192.168.201.129:80 weight=1;

  62. server 192.168.201.130:80 weight=1;

  63. server 192.168.201.131:80 weight=1;

  64. server 192.168.201.132:80 weight=1;

  65. server 192.168.201.133:80 weight=1;

  66. server 192.168.201.134:80 weight=1;

  67. server 192.168.201.136:80 weight=1;

  68. server 192.168.201.137:80 weight=1;

  69. server 192.168.201.138:80 weight=1;

  70. }

  71. upstream m_server {

  72. # ip_hash;

  73. # server 192.168.201.122:80 weight=1;

  74. server 192.168.201.123:80 weight=1;

  75. server 192.168.201.124:80 weight=1;

  76. server 192.168.201.125:80 weight=1;

  77. server 192.168.201.126:80 weight=1;

  78. server 192.168.201.127:80 weight=1;

  79. server 192.168.201.128:80 weight=1;

  80. @H_473_404@

    server 192.168.201.129:80 weight=1;

  81. server 192.168.201.130:80 weight=1;

  82. server 192.168.201.131:80 weight=1;

  83. server 192.168.201.132:80 weight=1;

  84. server 192.168.201.133:80 weight=1;

  85. server 192.168.201.134:80 weight=1;

  86. server 192.168.201.136:80 weight=1;

  87. server 192.168.201.137:80 weight=1;

  88. server 192.168.201.138:80 weight=1;

  89. }

  90. upstream weixin_server {

  91. # ip_hash;

  92. server 192.168.201.35:80 weight=1;

  93. server 192.168.201.34:80 weight=1;

  94. }


  95. upstream op_server {

  96. # ip_hash;

  97. server 192.168.201.35:80 weight=1;

  98. # server 192.168.201.34:80 weight=1;

  99. }

  100. #---------------------------www.lqxshop.com-----------------------

  101. server {

  102. listen 80;

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

  104. om;

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

  106. #limit_rate 40k;

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

  108. 得超过burst指定

  109. #limit_req zone=reqone burst=50;

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

  111. #limit_conn reqnum 20;

  112. location / {

  113. proxy_set_header HTTP_REFERER $http_referer;

  114. proxy_pass http://os_server;

  115. proxy_set_header Host $host;

  116. proxy_set_header X-Real-IP $remote_addr;

  117. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  118. index index.html index.PHP index.htm index.jsp;

  119. }

  120. }


  121. #--------------------------------m.lqxshop.com----------------------

  122. server {

  123. listen 80;

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

  125. #limit_rate 40k;

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

  127. 得超过burst指定

  128. #limit_req zone=reqone burst=50;

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

  130. #limit_conn reqnum 20;

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

  132. location / {

  133. proxy_pass http://m_server;

  134. proxy_set_header HTTP_REFERER $http_referer;

  135. proxy_set_header Host $host;

  136. proxy_set_header X-Real-IP $remote_addr;

  137. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  138. index index.html index.htm index.jsp;

  139. }

  140. }


  141. #--------------------------------weixin.lqxshop.com----------------------

  142. server {

  143. listen 80;

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

  145. #limit_rate 40k;

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

  147. 得超过burst指定

  148. #limit_req zone=reqone burst=50;

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

  150. #limit_conn reqnum 20;

  151. server_name weixin.shop.com;

  152. location / {

  153. proxy_pass http://weixin_server;

  154. proxy_set_header HTTP_REFERER $http_referer;

  155. proxy_set_header Host $host;

  156. proxy_set_header X-Real-IP $remote_addr;

  157. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  158. index index.html index.htm index.jsp;

  159. }

  160. }



  161. #--------------------------------op.lqxshop.com----------------------

  162. server {

  163. listen 80;

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

  165. #limit_rate 30k;

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

  167. 得超过burst指定

  168. #limit_req zone=reqone burst=50;

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

  170. #limit_conn reqnum 20;

  171. server_name op.shop.com;

  172. location / {

  173. proxy_pass http://op_server;

  174. proxy_set_header HTTP_REFERER $http_referer;

  175. proxy_set_header Host $host;

  176. proxy_set_header X-Real-IP $remote_addr;

  177. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  178. index index.html index.htm index.jsp;

  179. }

  180. }


  181. }



  182. 二.APP(Apache+PHP)搭建

  183. 1、移除系统自带的rpm包的http MysqL PHP

  184. yum remove httpd MysqL MysqL-server PHP PHP-cli PHP-common PHP-devel PHP-gd -y

  185. 2 安装必备的开发包

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

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

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

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

  190. libmhash-devel MysqL-devel libxslt libxslt-devel curl tcl expect

    3.同步系统时间:

  191. vim /etc/ntp.conf

  192. server 3.cn.pool.ntp.org

  193. server 3.asia.pool.ntp.org

  194. server 0.asia.pool.ntp.org

  195. chkconfig ntpd on

  196. service ntpd restart

  197. 4.安装Apache:

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

  199. cd /usr/local/src/

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

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

  202. cd ../apr-util-1.5.2/

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

  204. cd ../pcre-8.33/

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

  206. cd ../libmcrypt-2.5.8/

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

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

  209. cd ../httpd-2.4.6/

  210. ./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/

  211. make && make install

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

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

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

  215. # chkconfig: 35 61 61

  216. # description: Apache

  217. chkconfig --add httpd

  218. chkconfig httpd on

  219. 5.安装PHP

  220. cd ../PHP-5.5.3/

  221. ./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

  222. make && make install


  223. 装载XXX模块



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

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


  226. 6.apache和PHP结合:

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

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

  229. AddType application/x-httpd-PHP .PHP

  230. 查找DirectoryIndex index.html 把该行修改

  231. DirectoryIndex index.html index.htm index.PHP

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

  233. cd /usr/local/apache/htdocs

  234. vi index.PHP //在index.PHP文件中写入下面三行

  235. <?PHP

  236. PHPinfo();

  237. ?>

  238. 重启apache服务

  239. /sbin/service httpd restart

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

  241. elinks http://localhost/index.PHP

  242. 成功的页面



  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. @H_404_158@


  27. 3.编译安装MysqL

  28. tar zxvf MysqL-5.5.23.tar.gz -C /usr/local/src/

  29. cd /usr/local/src/MysqL-5.5.23

  30. cmake -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \

  31. -DMysqL_DATADIR=/data/MysqL \

  32. -DWITH_MYISAM_STORAGE_ENGINE=1 \

  33. -DWITH_INNOBASE_STORAGE_ENGINE=1 \

  34. -DWITH_ARCHIVE_STORAGE_ENGINE=1 \

  35. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

  36. -DENABLED_LOCAL_INFILE=1 \

  37. -DDEFAULT_CHARSET=utf8 \

  38. -DDEFAULT_COLLATION=utf8_general_ci \

  39. -DEXTRA_CHARSETS=all

  40. make && make install

  41. groupadd -r -g 3306 MysqL

  42. useradd -u 3306 -g MysqL -r -M -s /sbin/nologin MysqL

  43. mkdir -p /data/MysqL/

  44. mkdir -p /data/log/

  45. chown -R MysqL:MysqL /data/

  46. chown -R MysqL:MysqL /usr/local/MysqL/*

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


  48. 4.初始化

  49. /usr/local/MysqL/scripts/MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL --datadir=/data/MysqL & //初始化数据库


  50. 5.启动项

  51. cp support-files/MysqL.server /etc/init.d/MysqLd

  52. chmod +x /etc/init.d/MysqLd

  53. /chkconfig --add MysqLd

  54. chkconfig --level 2345 MysqLd on

  55. service MysqLd start

  56. netstat -tnlp |grep 3306


  57. 6.相关命令

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

  59. # ln -s /usr/local/MysqL/bin/MysqL MysqL

  60. # ln -s /usr/local/MysqL/bin/MysqLdump MysqLdump

  61. # ln -s /usr/local/MysqL/bin/MysqLadmin MysqLadmin

  62. # ln -s /usr/local/MysqL/bin/MysqLbinlog

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

  64. skip-external-locking

  65. key_buffer_size = 256M

  66. max_allowed_packet = 500M

  67. table_open_cache = 2048

  68. sort_buffer_size = 8M

  69. read_buffer_size = 4M

  70. read_rnd_buffer_size = 16M

  71. myisam_sort_buffer_size = 128M


  72. ###添加

  73. log-error=/data/log/MysqL.err.log

  74. skip-name-resolv

  75. max_connections = 3000

  76. max_connect_errors = 2000


  77. slow_query_log

  78. long_query_time = 2

  79. slow_query_log_file = /data/log/slow.log


  80. @H_473_404@

    bulk_insert_buffer_size = 64M

  81. query_cache_type = 1

  82. query_cache_size =256M

  83. query_cache_limit = 4M

  84. ft_min_word_len = 2

  85. join_buffer_size = 16M

  86. innodb_file_per_table

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

  88. myisam_repair_threads = 1

  89. innodb_log_files_in_group = 3

  90. thread_cache_size = 8

  91. # Try number of cpu's*2 for thread_concurrency

  92. thread_concurrency = 8


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


  94. :wq //保存退出

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

  96. service MysqLd restart

  97. MysqL -u root

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

  99. MysqL>flush privileges;

猜你在找的CentOS相关文章