说明:
1.官网采用LAMP框架,Nginx做前端轮询代理
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
一.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.配置文件如下
user nobody;
worker_processes 8;
pid logs/Nginx.pid;
events {
use epoll;
worker_connections 65535;
}
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_type application/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.PHP index.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;
@H_711_404@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;
index index.html index.PHP index.htm index.jsp;
}
}
#--------------------------------m.lqxshop.com----------------------
server {
@H_301_586@#限制每个连接的带宽大小
#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;
index index.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;
index index.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;
index index.html index.htm index.jsp;
}
}
}
二.APP(Apache+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-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
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
# 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,在该行下面添加
查找DirectoryIndex index.html 把该行修改成
DirectoryIndex index.html index.htm index.PHP
测试apache和PHP是否整合成功,下面我们测试apache和PHP是否整合成功,在apache文档跟目录下新建一个小小的PHP程序
cd /usr/local/apache/htdocs
<?PHP
PHPinfo();
?>
重启apache服务
/sbin/service httpd restart
elinks http://localhost/index.PHP
成功的页面
server 192.168.201.129:80 weight=1;
listen 80;
三.MysqL搭建
10 11
软件源代码包存放位置 /opt
软件解压位置 /usr/local/src
源码包编译安装位置(prefix) /usr/local/
脚本以及维护程序存放位置 /script
数据库日志位置: /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 \
-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
mkdir -p /data/MysqL/
mkdir -p /data/log/
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.启动项
chmod +x /etc/init.d/MysqLd
/chkconfig --add MysqLd
chkconfig --level 2345 MysqLd on
service MysqLd start
netstat -tnlp |grep 3306
6.相关命令
# cd /usr/local/bin //进入用户的默认搜索路径下建立MysqL命令的软连接,可以直接执行MysqL命令
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
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 //保存退出
service MysqLd restart
MysqL -u root
MysqL> grant all privileges on *.* to lqx@'%' identified by 'shlqx1!';
MysqL>flush privileges;
bulk_insert_buffer_size = 64M