Skip to content

Instantly share code, notes, and snippets.

@murachi1208
Last active March 27, 2019 13:12
Show Gist options
  • Save murachi1208/de1c99251896305a51cf to your computer and use it in GitHub Desktop.
Save murachi1208/de1c99251896305a51cf to your computer and use it in GitHub Desktop.
Vagrant で CentOS6.6, LVS (IPVS) の NAT 転送方法をためしてみる, その1 ref: http://qiita.com/murachi1208/items/dafcd2d4b1a7d52bfec0
config.vm.define :nictest do |node|
node.vm.network :public_network, ip: "192.168.0.201"
node.vm.network :private_network, ip: "192.168.11.117"
end
$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:4f:b8:06 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
inet6 fe80::a00:27ff:fe4f:b806/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:e0:ee:d2 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.201/24 brd 192.168.0.255 scope global eth1
inet6 fe80::a00:27ff:fee0:eed2/64 scope link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:10:b4:f6 brd ff:ff:ff:ff:ff:ff
inet 192.168.11.117/24 brd 192.168.11.255 scope global eth2
inet6 fe80::a00:27ff:fe10:b4f6/64 scope link
valid_lft forever preferred_lft forever
# lvs
config.vm.define :nictest do |node|
node.vm.hostname = "lvs"
node.vm.network :public_network, ip: "192.168.0.201"
node.vm.network :private_network, ip: "192.168.11.117"
end
# node1
config.vm.define :node1 do |node|
node.vm.hostname = "node1"
node.vm.network :private_network, ip: "192.168.11.118"
end
# node2
config.vm.define :node2 do |node|
node.vm.hostname = "node2"
node.vm.network :private_network, ip: "192.168.11.119"
end
$ sudo yum install ipvsadm
$ sudo vi /etc/sysctl.conf
net.ipv4.ip_forward = 1 ← 0を1に
$ sudo /sbin/sysctl -p
$ sudo /sbin/sysctl -a | grep net.ipv4.ip_forward
$ sudo ipvsadm -C
$ sudo ipvsadm -A -t 192.168.0.201:80 -s rr
$ sudo ipvsadm -a -t 192.168.0.201:80 -r 192.168.11.118:80 -m
$ sudo ipvsadm -a -t 192.168.0.201:80 -r 192.168.11.119:80 -m
$ sudo /etc/init.d/ipvsadm save
$ sudo cat /etc/sysconfig/ipvsadm
$ sudo chkconfig ipvsadm on
$ sudo ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.0.201:http rr
-> 192.168.11.118:http Masq 1 0 0
-> 192.168.11.119:http Masq 1 0 0
$ sudo su
# yum install httpd
# sudo service httpd start
# chkconfig httpd on
# echo "node" > /var/www/html/index.html
$ sudo route add default gw 192.168.11.117
$ netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
0.0.0.0 192.168.11.117 0.0.0.0 UG 0 0 0 eth1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment