KVM之web管理工具webvirtmgr安裝
由于一直使用命令行對kvm虛擬機進(jìn)行管理,雖然某些操作很快捷圾亏,但是有新同事對kvm不熟悉的時候就需要一個界面管理工具來對kvm虛擬機進(jìn)行操作了拇勃,webvirtmgr是一個aliyun平臺的超級簡化版界面管理工具准给,基于python編程摹迷、數(shù)據(jù)庫由sqlite3提供支持對kvm進(jìn)行管理宵凌,支持通過tcp供搀、ssh隅居、TLS、socket等方式對kvm服務(wù)器進(jìn)行連接管理葛虐。界面也是極為簡潔胎源,很適合輕量化管理屿脐。
webvirtmgr安裝
依賴組件安裝
由于webvirtmgr基于python編程所以需要安裝相關(guān)的python模塊:python-pip libvirt-python python-websockify libxml2-python supervisor Nginx novnc
pip : python 模塊、包管理工具
libvirt-python: libvirt的python接口
supervisor : python 專用的后臺進(jìn)程管理工具,它可以讓python程序變?yōu)楹笈_daemon的诵,
并監(jiān)控其進(jìn)程狀態(tài),異常退出時可以自動重啟
nginx:反向代理西疤,讓我們通過nginx來訪問webvirtmgr
novnc:由于webvirtmgr使用了novnc提供網(wǎng)頁版的VNC功能,所以需要安裝novnc。
由于這些安裝包有的在自帶的yum源中沒有代赁,所以使用epel源,進(jìn)行安裝芭碍。在這里使用阿里云的epel源進(jìn)行安裝
#安裝epel源
#CentOS7/RHEL7
wget -O /etc/yum.repos.d/epel-aliyun.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
#CentOS6/RHEL6
wget -O /etc/yum.repos.d/epel-aliyun.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum makecache
#安裝所需組件
yum -y install novnc python-pip libvirt-python libxml2-python python-websockify supervisor nginx git
下載webvirtmgr
webvirtmgr的安裝包可以從github獲取,https://github.com/retspen/webvirtmgr 窖壕,獲取方法如下:
#創(chuàng)建web目錄用于存放webvirtmgr
mkdir /web
git clone https://github.com/retspen/webvirtmgr.git
cd /web/webvirtmgr
pip install -r requirements.txt
初始化Django環(huán)境
[root@node40 ~]# cd /web/webvirtmgr/
[root@node40 webvirtmgr]# ./manage.py syncdb
WARNING:root:No local_settings file found.
Creating tables ...
Creating table auth_permission
...
Creating table create_flavor
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'root'): admin # 這里輸入Django認(rèn)證系統(tǒng)的超級管理員
Email address: yunwei@daqsoft.com
Password: # 輸入密碼
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)
[root@node40 webvirtmgr]# ./manage.py collectstatic
WARNING:root:No local_settings file found.
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Copying '/data/webvirtmgr/webvirtmgr/static/js/infrastructure.js'
Copying '/data/webvirtmgr/webvirtmgr/static/js/bootstrap-multiselect.js'
......
Copying '/data/webvirtmgr/webvirtmgr/static/img/favicon.ico'
Copying '/data/webvirtmgr/webvirtmgr/static/img/desc.gif'
Copying '/data/webvirtmgr/webvirtmgr/static/img/asc.gif'
75 static files copied.
[root@node40 webvirtmgr]# chown -R nginx.nginx /web
配置supervisor,使webvirtmgr和webvirtmgr-console以daemon方式運行。
[root@node40 webvirtmgr]# cp /etc/supervisord.conf{,_bak}
# supervisor 在CentOS6中配置時編輯配置文件/etc/supervisord.conf
[root@node40 webvirtmgr]# cat << EOF >> /etc/supervisord.conf
[program:webvirtmgr]
command=/usr/bin/python /data/webvirtmgr/manage.py run_gunicorn -c /data/webvirtmgr/conf/gunicorn.conf.py
directory=/data/webvirtmgr
autostart=true
autorestart=true
logfile=/var/log/supervisor/webvirtmgr.log
log_stderr=true
user=webvirtmgr
[program:webvirtmgr-console]
command=/usr/bin/python /data/webvirtmgr/console/webvirtmgr-console
directory=/data/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=webvirtmgr
EOF
# 添加supervisord到自啟動鸳吸,并啟動服務(wù)
chkconfig supervisord on
service supervisord start
#檢查是否啟動成功
ps -ef | grep webvirtmgr
ss -anlt | egrep --color "(8000|6080)"
配置nginx代理webvirtmgr
[root@node40 webvirtmgr]# vim /etc/nginx/conf.d/webvirtmgr.conf
server {
listen 80 ;
server_name kvm.daqsoft.com;
access_log /var/log/nginx/access_webvirtmgr.log;
location /static/ {
root /data/webvirtmgr;
expires max;
}
location / {
proxy_pass http://127.0.0.1:8000;
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 $scheme;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
client_max_body_size 1024M;
}
}
[root@node40 webvirtmgr]# mv /etc/nginx/conf.d/default.conf{,_bak}
[root@node40 webvirtmgr]# chkconfig nginx on
[root@node40 webvirtmgr]# service nginx start
安裝完成,訪問webvirtmgr
雖然這里已經(jīng)配置完成层释,但是需要對libvirtd服務(wù)進(jìn)行配置贡羔,才能在webvirtmgr中對kvm服務(wù)器進(jìn)行遠(yuǎn)程管理
配置kvm服務(wù)器
由于kvm服務(wù)器與webvirtmgr是分離部署,所以現(xiàn)在要對kvm服務(wù)器進(jìn)行配置个初,如果有多臺KVM服務(wù)器配置方法一樣乖寒。
webvirtmgr連接KVM虛擬機常用的方式是:tcp和ssh 兩種,socket方式適用于連接webvirtmgr本地kvm服務(wù)器院溺;在此以TCP訪問方式配置進(jìn)行介紹。
-
設(shè)置libvirtd服務(wù)以tcp監(jiān)聽模式進(jìn)行啟動;配置文件:/etc/sysconfig/libvirtd
在kvm服務(wù)器上找到 /etc/sysconfig/libvirtd ,去掉其中LIBVIRTD_ARGS及LIBVIRTD_CONFIG前的注釋符號(#)掉分。cp /etc/sysconfig/libvirtd{,_bak} sed -i -e "s/^#\(LIBVIRTD_ARGS\)/\1/" -e "s/^#\(LIBVIRTD_CONFIG\)/\1/" /etc/sysconfig/libvirtd
配置libvirtd服務(wù)監(jiān)聽參數(shù)禽额;配置文件:/etc/libvirt/libvirtd.conf
需要修改的配置參數(shù):
cp /etc/libvirt/libvirtd.conf{,_bak}
vim /etc/libvirt/libvirtd.conf
listen_tcp=1 # 允許進(jìn)行tcp監(jiān)聽
tcp_port="16509" # 服務(wù)端口
listen_addr="0.0.0.0" # socket監(jiān)聽時采用的IP,在此為在所有IP地址上進(jìn)行監(jiān)聽谆膳,
# 建議只配置到服務(wù)器的管理接口所在IP上進(jìn)行監(jiān)聽
auth_tcp=sasl # 使用sasl進(jìn)行認(rèn)證
listen_tls=0 # 不使用tls進(jìn)行監(jiān)聽,在不使用CA進(jìn)行認(rèn)證時一定要啟該配置
-
設(shè)置認(rèn)證用戶密碼叭爱,啟動服務(wù)
saslpasswd2 -a libvirt admin chkconfig libvirtd on service libvirtd start