Hướng dẫn cài đặt và sử dụng OpenVZ trên CentOS 6.0 docx

12 823 2
Hướng dẫn cài đặt và sử dụng OpenVZ trên CentOS 6.0 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Hướng dẫn cài đặt sử dụng OpenVZ CentOS 6.0 OpenVZ nhánh mã nguồn mở Virtuozzo SWsoft cung cấp Đây giải pháp ảo hóa thương mại sử dụng nhiều nhà cung cấp máy chủ ảo hóa Các vá nhân OpenVZ cấp phép theo giấy phép GLP công cụ cấp người dùng theo giấy phép QPL Với OpenVZ bạn tạo nhiều máy chủ riêng ảo (VPS) phần cứng tương tự Xen dự án Linux Vserver Trong hướng dẫn giúp bạn chuẩn bị máy chủ CentOS 6.0 cho OpenVZ Ảnh minh họa hệ thống mạng sử dụng cơng nghệ ảo hóa Cài đặt OpenVZ Để cài đặt OpenVZ, cần thêm kho OpenVZ cho yum: cd /etc/yum.repos.d wget http://download.openvz.org/openvz.repo rpm import http://download.openvz.org/RPM-GPG-KeyOpenVZ Bây mở openvz.repo vi openvz.repo … vơ hiệu hóa kho lưu trữ [openvz-kernel-rhel5] (đặt enabled=0) thay vào kích hoạt kho [openvz-kernel-rhel6] (đặt enabled=1): [ ] [openvz-kernel-rhel5] name=OpenVZ RHEL5-based kernel #baseurl=http://download.openvz.org/kernel/branches/rhe l5-2.6.18/current/ mirrorlist=http://download.openvz.org/kernel/mirrorsrhel5-2.6.18 enabled=0 gpgcheck=1 gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ [ ] [openvz-kernel-rhel6] name=OpenVZ RHEL6-based kernel #baseurl=http://download.openvz.org/kernel/branches/rhe l6-2.6.32/current/ mirrorlist=http://download.openvz.org/kernel/mirrorsrhel6-2.6.32 enabled=1 gpgcheck=1 gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ [ ] Nội dung kho lưu trữ nhân (kernel) OpenVZ có vài khác biệt (bạn xem chi tiết đây) Chạy dòng lệnh: yum search vzkernel Và số kernel có sẵn: [root@server1 yum.repos.d]# yum search vzkernel [ ] vzkernel.i686 : The Linux kernel vzkernel.x86_64 : The Linux kernel vzkernel-debug.i686 : The Linux kernel compiled with extra debugging enabled vzkernel-debug.x86_64 : The Linux kernel compiled with extra debugging enabled vzkernel-debug-devel.i686 : Development package for building kernel modules to match the debug kernel vzkernel-debug-devel.x86_64 : Development package for building kernel modules to match the debug kernel vzkernel-devel.i686 : Development package for building kernel modules to match the kernel vzkernel-devel.x86_64 : Development package for building kernel modules to match the kernel vzkernel-firmware.noarch : Firmware files used by the Linux kernel vzkernel-headers.i686 : Header files for the Linux kernel for use by glibc vzkernel-headers.x86_64 : Header files for the Linux kernel for use by glibc [root@server1 yum.repos.d]# Chọn số tiến hành cài đặt: yum install vzkernel Điều tự động update nạp khởi động GRUB tốt Chúng ta nên mở /boot/grub/menu.lst; đoạn kernel lúc nên chứa nội dung kernel OpenVZ Tiêu đề bạn đặt "CentOS Linux" Ngoài chắn giá trị default để kernel (OpenVZ kernel) tự động khởi động thay CentOS kernel mặc định vi /boot/grub/menu.lst # grub.conf generated by anaconda # # Note that you not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition This means that # all kernel and initrd paths are relative to /boot/, eg # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/mapper/vg_server1-lv_root # initrd /initrd-[generic-]version.img #boot=/dev/sda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title CentOS Linux OpenVZ (2.6.32-042stab020.1) root (hd0,0) kernel /vmlinuz-2.6.32-042stab020.1 ro root=/dev/mapper/vg_server1-lv_root rd_LVM_LV=vg_server1/lv_root rd_LVM_LV=vg_server1/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=de crashkernel=auto rhgb quiet initrd /initramfs-2.6.32-042stab020.1.img title CentOS (2.6.32-71.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-71.el6.x86_64 ro root=/dev/mapper/vg_server1-lv_root rd_LVM_LV=vg_server1/lv_root rd_LVM_LV=vg_server1/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=de crashkernel=auto rhgb quiet initrd /initramfs-2.6.32-71.el6.x86_64.img Bầy tiến hành cài đặt OpenVZ sử dụng công cụ: yum install vzctl vzquota Mở /etc/sysctl.conf chắn bạn có thiết lập đây: vi /etc/sysctl.conf [ ] net.ipv4.ip_forward = net.ipv4.conf.default.proxy_arp = net.ipv4.conf.all.rp_filter = kernel.sysrq = net.ipv4.conf.default.send_redirects = net.ipv4.conf.all.send_redirects = net.ipv4.icmp_echo_ignore_broadcasts=1 net.ipv4.conf.default.forwarding=1 [ ] Nếu bạn muốn chỉnh sửa /etc/sysctl.conf, chạy lệnh: sysctl -p Lưu ý: Các bước quan trọng địa IP máy ảo từ Subnet khác với địa IP hệ thống máy chủ Nếu bạn khơng thực xác theo bước này, kết nối mạng không hoạt động máy ảo! Mở /etc/vz/vz.conf thiết lập NEIGHBOUR_DEVS cho toàn bộ: vi /etc/vz/vz.conf [ ] NEIGHBOUR_DEVS=all [ ] SELinux cần phải vô hiệu hóa bạn muốn sử dụng OpenVZ Mở /etc/sysconfig/selinux thiết lập giá trị SELINUX thành disabled: vi /etc/sysconfig/selinux # This file controls the state of SELinux on the system # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced # permissive - SELinux prints warnings instead of enforcing # disabled - No SELinux policy is loaded SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection SELINUXTYPE=targeted Cuối khởi động lại hệ thống: reboot Nếu hệ thống reboot lại mà không gặp cố nào, chạy tiếp lệnh sau: uname -r Và kernel OpenVZ hiển thị sau: [root@server1 ~]# uname -r 2.6.32-042stab020.1 [root@server1 ~]# Sử dụng OpenVZ Trước tạo máy ảo với OpenVZ, cần có template cho distribution mà muốn sử dụng máy ảo đường dẫn /vz/template/cache Máy ảo tạo từ template Bạn tìm thấy danh sách template precreated Ví dụ muốn sử dụng Fedora 15 máy ảo mình, tải Fedora 15 template: cd /vz/template/cache wget http://download.openvz.org/template/precreated/beta/fed ora-15-x86.tar.gz Và sau lệnh để sử dụng OpenVZ: Để thiết lập VPS từ Fedora 15 template, chạy lệnh: vzctl create 101 ostemplate fedora-15-x86 config basic Thông số 101 phải unique ID, máy ảo cần có unique ID riêng Bạn sử dụng phần cuối địa IP cho máy ảo, chẳng hạn bạn có địa 192.168.0.101, bạn dùng số 101 làm ID Nếu bạn muốn VM khởi động boot, chạy lệnh: vzctl set 101 onboot yes save Thiết lập hostname địa IP cho VM: vzctl set 101 hostname test.example.com save vzctl set 101 ipadd 192.168.0.101 save Tiếp theo, thiết lập số socket lên tới 120 gán tên máy chủ cho VM: vzctl set 101 numothersock 120 save vzctl set 101 nameserver 8.8.8.8 nameserver 8.8.4.4 nameserver 145.253.2.75 save (Thay sử dụng lệnh vzctl set, bạn chỉnh sửa trực tiếp tập tin cấu hình VM kho lưu trữ đường dẫn /etc/vz/conf Nếu ID VM 101, sau tiến hành cấu hình lại tập tin /etc/vz/conf/101.conf) Để khởi động VM, chạy lệnh: vzctl start 101 Thiết lập mật root cho VM, thực thi lệnh: vzctl exec 101 passwd Bây bạn thực kết nối tới VM thông qua SSH (chẳng hạn với PuTTY) nhập vào lệnh sau: vzctl enter 101 Để thoát khỏi giao diện điều khiển VM, sử dụng lênh: exit Để dừng hẳn VM, chạy lệnh: vzctl stop 101 Để restart VM, chạy lệnh: vzctl restart 101 Để xóa VM từ ổ đĩa cứng (bạn phải dừng hẳn lại trước làm điều này), chạy lệnh: vzctl destroy 101 Để xem danh sách VM bạn trạng thái chúng, dùng lệnh: vzlist -a [root@server1 cache]# vzlist -a CTID E NPROC STATUS IP_ADDR HOSTNAM 101 14 running 192.168.0.101 test.ex ample.com [root@server1 cache]# Để xem nguồn tài nguyên phân bổ cho VM, nhập vào dòng lệnh sau: vzctl exec 101 cat /proc/user_beancounters [root@server1 cache]# vzctl exec 101 cat /proc/user_beancounters Version: 2.5 uid resource barrier limit 101: 11055923 held 1508202 kmemsize 11377049 5430 19 21 2489 2775 0 0 numproc 240 0 21504 381 69632 dummy 7102 shmpages 21504 381 256 privvmpages 65536 1661695 failcnt lockedpages 256 maxheld 240 physpages 2147483647 vmguarpages 33792 2147483647 oomguarpages 2489 44720 13144 11 2703360 2097152 262144 120 3624960 numfile 9312 9312 dummy 0 0 dcachesize 3409920 531 numothersock 120 503 2703360 dgramrcvbuf 262144 13 othersockbuf 1126080 8380 256 tcprcvbuf 1720320 14356 tcpsndbuf 1720320 0 numsiginfo 256 81920 206 16 numpty 16 360 numflock 188 numtcpsock 360 26112 2147483647 2775 dummy 0 0 10 10 numiptent 128 0 dummy 0 128 [root@server1 cache]# Ở bạn lưu ý đến cột failcnt quan trọng, phép chứa giá trị 0, khơng có nghĩa VM cần dùng nhiều nguồn tài nguyên phân bổ cho Mở tập tin cấu hình VM /etc/vz/conf tăng thêm tài nguyên, sau khởi động lại VM Để tìm hiểu thêm lệnh vzctl, chạy: man vzctl ... http://download .openvz. org /openvz. repo rpm import http://download .openvz. org/RPM-GPG-KeyOpenVZ Bây mở openvz. repo vi openvz. repo … vơ hiệu hóa kho lưu trữ [openvz- kernel-rhel5] (đặt enabled=0) thay vào... -r Và kernel OpenVZ hiển thị sau: [root@server1 ~]# uname -r 2.6.32-042stab020.1 [root@server1 ~]# Sử dụng OpenVZ Trước tạo máy ảo với OpenVZ, cần có template cho distribution mà muốn sử dụng. .. mirrorlist=http://download .openvz. org/kernel/mirrorsrhel5-2.6.18 enabled=0 gpgcheck=1 gpgkey=http://download .openvz. org/RPM-GPG-Key -OpenVZ [ ] [openvz- kernel-rhel6] name =OpenVZ RHEL6-based kernel

Ngày đăng: 07/03/2014, 01:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan