keepalived+nginx安装配置
软件版本号:
pcre8.36 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
keepalived1.2.19
http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
nginx1.8.0
http://nginx.org/download/nginx-1.8.0.tar.gz<pre name="code" class="html"><pre name="code" class="html">安装步骤
安装pcre
tar -zxvf pcre-8.36.tar.gz
cd pcre-8.36
./configure --prefix=/usr/local/pcre
make && make install
安装keepalived
tar -zxvf keepalived-1.2.19.tar.gz
cd keepalived-1.2.19
./configure --prefix=/usr/local/keepalived
make && make install
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir –pv /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
ln -s /usr/local/keepalived/sbin/keepalived /sbin/
chkconfig keepalived on
安装nginx
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre/
make && make install
<strong><span style="font-size:18px;">启动和停止</span></strong>
Nginx:
启动:进入到安装之后${nginx}的sbin文件夹。运行./nginx
停止:./nginx –s stop
检查是否成功安装:进入到安装之后${nginx}的sbin文件夹,运行./nginx -t Keepalived
启动:service keepalived start
停止:service keepalived stop <strong><span style="font-size:18px;">配置</span></strong>
配置Keepalived
主备keepalived的配置大致同样,不同之处在于state和priority。 例如以下所看到的:
! Configuration File for keepalived
#配置报警邮件
global_defs {
notification_email {
acassen@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
#配置keepalived服务器实例
vrrp_instance VI_1 {#VI_1为名称
state MASTER #MASTER为主服务器。BACKUP为备用服务器
interface p2p1 #p2p1为网卡标志
virtual_router_id 51 #51为默认值
priority 100 #主服务器的优先级要大于备服务器
advert_int 1 #1为默认值
authentication {#认证,採用默认值就可以
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {#对外提供的虚拟IP,不能与现有IP冲突
200.31.157.243
}
}
配置Nginx
Nginx的基本配置例如以下所看到的:
#user nobody; #username称
worker_processes auto; #处理进程个数,一般为自己主动分配
error_log logs/error.log; #错误日志记录位置
#error_log logs/error.log notice; #notice/info等为记录错误的级别
#error_log logs/error.log info;
pid logs/nginx.pid; #进程记录文件 events {
worker_connections 5120; #可处理的连接数,最大处理能力为processes×connections
} http {
include mime.types;
default_type application/octet-stream;
#配置日志格式(main为自己定义格式名称)
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; #日志文件位置
keepalive_timeout 65; #连接超时时间
proxy_connect_timeout 10; #后台服务器响应超时时间 #配置反向代理
upstream tomcat{ #tomcat为名称
server 200.31.157.116:8090 weight=1; #后台服务器的地址以及port号。weight为权重
server 200.31.157.117:8090 weight=1;
} #配置负载均衡,Server为nginx服务器
upstream nginx{
server 200.31.157.116:8084 weight=1;
server 200.31.157.117:8084 weight=1;
} #配置处理请求Server
server{
listen 8084; #监听的port号
server_name 200.31.157.243; #自己定义服务名称,不能与其他Server有冲突
#charset koi8-r; #定义字符集
#access_log logs/host.access.log main; #定义日志名称与日志格式(main) #设定訪问处理规则。假设路径以/cwap开头,则通过下面规则进行处理
location /cwap {
proxy_pass http://tomcat; #反向代理到tomcat服务器该处的tomcat为upstream名称
proxy_redirect off;
proxy_set_header Host $host; #下面是读取訪问IP
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} location / {
root html; #根文件夹
index index.html index.htm;
}
#error_page 404 /404.html; #配置错误页面 # redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server{
listen 80;
server_name localhost;
access_log logs/access.log main;
location /cwap {
proxy_pass http://nginx;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} location / {
root html;
index index.html index.htm;
#expires 1d; #页面缓存时间
}
error_page 404 /404.html; # redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
} <strong><span style="font-size:18px;">负载均衡</span></strong>
nginx 的 upstream眼下支持 4 种方式的分配
轮询(默认)
每一个请求按时间顺序逐一分配到不同的后端服务器,假设后端服务器down掉。能自己主动剔除。 weight
定轮询几率。weight和訪问比率成正比,用于后端服务器性能不均的情况。
ip_hash
每一个请求按訪问ip的hash结果分配,这样每一个訪客固定訪问一个后端服务器。能够解决session的问题。
fair(第三方)
按后端服务器的响应时间来分配请求。响应时间短的优先分配。 在http中upstream配置中,clouder是起的负载均衡服务器或者反向代理的名称。 upstream clouder {
#ip_hash;
#least_conn;
server 200.31.157.116:8090;
server 200.31.157.116:9090 down; #表示当前server临时不參与负载
server 200.31.157.117:8090 weight=2; #默觉得1,weight越大,负载的权重越大
#其他全部非backup机器down或忙时。请求backup机器。所以这台机器压力会最轻
server 200.31.157.117:9090 backup;
<span style="white-space:pre"> </span>server 200.31.157.117:8084 fail_timeout=10s; #失败后的暂停时间
<span style="white-space:pre"> </span>#最大失败次数为2,失败后暂停时间为10
server 200.31.157.117:8083 max_fails=2 fail_timeout=10s;
}
keepalived+nginx安装配置的更多相关文章
- LVS+Nginx(LVS + Keepalived + Nginx安装及配置)
(也可以每个nginx都挂在上所有的应用服务器) nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广 ...
- Nginx安装配置(转)
Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/ ...
- Nginx安装配置PHP(FastCGI)环境的教程
这篇是Nginx安装配置PHP(FastCGI)环境的教程.Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用. 一.什么是 FastCGI F ...
- Nginx安装配置与HelloWorld
<深入理解Nginx>阅读与实践(一):Nginx安装配置与HelloWorld 最近在读陶辉的<深入理解Nginx:模块开发与架构解析>,一是想跟着大牛练练阅读和编写开源代码 ...
- Nginx 安装 配置 使用
Nginx 安装 配置 使用 基本的HTTP服务器特性 处理静态文件,索引文件以及自动索引:打开文件描述符缓存(缓存元数据和文件描述符,下一次可以直接从内存找到数据或者文件的位置): 使用缓存加速反向 ...
- VMware Linux 下 Nginx 安装配置 - nginx.conf 配置 [负载两个 Tomcat] (三)
首先启动Nginx 1. 相关浏览 两个 Tomcat 配置: VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二) Nginx 安装配置启动: VMware Linu ...
- VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二)
准备工作 相关浏览: VMware Linux 下 Nginx 安装配置 (一) 1. 选在 /usr/local/ 下创建 softs 文件夹,通过 ftp 命令 把 apache-tomcat-7 ...
- Hearbeat + Nginx 安装配置
Hearbeat + Nginx 安装配置 实验环境 两台主机:Linux Centos 6.5 32位 主 服务端:Hearbeat + Nginx eth0:192.168.1.160(公网) e ...
- Nginx安装配置|Nginx反向代理|Nginx支持HTTPS|Nginx重定向
Nginx安装配置 可以直接看到最下面的HTTPS. Nginx安装 我的系统如下: No LSB modules are available. Distributor ID: Ubuntu Desc ...
随机推荐
- IBatis的分页研究
IBatis的分页研究 博客分类: Ibatis学习 摘自: http://cpu.iteye.com/blog/311395 yangtingkun Oracle分页查询语句 ibaits. ...
- Tcl之Read files for synthesis
The following file is to read all design files into syntehsis tool automatically, like Cadence RTL C ...
- windows如何统计端口的连接数
习惯了linux的系统管理员,对linux的命令行工具总是印象极深,几乎所有的管理都可以在命令行下完成.命令行工具是linux系统管理的主流. 而使用windows是,因为图形化的界面,大家习惯了图形 ...
- 让ios支持http协议
ios默认只支持https协议,打开info.plist文件,加入以下设置 NSAppTransportSecurity NSAllowsArbitraryLoads
- layer iframe层ajax回调弹出layer.msg()
ajax success方法 success: function(data){ layer.msg("输入你需要的提示",{time:1000,end:function(){ // ...
- 关押罪犯 - 并查集&优先队列
题目地址:http://www.51cpc.com/web/problem.php?id=4261 Summarize: 此题最巧妙的是“敌人的敌人就是朋友!”,故需先将敌对关系放入优先队列,按怨恨值 ...
- 洛谷——P3946 ことりのおやつ(小鸟的点心)
P3946 ことりのおやつ(小鸟的点心) 题目太长,请去链接里看吧 注意细节:特判终点(即使困住又能怎样,到达就好了),特判高度 #include<bits/stdc++.h> #defi ...
- Dollar Dayz POJ - 3181
解法 完全背包+大数...不想写大数了放个python得了 代码 dp=[0 for i in range(2000)] n,k=map(int,input().split()) num=[i for ...
- FTP配置
常用的匿名FTP配置项 anonymous_enable=YES 是否允许匿名用户访问 anon_umask=022 匿名用户所上传文件的权限 ...
- response对象处理HTTP文件头(禁用缓存、设置页面自动刷新、定时跳转网页)
response对象处理HTTP文件头 制作人:全心全意 禁用缓存 在默认情况下,浏览器将会对显示的网页内容进行缓存.这样,当用户再次访问相关网页时,浏览器会判断网页是否有变化,如果没有变化则直接显示 ...