一、前言
公司的数据库、windows机器都没有外网IP的,都是用一台linux机器的iptables做的nat映射,当机器多了会发现iptables就成了性能瓶颈,于是找到了redir这个端口映射工具,此工具只支持http协议的哦,性能比iptables强多了,redir用了几天发现有时候进程会莫名其妙掉了,所以找到了小米开源的进程管理工具frigga,二者结合一切搞定。
二、软件安装配置
1、redir安装配置
A、redir安装
yum -y install redir
B、redir配置
redir --lport=对外提供服务端口 --caddr=需要映射的内网IP --cport=要映射的内网端口
2、frigga安装配置
A、frigga安装
#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配置
添加一条映射例子: 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的访问端口、账号信息定义
[root@localhost conf]# cat /opt/frigga/conf/frigga.yml --- port: 9000 http_auth: ["admin", "123456"]
转载于:https://blog.51cto.com/navyaijm/1307041