准备工作:

yum install -y gcc openssl-devel pcre-devel install iptables-services

setenforce 0
sed -ri 's/^(SELINUX=).*/\1disabled/' /etc/selinux/config systemctl stop firewalld
systemctl disable firewalld
systemctl enable iptables
systemctl start iptables vim /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -d 224.0.0.0/8 -p vrrp -j ACCEPT
-A OUTPUT -d 224.0.0.0/8 -p vrrp -j ACCEPT
systemctl restart iptables

 

安装nginx两个机器安装方式一样
#上传tengine-2.1.2.tar.gz /tmp

#安装
cd /tmp
yum install -y gcc openssl-devel pcre-devel
tar -xf tengine-2.1.2.tar.gz
mkdir -p /opt/platform/nginx/logs
cd tengine-2.1.2
./configure --prefix=/opt/platform/nginx --with-http_ssl_module --with-http_stub_status_module
make && make install

#替换nginx.conf
cd /opt/platform/nginx/conf
mv nginx.conf nginx.conf.bak
上传nginx.conf

#user  ops;
worker_processes auto;
worker_cpu_affinity auto; error_log logs/error.log error; pid logs/nginx.pid; worker_rlimit_nofile 65535; events {
use epoll;
worker_connections 65535;
} 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"'; log_format json '{"@timestamp":"$time_iso8601",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"http_host":"$http_host",'
'"request":"$request",'
'"status":"$status",'
'"body_bytes_sent":$body_bytes_sent,'
'"http_referer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"http_x_frowarded_for":"$http_x_forwarded_for",'
'"upstream_status":"$upstream_status",'
'"upstream_addr":"$upstream_addr",'
'"upstream_response_time":"$upstream_response_time",'
'"request_time":$request_time}'; access_log logs/access.log json; sendfile on;
#tcp_nopush on; keepalive_timeout 65; client_header_buffer_size 20m;
large_client_header_buffers 4 2048k;
client_max_body_size 20m;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k; proxy_ignore_client_abort on; #让代理服务端不要主动关闭客户端的连接。 gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/jpeg image/gif image/png application/javascript;
gzip_proxied any;
gzip_disable "MSIE [1-6]\."; server {
listen 80 default;
server_name _;
return 499;
} include /opt/platform/nginx/conf/vhosts/*.conf;
}

  

#增加web应用负载均衡配置文件
mkdir -p vhosts
cd vhosts
上传ken.conf

upstream ken {
server ip:port weight=4 max_fails=2 fail_timeout=30s;
server ip:port weight=4 max_fails=2 fail_timeout=30s;
} server {
listen 8080;
server_name _;
access_log logs/ken.log json; location / {
proxy_pass http://ken;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 10s;
proxy_send_timeout 150s;
proxy_read_timeout 150s;
proxy_next_upstream error timeout invalid_header http_404 http_500 http_502 http_504;
}
}

  

#配置文件生效
/opt/platform/nginx/sbin/nginx -s reload

安装keepalived
#上传tengine-2.1.2.tar.gz 在目录/tmp
#主机安装
cd /tmp
tar -xvf keepalived-nginx.tar.gz -C /opt/platform/

/opt/platform/keepalived/etc/keepalived/keepalived.conf

! Configuration File for keepalived

  global_defs {
router_id ken
} vrrp_script check_nginx {
script "/opt/platform/keepalived/bin/check.sh"
interval 2
timeout 2
fall 2
} vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 215
priority 99
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass ken@215
} track_script {
check_nginx
} virtual_ipaddress {
vip/24 brd mask
} notify_master "/opt/platform/keepalived/bin/notify.sh master"
notify_backup "/opt/platform/keepalived/bin/notify.sh backup"
notify_fault "/opt/platform/keepalived/bin/notify.sh fault"
notify_stop "/opt/platform/keepalived/bin/notify.sh stop"
}

  

另外一台机器安装方式一样,但是需要修改keepalived.conf的一个参数
priority 150 #将99调整为150

启动keepalived
cd /opt/platform/keepalived/sbin
sh startup.sh

nginx+keepalived高可用的更多相关文章

  1. Nginx入门篇(七)之Nginx+keepalived高可用集群

    一.keepalived介绍 keepalived软件最开始是转为负载均衡软件LVS而设计,用来管理和监控LVS集群系统中各个服务节点的状态,后来又加入了可实现高可用的VRRP功能.所以Keepali ...

  2. 使用Ansible实现nginx+keepalived高可用负载均衡自动化部署

    本篇文章记录通过Ansible自动化部署nginx的负载均衡高可用,前端代理使用nginx+keepalived,端web server使用3台nginx用于负载效果的体现,结构图如下: 部署前准备工 ...

  3. Nginx+keepalived(高可用主备模式)

    Nginx+keepalived(高可用主备模式) 环境:centos6.7 准备:两台服务器(虚拟机).两台应用(Tomcat).Nginx.keepalived server1:192.168.2 ...

  4. Nginx+keepalived(高可用双主模式)

    Nginx+keepalived(高可用双主模式) tips:前面已经介绍了nginx+keepalived高可用主从模式,今天补充下高可用的双主模式,均可以作为主机使用 server1:192.16 ...

  5. Nginx+Keepalived高可用集群应用实践

    Nginx+Keepalived高可用集群应用实践 1.Keepalived高可用软件 1.1 Keepalived服务的三个重要功能 1.1.1管理LVS负载均衡软件 早期的LVS软件,需要通过命令 ...

  6. Nginx知多少系列之(十四)Linux下.NET Core项目Nginx+Keepalived高可用(主从模式)

    目录 1.前言 2.安装 3.配置文件详解 4.工作原理 5.Linux下托管.NET Core项目 6.Linux下.NET Core项目负载均衡 7.负载均衡策略 8.加权轮询(round rob ...

  7. nginx+keepalived 高可用方案

    nginx+keepalived 高可用方案 准备工作 192.168.157.11 192.168.157.12 安装nginx 跟新yum源文件 rpm -ivh http://nginx.org ...

  8. nginx+keepalived高可用及双主模式

    高可用有2中方式. 1.Nginx+keepalived 主从配置 这种方案,使用一个vip地址,前端使用2台机器,一台做主,一台做备,但同时只有一台机器工作,另一台备份机器在主机器不出现故障的时候, ...

  9. nginx+keepalived高可用web负载均衡

    一:安装环境 准备2台虚拟机,都安装好环境 centos 7keepalived:vip: 192.168.1.112192.168.1.110 nginxip 192.168.1.109 maste ...

  10. nginx keepalived 高可用方案(转)

    转自: https://www.cnblogs.com/leeSmall/p/9356535.html 一.Nginx Rewrite 规则 1. Nginx rewrite规则 Rewrite规则含 ...

随机推荐

  1. Activity中使用PagerAdapter实现切换代码

    主活动 public class ViewPagerManager extends AppCompatActivity { private ViewPager viewPager; @Override ...

  2. AngularJS复习小结

    开发移动端App,首先得在头部 <meta name="viewport" content="width=device-width, initial-scale=1 ...

  3. python 查看源代码

    使用包inspect import inspect from mxnet import contrib 查看模块所在路径: inspect.getsourcefile(contrib) 查看源码: i ...

  4. pm2 配合log4js处理日志

    1.pm2启动时通常会发现log4js记录不到日志信息: 2.决解方案,安装pm2的pm2-intercom进程间通信模块 3.在log4js的配置文件logger.js里添加如下命令: pm2: t ...

  5. mysql 创建++删除 数据表

    创建表:CREATE TABLE IF NOT EXISTS `runoob_tbl`( `runoob_id` INT UNSIGNED AUTO_INCREMENT, `runoob_title` ...

  6. P1439 【模板】最长公共子序列 LCS

    P1439 [模板]最长公共子序列 题解 1.RE的暴力DP O(n2) 我们设dp[i][j]表示,S串的第i个前缀和T串的第j个前缀的最长公共子序列. ◦          分情况: ◦      ...

  7. 实现超简单的http服务器

    想在Linux下实现一个简单的web Server并不难.一个最简单的HTTP Server不过是一个高级的文件服务器,不断地接收客户端(浏览器)发送的HTTP请求,解析请求,处理请求,然后像客户端回 ...

  8. Linux Shell 自动备份脚本

    写一个使用shell脚本增量备份系统文件,顺便复习一下shell脚本相关的命令,这个脚本可以根据自己的需求来备份不同的文件或者文件夹,进行完整备份和增量备份. 参考的网址:http://blog.51 ...

  9. [ZT]Enhancement-01

    Enhancement(1)--BTEs 最近一个同事碰到一个FI的增强,要用BTEs实现,我也是第一次接触到这种增强,所以跟着他一起做了一下.写一个这方面的小节.    BTEs(Business ...

  10. git如何从远端获取某个文件

    git fetch git checkout origin/master -- path/folder/filename