KVM之web管理工具webvirtmgr安裝

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)行介紹。

  1. 設(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
    
  2. 配置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)證時一定要啟該配置
  1. 設(shè)置認(rèn)證用戶密碼叭爱,啟動服務(wù)

     saslpasswd2 -a libvirt admin
     chkconfig libvirtd on
     service libvirtd start
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市漱病,隨后出現(xiàn)的幾起案子买雾,更是在濱河造成了極大的恐慌,老刑警劉巖杨帽,帶你破解...
    沈念sama閱讀 217,907評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件漓穿,死亡現(xiàn)場離奇詭異,居然都是意外死亡注盈,警方通過查閱死者的電腦和手機晃危,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,987評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來当凡,“玉大人山害,你說我怎么就攤上這事⊙亓浚” “怎么了浪慌?”我有些...
    開封第一講書人閱讀 164,298評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長朴则。 經(jīng)常有香客問我权纤,道長钓简,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,586評論 1 293
  • 正文 為了忘掉前任汹想,我火速辦了婚禮外邓,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘古掏。我一直安慰自己损话,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,633評論 6 392
  • 文/花漫 我一把揭開白布槽唾。 她就那樣靜靜地躺著丧枪,像睡著了一般。 火紅的嫁衣襯著肌膚如雪庞萍。 梳的紋絲不亂的頭發(fā)上拧烦,一...
    開封第一講書人閱讀 51,488評論 1 302
  • 那天,我揣著相機與錄音钝计,去河邊找鬼恋博。 笑死债沮,一個胖子當(dāng)著我的面吹牛秦士,可吹牛的內(nèi)容都是我干的永高。 我是一名探鬼主播,決...
    沈念sama閱讀 40,275評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼饲宛!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起幕庐,我...
    開封第一講書人閱讀 39,176評論 0 276
  • 序言:老撾萬榮一對情侶失蹤异剥,失蹤者是張志新(化名)和其女友劉穎絮重,沒想到半個月后歹苦,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體殴瘦,經(jīng)...
    沈念sama閱讀 45,619評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡蚪腋,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,819評論 3 336
  • 正文 我和宋清朗相戀三年辣吃,在試婚紗的時候發(fā)現(xiàn)自己被綠了芬探。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片厘惦。...
    茶點故事閱讀 39,932評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡宵蕉,死狀恐怖羡玛,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情薄榛,我是刑警寧澤,帶...
    沈念sama閱讀 35,655評論 5 346
  • 正文 年R本政府宣布敞恋,位于F島的核電站硬猫,受9級特大地震影響啸蜜,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜衬横,卻給世界環(huán)境...
    茶點故事閱讀 41,265評論 3 329
  • 文/蒙蒙 一冕香、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧突那,春花似錦构眯、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,871評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽硅卢。三九已至,卻和暖如春将塑,著一層夾襖步出監(jiān)牢的瞬間点寥,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,994評論 1 269
  • 我被黑心中介騙來泰國打工蔽莱, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留碾褂,地道東北人历葛。 一個月前我還...
    沈念sama閱讀 48,095評論 3 370
  • 正文 我出身青樓恤溶,卻偏偏與公主長得像,于是被迫代替她去往敵國和親咒程。 傳聞我的和親對象是個殘疾皇子帐姻,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,884評論 2 354

推薦閱讀更多精彩內(nèi)容