![Gitter](https://badges.gitter.im/Join Chat.svg)
mruby-ipvs is an interface to the IP Virtual Server(IPVS) for mruby.
- Install dependencies.
apt-get -y install libnl-dev # or yum -y install libnl-devel, and so on...
- clone mruby
git clone https://github.com/mruby/mruby/ /usr/local/src/mruby
- add
conf.gem
line tobuild_config.rb
(/usr/local/src/mruby/build_config.rb
).
MRuby::Build.new do |conf|
# ... (snip) ...
conf.gem :git => 'https://github.com/rrreeeyyy/mruby-ipvs.git', :options => '--recursive'
end
- build mruby
cd /usr/local/src/mruby && ruby ./minirake
- check the instllation
/usr/local/src/mruby/build/host/bin/mruby -e 'p IPVS'
IPVS
- add service.
# Create IPVS::Service instance.
s = IPVS::Service.new({
'addr' => '10.0.0.1:80',
'port' => 80,
'sched_name' => 'wrr'
})
# apply to IPVS.
s.add_service
- add destination.
# Create IPVS::Dest instance.
d1 = IPVS::Dest.new({
'addr' => '192.168.0.1',
'port' => 80,
'weight' => 1
})
d2 = IPVS::Dest.new({
'addr' => '192.168.0.2',
'port' => 80,
'weight' => 1,
'conn' => 'DR'
})
# Add destination to IPVS::Service instance.
s.add_dest(d1)
s.add_dest(d2)
# Change the destination weight, connection flag.
d1.weight = 3
d2.conn = 'TUN'
- sync daemon start/stop
# Create IPVS::Daemon instance.
daemon = IPVS::Daemon.new({
'state' => 'master', # "master" or "backup"
'ifname' => 'eth0',
'syncid' => 1
})
daemon.start() # you can daemon.stop() after start.
- check the results
$ cat /proc/net/ip_vs
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 0A000001:0050 wrr
-> C0A80002:0050 Tunnel 1 0 0
-> C0A80001:0050 Masq 3 0 0
- check the sync daemon multicast group
# netstat -anu | grep 224.0.0.81:8848
udp 0 0 10.0.2.15:50758 224.0.0.81:8848 ESTABLISHED
- more examples in
examples/
.- examples/keepalived.rb: keepalived like DSL.
Local Source Testing (Requirements: Vagrant)
$ git clone https://github.com/rrreeeyyy/mruby-ipvs/
$ cd mruby-ipvs
$ git submodule update --init
$ vagrant up
$ vagrant ssh -c 'cd /usr/local/src/mruby && rake test'
- [in Japanese] http://rrreeeyyy.com/blog/2014/03/17/mruby-ipvs/ (blog)
- [in Japanese] https://speakerdeck.com/rrreeeyyy/mruby-ipvs (presentation)
- [in Japanese] http://rrreeeyyy.com/thesis/thesis.pdf (graduation thesis)
- Fork it ( https://github.com/rrreeeyyy/mruby-ipvs/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
GNU General Public License Version 2