debian 下安装 lxc

本文安装环境 debian 6.0

安装 lxc debootstrap 工具

aptitude install lxc bridge-utils debootstrap

设置网络

auto eth1
iface eth1 inet manual

auto br0
iface br0 inet static
  bridge_ports eth1  #根据自己实际网卡设置
  bridge_fd 0
  address 10.0.0.100
  netmask 255.255.255.0
  gateway 10.100.0.1
  dns-nameservers 10.20.0.2

加载 cgroup 编辑 /etc/fstab

cgroup  /sys/fs/cgroup  cgroup  defaults  0   0

立即加载

mount /sys/fs/cgroup

接下来创建一下虚拟机

#下载 squeeze  64位
debootstrap --verbose --variant=minbase --arch=amd64 --include ifupdown,locales,libui-dialog-perl,\
dialog,netbase,net-tools,iproute,openssh-server,vim,apt-utils,proxychains \
squeeze /var/cache/lxc/debian/rootfs-amd64 http://mirrors.163.com/debian/


mkdir -p /lxc/vm0     #存放目录

/usr/lib/lxc/templates/lxc-debian -p /lxc/vm0/   # 创建虚拟机

配置虚拟机网络,在 /lxc/vm0/config 文件填加些文本

lxc.utsname = vm0
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
# lxc.network.name = eth0
lxc.network.hwaddr = 00:FF:12:34:56:78
lxc.network.ipv4 = 10.0.0.110/24

到些整个虚拟机创建完成,接下来我们启动他

lxc-start -n vm0 -f /lxc/vm0/config

一些常用命令

lxc-info -n vm0 # 查看状态
lxc-stop -n vm0 # 关闭虚拟机

后边陆续添加如何对 lxc虚拟机 进行资源限制

debian 下 lxc 限制内存出错

起动 vm 的时候出现

lxc-start: open /cgroup/vm0/memory.limit_in_bytes : No such file or directory
lxc-start: failed to setup the cgroups for ‘vm0’
lxc-start: failed to setup the container
lxc-start: invalid sequence number 1. expected 2
lxc-start: failed to spawn ‘vm0’

在 /etc/default/grub 文件填加

GRUB_CMDLINE_LINUX="cgroup_enable=memory"
0# lxc-checkconfig 
Kernel config /proc/config.gz not found, looking in other places...
Found kernel config file /boot/config-2.6.32-5-amd64
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled

--- Control groups ---
Cgroup: enabled
Cgroup namespace: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: missing
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled

debian bridge 网卡参数说明

bridge_fd is the bridge forward delay time, in seconds, default 15.

bridge_hello is the bridge hello time, in seconds, default 2.

bridge_maxage is the bridge’s maximum message time, in seconds, default is 20.

bridge_stp controls the spanning tree protocol, on or off. Default is off, and is recommended to stay that way.

lxc guest 报错 respawning too disabled minutes

INIT: Id "c1" respawning too fast: disabled for 5 minutes
INIT: Id "c4" respawning too fast: disabled for 5 minutes
INIT: Id "c1" respawning too fast: disabled for 5 minutes
INIT: Id "c2" respawning too fast: disabled for 5 minutes
INIT: Id "c3" respawning too fast: disabled for 5 minutes
INIT: Id "c4" respawning too fast: disabled for 5 minutes
INIT: Id "c1" respawning too fast: disabled for 5 minutes
INIT: Id "c2" respawning too fast: disabled for 5 minutes
INIT: Id "c3" respawning too fast: disabled for 5 minutes
INIT: Id "c4" respawning too fast: disabled for 5 minutes

解决方法 编辑 /etc/inittab

#c1:12345:respawn:/sbin/getty 38400 tty1 linux
#c2:12345:respawn:/sbin/getty 38400 tty2 linux
#c3:12345:respawn:/sbin/getty 38400 tty3 linux
#c4:12345:respawn:/sbin/getty 38400 tty4 linux

mysql 5.5 半同步停止工作

两台 mysql 5.5 服务器互为主从,使且半同步模式,网络终断后,但是 同步未能恢复

mysql>  show status like 'Rpl_%';
+--------------------------------------------+-------------+
| Variable_name                              | Value       |
+--------------------------------------------+-------------+
| Rpl_semi_sync_master_clients               | 0           |
| Rpl_semi_sync_master_net_avg_wait_time     | 213         |
| Rpl_semi_sync_master_net_wait_time         | 51387187879 |
| Rpl_semi_sync_master_net_waits             | 240543674   |
| Rpl_semi_sync_master_no_times              | 2           |
| Rpl_semi_sync_master_no_tx                 | 6402        |
| Rpl_semi_sync_master_status                | OFF         |
| Rpl_semi_sync_master_timefunc_failures     | 0           |
| Rpl_semi_sync_master_tx_avg_wait_time      | 276         |
| Rpl_semi_sync_master_tx_wait_time          | 68522585281 |
| Rpl_semi_sync_master_tx_waits              | 248230976   |
| Rpl_semi_sync_master_wait_pos_backtraverse | 1101735     |
| Rpl_semi_sync_master_wait_sessions         | 0           |
| Rpl_semi_sync_master_yes_tx                | 240799932   |
| Rpl_semi_sync_slave_status                 | ON          |
| Rpl_status                                 | AUTH_MASTER |
+--------------------------------------------+-------------+

恢复操作

STOP SLAVE;
CHANGE MASTER TO master_heartbeat_period= milliseconds;
START SLAVE;