centos LAMP环境搭建
说明:1.官网采用LAMP框架,nginx做前端轮询代理2、移除系统自带的rpm包的http mysql phpyum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd-y3 安装必备的开发包/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-develpam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel \libxml2-devel curl-devellibicu libicu-devel libmcrypt libmcrypt-devel libmhashlibxml2 \libmhash-develmysql-devel libxslt libxslt-devel curl tcl expect4.同步系统时间:vim /etc/ntp.confserver 3.cn.pool.ntp.orgserver 3.asia.pool.ntp.orgserver 0.asia.pool.ntp.orgchkconfig ntpd onservice ntpd restart5.IP分配 nginx:192.168.201.4192.168.201.5192.168.201.6192.168.201.7 apache:192.168.201.123---192.168.201.138[*]一.nginx搭建
[*]1.下载源码包nginx-1.4.2
[*]2.安装nginx
[*]./configuer--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module & make & make install
[*]3.配置文件如下
[*]usernobody;
[*]worker_processes8;
[*]pid logs/nginx.pid;
[*]
[*]events {
[*] use epoll;
[*] worker_connections65535;
[*] }
[*]
[*]http {
[*]
[*]# 设置一个共享内存区域reqnum,以用于限制每个客户端IP可以并发连接的请求数
[*]# limit_conn_zone $binary_remote_addr zone=reqnum:10m;
[*]# 每个客户端IP每分钟只允许5个连接
[*]# limit_req_zone $binary_remote_addr zone=reqone:10m rate=10r/m;
[*] include mime.types;
[*] default_typeapplication/octet-stream;
[*]
[*] sendfile on;
[*] tcp_nopush on;
[*] tcp_nodelay on;
[*] keepalive_timeout 60;
[*] server_tokens off;
[*]
[*] log_format wwwlog'$remote_addr - $remote_user [$time_local] "$request" '
[*] '$status $body_bytes_sent "$http_referer" '
[*] '"$http_user_agent" $http_x_forwarded_for';
[*] access_log /usr/local/nginx/logs/access.log wwwlog;
[*]
[*] gzip on;
[*] gzip_min_length 1k;
[*] gzip_buffers 4 16k;
[*] gzip_http_version 1.1;
[*] gzip_comp_level 3;
[*] gzip_types text/plain application/x-javascript text/css applicati
[*]on/xml;
[*] gzip_vary on;
[*]
[*] server_names_hash_bucket_size 128;
[*] client_header_buffer_size 32k;
[*] client_max_body_size 300m;
[*] client_body_buffer_size 512k;
[*] large_client_header_buffers 4 32k;
[*]
[*] proxy_connect_timeout 60;
[*] proxy_send_timeout 120;
[*] proxy_read_timeout 120;
[*] proxy_buffer_size 16k;
[*] proxy_buffers 4 64k;
[*] proxy_busy_buffers_size 128k;
[*] proxy_temp_file_write_size 128k;
[*]
[*] index index.phpindex.htm index.html default.php default.htm defaul
[*]t.html index.php3;
[*]
[*]upstream os_server {
[*]# ip_hash;
[*]# server 192.168.201.122:80 weight=1;
[*] server 192.168.201.123:80 weight=1;
[*] server 192.168.201.124:80 weight=1;
[*] server 192.168.201.125:80 weight=1;
[*] server 192.168.201.126:80 weight=1;
[*] server 192.168.201.127:80 weight=1;
[*] server 192.168.201.128:80 weight=1;
[*] server 192.168.201.129:80 weight=1;
[*] server 192.168.201.130:80 weight=1;
[*] server 192.168.201.131:80 weight=1;
[*] server 192.168.201.132:80 weight=1;
[*] server 192.168.201.133:80 weight=1;
[*] server 192.168.201.134:80 weight=1;
[*] server 192.168.201.136:80 weight=1;
[*] server 192.168.201.137:80 weight=1;
[*] server 192.168.201.138:80 weight=1;
[*] }
[*]upstream m_server {
[*]# ip_hash;
[*]# server 192.168.201.122:80 weight=1;
[*] server 192.168.201.123:80 weight=1;
[*] server 192.168.201.124:80 weight=1;
[*] server 192.168.201.125:80 weight=1;
[*] server 192.168.201.126:80 weight=1;
[*] server 192.168.201.127:80 weight=1;
[*] server 192.168.201.128:80 weight=1;
[*] server 192.168.201.129:80 weight=1;
[*] server 192.168.201.130:80 weight=1;
[*] server 192.168.201.131:80 weight=1;
[*] server 192.168.201.132:80 weight=1;
[*] server 192.168.201.133:80 weight=1;
[*] server 192.168.201.134:80 weight=1;
[*] server 192.168.201.136:80 weight=1;
[*] server 192.168.201.137:80 weight=1;
[*] server 192.168.201.138:80 weight=1;
[*] }
[*]upstream weixin_server {
[*]# ip_hash;
[*] server 192.168.201.35:80 weight=1;
[*] server 192.168.201.34:80 weight=1;
[*] }
[*]
[*]upstream op_server {
[*]# ip_hash;
[*] server 192.168.201.35:80 weight=1;
[*]# server 192.168.201.34:80 weight=1;
[*] }
[*]#---------------------------www.lqxshop.com-----------------------
[*]server {
[*] listen 80;
[*] server_name www.shop.com www.ilqx.cn www.chenggongfang.com wx.lqxshop.c
[*]om;
[*] #限制每个连接的带宽大小
[*] #limit_rate 40k;
[*] #限制每个客户端ip在指定时间内容允许连接的请求数,且超过限制连接频率的连接数不
[*]得超过burst指定
[*] #limit_req zone=reqone burst=50;
[*] #使用前面定义的共享内存区域,限制每个客户端IP并发连接的最大数
[*] #limit_conn reqnum 20;
[*]location / {
[*] proxy_set_header HTTP_REFERER$http_referer;
[*] proxy_pass http://os_server;
[*] proxy_set_header Host $host;
[*] proxy_set_header X-Real-IP $remote_addr;
[*] proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
[*] indexindex.html index.php index.htm index.jsp;
[*] }
[*]}
[*]
[*]#--------------------------------m.lqxshop.com----------------------
[*]server {
[*] listen 80;
[*] #限制每个连接的带宽大小
[*] #limit_rate 40k;
[*] #限制每个客户端ip在指定时间内容允许连接的请求数,且超过限制连接频率的连接数不
[*]得超过burst指定
[*] #limit_req zone=reqone burst=50;
[*] #使用前面定义的共享内存区域,限制每个客户端IP并发连接的最大数
[*] #limit_conn reqnum 20;
[*] server_name m.shop.com m1.shop.com m2.shop.com;
[*]location / {
[*] proxy_pass http://m_server;
[*] proxy_set_header HTTP_REFERER$http_referer;
[*] proxy_set_header Host $host;
[*] proxy_set_header X-Real-IP $remote_addr;
[*] proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
[*] indexindex.html index.htm index.jsp;
[*]}
[*]}
[*]
[*]#--------------------------------weixin.lqxshop.com----------------------
[*]server {
[*] listen 80;
[*] #限制每个连接的带宽大小
[*] #limit_rate 40k;
[*] #限制每个客户端ip在指定时间内容允许连接的请求数,且超过限制连接频率的连接数
[*]得超过burst指定
[*] #limit_req zone=reqone burst=50;
[*] #使用前面定义的共享内存区域,限制每个客户端IP并发连接的最大数
[*] #limit_conn reqnum 20;
[*] server_name weixin.shop.com;
[*]location / {
[*] proxy_pass http://weixin_server;
[*] proxy_set_header HTTP_REFERER$http_referer;
[*] proxy_set_header Host $host;
[*] proxy_set_header X-Real-IP $remote_addr;
[*] proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
[*] indexindex.html index.htm index.jsp;
[*]}
[*]}
[*]
[*]
[*]#--------------------------------op.lqxshop.com----------------------
[*]server {
[*] listen 80;
[*] #限制每个连接的带宽大小
[*] #limit_rate 30k;
[*] #限制每个客户端ip在指定时间内容允许连接的请求数,且超过限制连接频率的连接数
[*]得超过burst指定
[*] #limit_req zone=reqone burst=50;
[*] #使用前面定义的共享内存区域,限制每个客户端IP并发连接的最大数
[*] #limit_conn reqnum 20;
[*] server_name op.shop.com;
[*]location / {
[*] proxy_pass http://op_server;
[*] proxy_set_header HTTP_REFERER$http_referer;
[*] proxy_set_header Host $host;
[*] proxy_set_header X-Real-IP $remote_addr;
[*] proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
[*] indexindex.html index.htm index.jsp;
[*]}
[*]}
[*]
[*]}
[*]
[*]
[*]二.APP(Apache+php)搭建
[*]1、移除系统自带的rpm包的http mysql php
[*]yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd-y
[*]2 安装必备的开发包
[*]/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-develpam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel \
[*]libxml2-devel curl-devellibicu libicu-devel libmcrypt libmcrypt-devel libmhashlibxml2 \
[*]libmhash-develmysql-devel libxslt libxslt-devel curl tcl expect
3.同步系统时间:
[*]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
[*]4.安装Apache:
[*]##############安装需要的插件:apr、apr-util、pcre、libmcrypt######################################
[*]cd /usr/local/src/
[*]cd apr-1.4.8################(rm: cannot remove `libtoolT': No such file or directory///////修改configure文件,+++++把RM='$RM'改为RM='$RM-f'+++++)
[*]./configure --prefix=/usr/local/apr && make && make install
[*]cd ../apr-util-1.5.2/
[*]./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ && make && make install
[*]cd ../pcre-8.33/
[*]./configure --prefix=/usr/local/pcre --enable-utf8 && make && make install
[*]cd ../libmcrypt-2.5.8/
[*]./configure --prefix=/usr/local/libmcrypt && make && make install
[*]###################开始安装Apache,并修改开启启动##################################################
[*]cd ../httpd-2.4.6/
[*]./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/
[*]make && make install
[*]/usr/local/apache/bin/apachectl start
[*]cp /usr/local/apache/bin/apachectl/etc/init.d/httpd
[*]vim /etc/init.d/httpd(第二行添加注释信息,添加为系统服务)
[*]# chkconfig: 35 61 61
[*]# description: Apache
[*]chkconfig --add httpd
[*]chkconfig httpd on
[*]5.安装php:
[*]cd ../php-5.5.3/
[*]./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
[*]make && make install
[*]
[*]装载XXX模块
[*]
[*]
[*]cd /usr/local/httpd-2.2.22/modules/generators/
[*]/usr/local/apache/bin/apxs -i -a -c mod_cgi.c
[*]
[*]6.apache和php结合:
[*]vim /usr/local/apache/conf/httpd.conf
[*]查找AddType application/x-gzip .gz .tgz,在该行下面添加
[*]AddType application/x-httpd-php .php
[*]查找DirectoryIndex index.html 把该行修改成
[*]DirectoryIndex index.html index.htm index.php
[*]测试apache和php是否整合成功,下面我们测试apache和php是否整合成功,在apache文档跟目录下新建一个小小的php程序
[*]cd /usr/local/apache/htdocs
[*]vi index.php//在index.php文件中写入下面三行
[*]<?php
[*]phpinfo();
[*]?>
[*]重启apache服务
[*]/sbin/servicehttpd restart
[*]访问,在浏览器中输入http://localhost(ip地址)/index.php 出现php信息界面则说明整合成功
[*]elinks http://localhost/index.php
[*]成功的页面
[*]
[*]三.mysql搭建
[*]
[*]10 11
[*]软件源代码包存放位置 /opt
[*]软件解压位置 /usr/local/src
[*]源码包编译安装位置(prefix) /usr/local/
[*]脚本以及维护程序存放位置 /script
[*]数据库文件位置: /data/mysql/
[*]数据库日志位置: /data/log
[*]数据库备份目录: /data/backup
[*]
[*]1.卸载默认的mysql及apache的rpm包
[*]yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd-y
[*]yum install ntp
[*]service ntpd stop
[*]ntpdate cn.pool.ntp.org
[*]service ntpd start
[*]chkconfig --level 2345 ntpd on
[*]
[*]2.安装依赖包
[*]yum install gcc gcc-c++ make cmake ncurses-devel vim -y
[*]cd /opt
[*] tar zxvf cmake-2.8.5.tar.gz -C /usr/local/src
[*] cd /usr/local/src
[*]cd cmake-2.8.5/
[*]./configure
[*]make && make install
[*]cd /opt
[*]
[*]3.编译安装mysql
[*]tar zxvf mysql-5.5.23.tar.gz -C /usr/local/src/
[*]cd /usr/local/src/mysql-5.5.23
[*] cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
[*] -DMYSQL_DATADIR=/data/mysql \
[*] -DWITH_MYISAM_STORAGE_ENGINE=1 \
[*] -DWITH_INNOBASE_STORAGE_ENGINE=1 \
[*] -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
[*] -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
[*] -DENABLED_LOCAL_INFILE=1 \
[*] -DDEFAULT_CHARSET=utf8 \
[*] -DDEFAULT_COLLATION=utf8_general_ci \
[*] -DEXTRA_CHARSETS=all
[*]make && make install
[*]groupadd -r -g 3306 mysql
[*]useradd -u 3306 -g mysql -r -M -s /sbin/nologin mysql
[*]mkdir -p /data/mysql/
[*]mkdir -p /data/log/
[*]chown -R mysql:mysql /data/
[*]chown -R mysql:mysql /usr/local/mysql/*
[*]cp support-files/my-huge.cnf /etc/my.cnf
[*]
[*]4.初始化
[*]/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql & //初始化数据库
[*]
[*]5.启动项
[*]cp support-files/mysql.server /etc/init.d/mysqld
[*]chmod +x /etc/init.d/mysqld
[*]/chkconfig --add mysqld
[*]chkconfig--level 2345 mysqld on
[*]servicemysqld start
[*]netstat -tnlp |grep 3306
[*]
[*]6.相关命令
[*]# cd /usr/local/bin //进入用户的默认搜索路径下建立mysql命令的软连接,可以直接执行mysql命令
[*] #ln -s /usr/local/mysql/bin/mysql mysql
[*] #ln -s /usr/local/mysql/bin/mysqldump mysqldump
[*] #ln -s /usr/local/mysql/bin/mysqladminmysqladmin
[*] #ln -s /usr/local/mysql/bin/mysqlbinlog
[*]vim /etc/my.cnf,在配置参数下面添加下面几行(大概37行下面),根据服务
[*]skip-external-locking
[*]key_buffer_size = 256M
[*]max_allowed_packet = 500M
[*]table_open_cache = 2048
[*]sort_buffer_size = 8M
[*]read_buffer_size = 4M
[*]read_rnd_buffer_size = 16M
[*]myisam_sort_buffer_size = 128M
[*]
[*]###添加
[*]log-error=/data/log/mysql.err.log
[*]skip-name-resolv
[*]max_connections = 3000
[*]max_connect_errors = 2000
[*]
[*]slow_query_log
[*]long_query_time = 2
[*]slow_query_log_file = /data/log/slow.log
[*]
[*]bulk_insert_buffer_size = 64M
[*]query_cache_type = 1
[*]query_cache_size =256M
[*]query_cache_limit = 4M
[*]ft_min_word_len = 2
[*]join_buffer_size = 16M
[*]innodb_file_per_table
[*]log-bin-trust-function-creators=1
[*]myisam_repair_threads = 1
[*]innodb_log_files_in_group = 3
[*]thread_cache_size = 8
[*]# Try number of CPU's*2 for thread_concurrency
[*]thread_concurrency = 8
[*]
[*]innodb_buffer_pool_size = 2G //修改这个参数为物理内存的80%
[*]
[*]:wq //保存退出
[*]rm -rvf/data/mysql/ib* myslq-bin* //删除原来的默认文件
[*]service mysqld restart
[*]mysql -u root
[*]Mysql> grant all privileges on *.* to lqx@'%' identified by 'shlqx1!';
[*]Mysql>flush privileges;
[*]
页:
[1]