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

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

    server {

    @H_301_671@

    listen 80;

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

  143. #limit_rate 40k;

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

  145. 得超过burst指定

  146. #limit_req zone=reqone burst=50;

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

  148. #limit_conn reqnum 20;

  149. server_name weixin.shop.com;

  150. location / {

  151. proxy_pass http://weixin_server;

  152. proxy_set_header HTTP_REFERER $http_referer;

  153. proxy_set_header Host $host;

  154. proxy_set_header X-Real-IP $remote_addr;

  155. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  156. index index.html index.htm index.jsp;

  157. }

  158. }



  159. #--------------------------------op.lqxshop.com----------------------

  160. server {

  161. listen 80;

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

  163. #limit_rate 30k;

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

  165. 得超过burst指定

  166. #limit_req zone=reqone burst=50;

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

  168. #limit_conn reqnum 20;

  169. server_name op.shop.com;

  170. location / {

  171. proxy_pass http://op_server;

  172. proxy_set_header HTTP_REFERER $http_referer;

  173. proxy_set_header Host $host;

  174. proxy_set_header X-Real-IP $remote_addr;

  175. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  176. index index.html index.htm index.jsp;

  177. }

  178. }


  179. }



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

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

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

  183. 2 安装必备的开发包

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

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

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

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

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

    3.同步系统时间:

  189. vim /etc/ntp.conf

  190. server 3.cn.pool.ntp.org

  191. server 3.asia.pool.ntp.org

  192. server 0.asia.pool.ntp.org

  193. chkconfig ntpd on

  194. service ntpd restart

  195. 4.安装Apache:

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

  197. cd /usr/local/src/

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

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

  200. cd ../apr-util-1.5.2/

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

  202. cd ../pcre-8.33/

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

  204. cd ../libmcrypt-2.5.8/

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

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

  207. cd ../httpd-2.4.6/

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

  209. make && make install

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

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

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

  213. # chkconfig: 35 61 61

  214. # description: Apache

  215. chkconfig --add httpd

  216. chkconfig httpd on

  217. 5.安装PHP

  218. cd ../PHP-5.5.3/

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

  220. make && make install


  221. 装载XXX模块



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

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


  224. 6.apache和PHP结合:

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

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

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

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

  229. DirectoryIndex index.html index.htm index.PHP

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

  231. cd /usr/local/apache/htdocs

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

  233. <?PHP

  234. PHPinfo();

  235. ?>

  236. 重启apache服务

  237. /sbin/service httpd restart

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

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

  240. 成功的页面



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

    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;

原文链接:https://www.f2er.com/centos/380397.html

猜你在找的CentOS相关文章