[KVM] Hướng dẫn cài đặt WebVirtCloud quản lí hạ tầng KVM

30/12/2020
KVM

Quên virt-manager đi! Hãy sử dụng một công cụ quản lí tập trung hạ tầng KVM của bạn một cách hiệu quả hơn, tiện dụng hơn. Sau đây tôi xin giới thiệu các bước cài đặt WebVirtCloud

Trước đây, chúng ta thường sử dụng các công cụ như virt-manager, webvirt, kimchi hay virsh… để quản trị các máy chủ KVM. Nhưng mỗi phần mềm đều tồn tại những điểm yếu nhất định, có thể đây sẽ giải quyết các vấn đề còn tồn đọng đó.

Mô hình cài đặt

Phân hoạch địa chỉ IP

Các bước cài đặt

Ở bài viết này tôi sử dụng node webvirtcloud để quản lý hạ tầng máy chủ KVM, vì vậy trước khi bắt đầu cài đặt chúng ta phải có các máy chủ KVM trước đó hoặc cài đặt nó.

Bước 1: Cài đặt KVM

Trong bài viết trước tôi đã hướng dẫn các bạn cài đặt KVM trên hai hệ điều hành Ubuntu server và CentOS ở hai bài viết dưới đây

Để có thể kết nối KVM đến WebvirtCloud, cần thêm một số bước sau :

  • Chỉnh sửa file cấu hình libvirt như sau:
vi /etc/libvirt/libvirtd.conf
listen_tls = 0 listen_tcp = 1 tcp_port = "16509" listen_addr = "0.0.0.0" auth_tcp = "none"  
  • Chỉnh sửa file /etc/sysconfig/libvirtd  : bỏ dấu # ở dòng sau :
LIBVIRTD_ARGS="--listen"
  • Cho phép port 16509 của libvirt và dải port 5900-5999 của VNC đi qua firewalld:
firewall-cmd --permanent --add-port=16509/tcp firewall-cmd --permanent --add-port=5900-5999/tcp firewall-cmd --reload
  • Restart lại dịch vụ libvirt :
systemctl restart libvirtd

Bước 2: Cài đặt WebVirtCloud trên CentOS 7

2.0 SSH đến node WebVirtCloud

ssh [email protected]

2.1 Cài đặt các packages cần thiết

yum install epel-release -y yum -y install python-virtualenv python-devel libvirt-devel glibc gcc nginx supervisor python-lxml git python-libguestfs

2.2 Tạo thư mục và clone source code từ trang chủ về

cd /srv git clone https://github.com/retspen/webvirtcloud && cd webvirtcloud git checkout 1e2fbc8 cp webvirtcloud/settings.py.template webvirtcloud/settings.py

2.3 Thay thế secret key

[root@webvirtcloud webvirtcloud]# pwd /srv/webvirtcloud

Thay đổi chuỗi secret key trong file settings.py bằng một đoạn string ngẫu nhiên mà chỉ mỗi bạn sở hữu

vim webvirtcloud/settings.py

Như sau

SECRET_KEY = 'minhdeptrai'

2.4 Cài đặt webvirtcloud

[root@webvirtcloud webvirtcloud]# pwd /srv/webvirtcloud
virtualenv venv source venv/bin/activate venv/bin/pip install -r conf/requirements.txt cp conf/nginx/webvirtcloud.conf /etc/nginx/conf.d/ venv/bin/python manage.py migrate

2.5 Cấu hình supervisor

Thêm các cấu hình sau vào cuối file /etc/supervisord.conf

cp /etc/supervisord.conf /etc/supervisord.conf.bk vim /etc/supervisord.conf

Như sau

[program:webvirtcloud] command=/srv/webvirtcloud/venv/bin/gunicorn webvirtcloud.wsgi:application -c /srv/webvirtcloud/gunicorn.conf.py directory=/srv/webvirtcloud user=nginx autostart=true autorestart=true redirect_stderr=true  [program:novncd] command=/srv/webvirtcloud/venv/bin/python /srv/webvirtcloud/console/novncd directory=/srv/webvirtcloud user=nginx autostart=true autorestart=true redirect_stderr=true

