1.keepalived介绍
keepalived最初是专为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了实现高可用的VRRP功能。keepalived除了能够管理LVS软件外,还能支持其他服务的高可用解决方案。
keepalived通过VRRP协议实现高可用功能的。VRRP(Virtual Router Redundancy Protocol)虚拟路由冗余协议。VRRP出现的目的就是为了解决静态路由单点故障问题,它能保证当个别节点宕机时,整个网络可以不间断地运行。
2.keepalived高可用故障转移原理
keepalived高可用服务之间的故障转移,是通过VRRP来实现的。在keepalived服务工作时,主Master节点会不断地向备节点发送(多播的方式)心跳消息,用来告诉备Backup节点自己还活着。
当主节点发生故障时,无法给备节点发送心跳消息,如果备节点无法继续检测到来自主节点的心跳。就会调用自身的接管程序,接管主节点的IP资源和服务。当主节点恢复时,备节点又会释放主节点故障时自身接管的IP资源和服务,恢复到原来的备用角色
3.安装nginx
3.1.主节点(192.168.80.22)
3.1.1.安装编译工具和库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
3.1.2.安装pcre
#进入目录cd /usr/local/develop/anginx#上传安装文件并解压tar -zxvf pcre-8.38.tar.gz#进入安装目录cd pcre-8.38#检查配置./configure#编译、安装make && make install#查看pcre版本pcre-config --version
3.1.3.安装nginx
#进入目录cd /usr/local/develop/anginx#上传安装文件,并解压tar -zxvf nginx-1.8.1.tar.gz#进入安装目录cd nginx-1.8.1#检查配置./configure --prefix=/usr/local/develop/anginx/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/develop/anginx/pcre-8.38#编译安装make && make install#查看nginx版本 /usr/local/develop/anginx/webserver/nginx/sbin/nginx -v--------------------------------------------------------[root@hadoop02 webserver]# /usr/local/develop/anginx/webserver/nginx/sbin/nginx -vnginx version: nginx/1.8.1#配置nginx(检查)/usr/local/develop/anginx/webserver/nginx/sbin/nginx -t#nginx管理命令/usr/local/develop/anginx/webserver/nginx/sbin/nginx # 启动 Nginx/usr/local/develop/anginx/webserver/nginx/sbin/nginx -s stop # 停止 Nginx/usr/local/develop/anginx/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件/usr/local/develop/anginx/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx
3.1.4.nginx基础配置
vi nginx.conf#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; 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; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #添加tomcat列表,真实应用服务器都放在这 upstream tomcat_pool{ #server tomcat地址:端口号 weight表示权值,权值越大,被分配的几率越大; server 192.168.80.22:8080 weight=4 max_fails=2 fail_timeout=30s; server 192.168.80.22:8081 weight=4 max_fails=2 fail_timeout=30s; } server { listen 80; server_name tomcat_pool; #charset koi8-r; #access_log logs/host.access.log main; location / { #root html; #index index.html index.htm; proxy_pass http://tomcat_pool; #转向tomcat处理 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } #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; }}
新闻热点
疑难解答