frigga+redir实现高性能端口映射

原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://navyaijm.blog.51cto.com/4647068/1307041

一、前言

公司的数据库、windows机器都没有外网IP的,都是用一台linux机器的iptables做的nat映射,当机器多了会发现iptables就成了性能瓶颈,于是找到了redir这个端口映射工具,此工具只支持http协议的哦,性能比iptables强多了,redir用了几天发现有时候进程会莫名其妙掉了,所以找到了小米开源的进程管理工具frigga,二者结合一切搞定。

二、软件安装配置

1、redir安装配置

A、redir安装

1
yum -y  install  redir

B、redir配置

1
redir --lport=对外提供服务端口 --caddr=需要映射的内网IP --cport=要映射的内网端口

2、frigga安装配置

A、frigga安装

1
2
3
4
5
6
7
8
9
10
11
12
13
#install ruby
yum -y  install  ruby gems
#update ruby
curl -L https: //get .rvm.io |  bash  -s stable
source   /etc/profile
rvm  install  ruby-1.9.3
#安装bundle
gem  install  bundle
#install frigga
cd  /opt/
git clone https: //github .com /xiaomi-sa/frigga .git
cd  /opt/frigga
. /script/run .rb start

B、frigga配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
添加一条映射例子:
cd /opt/frigga/gods/
vi  10.10 . 10 .10_3389.god 内容如下:
God.watch  do  |w|
w.name =  " proxy.kisops.com-9004__10.10.10.10-3389__WindowsOpVm "
w.start =  " redir  --lport=9004 --caddr=10.10.10.10 --cport=3389  --debug "
w.process_log =  " /data/log/redir/10.10.10.10_3389.log "
w.keepalive
w.:clean_pid_file)
w.stop_timeout  =  60 .seconds
w.lifecycle  do  |on|
on.condition(:flapping)  do  |c|
c.to_state = [:start, :restart]
c.times =  5
c.within =  5 .minute
c.transition = :unmonitored
c.retry_in =  10 .minutes
c.retry_times =  5
c.retry_within =  2 .hours
c.notify =  'proc_down'
end
end
end
God.contact(:email)  do  |c|
c.name =  'proc_down'
c.group =  'developers'
c.to_email =  "navyaijm@ijinshan.com"
end
#启动
god load  10.10 . 10 .10_3389.god
说明:
##生成配置文件,以.god后缀结尾,参考配置文件如下,需要修改的我标红
##name格式: proxy.kisops.com-外网端口__内网IP-内网端口__用途
##start格式:  redir --lport=外网端口  --caddr=内网IP  --cport=内网端口  --debug
##log格式:  /data/log/redir/内网IP_端口.log
##当进程异常,会导致god不断重启
###使用:flapping条件
## 5 分钟内start或者restart进程  5 次,如果启动失败,修改状态为unmonitored
## 10 分钟后再次尝试启动,如果 2 个小时内,尝试 5 次都失败,彻底放弃

3、frigga的访问端口、账号信息定义

1
2
3
4
[root@localhost conf]# cat /opt/frigga/conf/frigga.yml
---
port:  9000
http_auth: [ "admin" "123456" ]

192655500.jpg

本文出自 “屌丝运维男” 博客,请务必保留此出处http://navyaijm.blog.51cto.com/4647068/1307041

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值