2.6 Cấu hình nginx

Comment lại block server trong file /etc/nginx/nginx.conf

vim /etc/nginx/nginx.conf 

Như sau

#    server { #        listen       80 default_server; #        listen       [::]:80 default_server; #        server_name  _; #        root         /usr/share/nginx/html; # #        # Load configuration files for the default server block. #        include /etc/nginx/default.d/*.conf; # #        location / { #        } # #        error_page 404 /404.html; #            location = /40x.html { #        } # #        error_page 500 502 503 504 /50x.html; #            location = /50x.html { #        } #    }

Sau đó chỉnh sửa file /etc/nginx/conf.d/webvirtcloud.conf

vim /etc/nginx/conf.d/webvirtcloud.conf

Như sau

upstream gunicorn_server {     #server unix:/srv/webvirtcloud/venv/wvcloud.socket fail_timeout=0;     server 127.0.0.1:8000 fail_timeout=0; } server {     listen 80;      server_name servername.domain.com;     access_log /var/log/nginx/webvirtcloud-access_log;       location /static/ {         root /srv/webvirtcloud;         expires max;     }      location / {         proxy_pass http://gunicorn_server;         proxy_set_header X-Real-IP $remote_addr;         proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;         proxy_set_header Host $host:$server_port;         proxy_set_header X-Forwarded-Proto $remote_addr;         proxy_connect_timeout 600;         proxy_read_timeout 600;         proxy_send_timeout 600;         client_max_body_size 1024M;     } }

2.7 Phần quyền cho các thư mục

Phân quyền cho user nginx có thể đọc được file trong thư mục chứa code

chown -R nginx:nginx /srv/webvirtcloud

Phần quyền cho selinux

yum install policycoreutils-python -y setenforce 0 semanage fcontext -a -t httpd_sys_content_t "/srv/webvirtcloud(/.*)"

2.8 Cấu hình firewalld

firewall-cmd --permanent --add-port=80/tcp firewall-cmd --permanent --add-port=6080/tcp firewall-cmd --reload

2.9 Restart và Enable services

systemctl restart nginx && systemctl restart supervisord systemctl enable nginx && systemctl enable supervisord

2.10 Truy cập web sau đó add các nodes KVM

Truy cập đường dẫn

http://10.10.10.172

Login với user mặc định admin/admin. Sau đó add nodes

Một số hình ảnh mô tả thêm

Sau đây là một số hình ảnh từ trang chủ, ở bài viết sau tôi sẽ hướng dẫn các bạn cách sử dụng nó

Như vậy là bạn đã bước đầu setup thành công WebVirtCloud. Hẹn các độc giả ở những bài viết tiếp sau. 🙂

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Setting up Libvirt QEMU and KVM stack on Debian

QEMU-KVM based virtualization is at the heart of Linux based virtualization stack. It is free and open source and is one...
29/12/2020

[KVM][CentOS-7] Hướng dẫn cài đặt KVM trên CentOS-7

KVM (Kernel-based Virtual Machine) được biết đến là một cơ sở hạ tầng ảo hóa cho nhân Linux dành...
30/12/2020

[KVM] Hướng dẫn sử dụng WebVirtCloud

Sau bài cài đặt, mình đã dành vài ngày để thử nghiệm các tính năng và cách sử dụng của WebVirtCloud....
30/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

SỰ KHÁC BIỆT GIỮA RESIDENTIAL PROXY VÀ PROXY DATACENTER
17/02/2024

Mua Proxy v6 US Private chạy PRE, Face, Insta, Gmail
07/01/2024

Mua shadowsocks và hướng dẫn sữ dụng trên window
05/01/2024

Tại sao Proxy Socks lại được ưa chuộng hơn Proxy HTTP?
04/01/2024

Mua thuê proxy v4 nuôi zalo chất lượng cao, kinh nghiệm tránh quét tài khoản zalo
02/01/2024