debian openvz vps 优化

比较喜欢 debian vps ,系统比较简洁,而且很省内存,但大部分的 vps 商都使用的标准模版,带了不少垃圾东西。

首先进行系统更新

apt-get update && apt-get upgrade

安装sysv-rc-conf做为开机管理项

apt-get install sysv-rc-conf

先删除 apache 相关,使用 nginx 代替

apt-get remove --purge apache*

删除sendmail 相关

apt-get remove --purge sendmail* sasl2-bin

删除bind9相关

apt-get remove --purge bind9-*

删除xinetd 相关

apt-get remove --purge xinetd 

删除samba相关

apt-get remove --purge samba-*

删除rpcbind相关

apt-get remove --purge rpcbind

阿里云(aliyun)青岛节点挂载硬盘io测试

杭州节点已经停售了,在青岛订购了一台,贴上测试结果。

fdisk -l

Disk /dev/xvda: 21.5 GB, 21474754560 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00090497

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        2611    20969472   83  Linux

Disk /dev/xvdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/xvdb doesn't contain a valid partition table

分区

fdisk /dev/xvdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xbe797f61.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6527, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): 
Using default value 6527

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


格式成 ext3

mkfs.ext3 /dev/xvdb1

挂载分区

mkdir /pub
mount /dev/xvdb1 /pub

写入速度测试

dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
4096+0 records in
4096+0 records out
268435456 bytes (268 MB) copied, 81.2347 s, 3.3 MB/s

好可怜啊。。

cpu 信息

cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 45
model name	: Intel(R) Xeon(R) CPU E5-2420 0 @ 1.90GHz
stepping	: 7
cpu MHz		: 1900.054
cache size	: 15360 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good pni ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm
bogomips	: 3800.10
clflush size	: 64
cache_alignment	: 64
address sizes	: 46 bits physical, 48 bits virtual
power management:

processor	: 1
vendor_id	: GenuineIntel
cpu family	: 6
model		: 45
model name	: Intel(R) Xeon(R) CPU E5-2420 0 @ 1.90GHz
stepping	: 7
cpu MHz		: 1900.054
cache size	: 15360 KB
physical id	: 2
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 2
initial apicid	: 2
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good pni ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm
bogomips	: 3808.34
clflush size	: 64
cache_alignment	: 64
address sizes	: 46 bits physical, 48 bits virtual
power management:

内存信息

free -m
             total       used       free     shared    buffers     cached
Mem:          2011        809       1202          0        123        615
-/+ buffers/cache:         70       1940
Swap:            0          0          0

系统信息

cat /etc/issue
Debian GNU/Linux 6.0 \n \l
					

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虚拟机 进行资源限制