环境标准:
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
内核:2.6.32-642.el6.x86_64
系统:CentOS release 6.8 (Final)
ip:
web01:10.0.0.8 nginx 解析手机端 均做了nginx的负载均衡但是只均衡一台机器可以后续往里填
web02:10.0.0.200 nginx 解析电脑端 均做了nginx的负载均衡但是只均衡一台机器可以后续往里填
lb01:10.0.0.201 nginx 负载均衡lb01 主负载均衡
lb02:10.0.0.31 nginx 负载均衡lb02 备的负载均衡
vip:10.0.0.5(虚拟) keepalive 虚拟路由冗余 保证负载均衡存在解决单点问题
存放目录:/home/oldboy/tools/
安装目录:/application/
运行用户:www
脚本目录:/server/script(在这里暂时没有使用脚本)
ip功能介绍:
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
web01:
第一个里程碑:部署配置nginx
1.mkdir -p /home/oldboy/tools
2.cd /home/oldboy/tools
3.wget http://nginx.org/download/nginx-1.10.2.tar.gz
4.useradd -s /sbin/nologin -M www
5. tar xf nginx-1.10.2.tar.gz
6.cd nginx-1.10.2
7.yum install -y pcre-devel openssl-devel
8.yum install gcc-c++ -y
9. ./configure --user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module
10.make && make install
11.ln -s /application/nginx-1.10.2 /application/nginx
12.vim /application/nginx/config/nginx.conf
===================================================
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log logs/access.log main;
include extra/blog.conf;
}
===================================================
13.mkdir /application/nginx/config/extra
14.vim /application/nginx/config/extra/blog.conf
====================================================
server {
listen 80;
server_name blog.ls.com;
location / {
root html/blog;
index index.php gen.html index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
=====================================================
15.mkdir /application/nginx/html/blog
16.echo "hello word!!! i am web01" > /application/nginx/html/blog/index.html
17. /application/nginx/sbin/nginx -t
18. /application/nginx/sbin/nginx
第二个里程碑:测试
[root@test html]# curl 10.0.0.8
hello web01
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
web02:
第一个里程碑:部署配置nginx
1.mkdir -p /home/oldboy/tools
2.cd /home/oldboy/tools
3.wget http://nginx.org/download/nginx-1.10.2.tar.gz
4.useradd -s /sbin/nologin -M www
5. tar xf nginx-1.10.2.tar.gz
6.cd nginx-1.10.2
7.yum install -y pcre-devel openssl-devel
8.yum install gcc-c++ -y
9. ./configure --user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module
10.make && make install
11.ln -s /application/nginx-1.10.2 /application/nginx
12.vim /application/nginx/config/nginx.conf
=========================================================
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log logs/access.log main;
include extra/blog.conf;
}
=========================================================
15.mkdir /application/nginx/html/blog
16.echo "hello word!!! i am web02" > /application/nginx/html/blog/index.html
17. /application/nginx/sbin/nginx -t
18. /application/nginx/sbin/nginx
第二个里程碑:测试
[root@test html]# curl 10.0.0.200
hello web02
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
lb01:
第一个里程碑:部署配置nginx
1.mkdir -p /home/oldboy/tools
2.cd /home/oldboy/tools
3.wget http://nginx.org/download/nginx-1.10.2.tar.gz
4.useradd -s /sbin/nologin -M www
5. tar xf nginx-1.10.2.tar.gz
6.cd nginx-1.10.2
7.yum install -y pcre-devel openssl-devel
8.yum install gcc-c++ -y
9. ./configure --user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module
10.make && make install
11.ln -s /application/nginx-1.10.2 /application/nginx
12.vim /application/nginx/config/nginx.conf
=========================================================
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log logs/access.log main;
upstream dn {
server 10.0.0.8;
}
upstream sj {
server 10.0.0.200;
}
server {
listen 80;
server_name blog.ls.com;
location / {
if ( $http_user_agent ~* ‘curl‘ )
{
proxy_pass http://dn;
}
proxy_pass http://sj;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
}
=========================================================
13. /application/nginx/sbin/nginx -t
14. /application/nginx/sbin/nginx
第二个里程碑:测试
[root@test html]# curl 10.0.0.201
hello web02
[root@test html]# curl 10.0.0.201
hello web01
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
lb02:
第一个里程碑:部署配置nginx
1.mkdir -p /home/oldboy/tools
2.cd /home/oldboy/tools
3.wget http://nginx.org/download/nginx-1.10.2.tar.gz
4.useradd -s /sbin/nologin -M www
5. tar xf nginx-1.10.2.tar.gz
6.cd nginx-1.10.2
7.yum install -y pcre-devel openssl-devel
8.yum install gcc-c++ -y
9. ./configure --user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module
10.make && make install
11.ln -s /application/nginx-1.10.2 /application/nginx
12.vim /application/nginx/config/nginx.conf
=========================================================
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log logs/access.log main;
upstream dn {
server 10.0.0.8;
}
upstream sj {
server 10.0.0.200;
}
server {
listen 80;
server_name blog.ls.com;
location / {
if ( $http_user_agent ~* ‘curl‘ )
{
proxy_pass http://dn;
}
proxy_pass http://sj;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
}
=========================================================
13. /application/nginx/sbin/nginx -t
14. /application/nginx/sbin/nginx
第二个里程碑:测试
[root@test html]# curl 10.0.0.31
hello web02
[root@test html]# curl 10.0.0.31
hello web01
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
lb01:keepalive
yum install keepalived -y
vim /etc/keepalived/keepalived.conf
----------------------------------------------
! Configuration File for keepalived
global_defs {
notification_email {
shuaileo@163.com
}
notification_email_from shuaileo@163.com
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id LVS_DEVEL1
}
vrrp_instance VI_1 {
state MASTER #标记为主
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.5/24 dev eth0 label eth0:0
}
}
-------------------------------------------------
/etc/init.d/keepalive start
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
lb02:keepalive
yum install keepalived -y
vim /etc/keepalived/keepalived.conf
----------------------------------------------
! Configuration File for keepalived
global_defs {
notification_email {
shuaileo@163.com
}
notification_email_from shuaileo@163.com
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id LVS_DEVEL1
}
vrrp_instance VI_1 {
state MASTER #标记为主
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.5/24 dev eth0 label eth0:0
}
}
-----------------------------------------------
/etc/init.d/keepalive start
第二个里程碑:测试
ip a
curl 10.0.0.5
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
linux端:
vim /etc/hosts
--------------------
10.0.0.3 blog.ls.com
--------------------
[root@salt conf]# curl blog.ls.com
hello web01
Windows客户端:
vim /etc/hosts
--------------------
10.0.0.3 blog.ls.com
--------------------
浏览器端打开blog.ls.com
hello web02
本文出自 “我的学习” 博客,请务必保留此出处http://shuai12138.blog.51cto.com/10118203/1910540
原文地址:http://shuai12138.blog.51cto.com/10118203/1910540