使用lxc模拟服务器集群环境

这里将介绍如何使用lxc创建集群环境用于模拟服务器环境,方便测试项目。

系统环境ubuntu

创建router容器

lxc-create -n router -t debian

修改router的网卡配置

nano /etc/network/interface

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
	address 192.168.122.186
	netmask 255.255.255.0
	gateway 192.168.122.1


auto eth0:1
allow-hotplug eth0:1
iface eth0:1 inet static
    address 192.168.0.1
    netmask 255.255.0.0

添加nat转发
iptables -t nat -A POSTROUTING -s 0.0.0.0/0 -o eth0 -j MASQUERADE

创建srv容器

lxc-create -n router -t debian

修改srv1网卡配置

nano /etc/network/interface

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual
   pre-up   ifconfig $IFACE up
   pre-down ifconfig $IFACE down

auto br0
allow-hotplug br0
iface br0 inet static
    bridge_ports eth0
    address 192.168.1.1
    netmask 255.255.255.0
    gateway 192.168.0.1
修改dns

echo "nameserver 8.8.8.8" > /etc/resolv.conf

添加route

route add -net 192.168.0.0 netmask 255.255.0.0 dev br0

route add default gw 192.168.0.1

srv2 , srv3 ........都用上面的方式去创建区别是将 192.168.1.1 换成 192.168.1.2


container内安装lxc

首先需要安装lxc 

在srv里创建容器

lxc-create -n app -t debian 

容器配置如下 /usr/local/var/lib/lxc/app/config
lxc.network.mtu = 1500
lxc.network.type = veth
lxc.network.name = eth0
lxc.network.link = br0
lxc.network.ipv4 = 192.168.100.2/16
lxc.network.flags = up
lxc.network.ipv4.gateway = 192.168.0.1



你可能感兴趣的:(linux,Debian,集群,服务器,lxc)