KVM使用第三方軟件可視化管理

1. 服務器環境規劃

操作系統 IP地址 主機名 備註
Centos7.6 192.168.10.10 KVM-Node1  

2. 環境準備

2.1 查看當前系統版本

[root@KVM-Node1 ~]# hostnamectl 

2.2 關閉selinux 

[root@KVM-Node1 ~]# sed -i '/SELINUX=/cSELINUX=disabled' /etc/selinux/config

[root@KVM-Node1 ~]# setenforce 0

2.3 關閉firewalld ebtables防火牆

[root@KVM-Node1 ~]# systemctl stop ebtables firewalld

[root@KVM-Node1 ~]# systemctl disable ebtables firewalld

3. 操作步驟

1.安裝WebVirtMgr  

WebVirtMgr官⽅參考⼿冊

[root@KVM-Node1 ~]# yum -y install https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

[root@KVM-Node1 ~]# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx gcc python-devel

[root@KVM-Node1 ~]# pip install numpy

2. 安裝python需求並設置Django環境

[root@KVM-Node1 ~]# git clone git://github.com/retspen/webvirtmgr.git

[root@KVM-Node1 ~]# cd webvirtmgr

[root@KVM-Node1 webvirtmgr]#  pip install -r requirements.txt

[root@KVM-Node1 webvirtmgr]#  ./manage.py syncdb

輸入用戶信息:

You just installed Django's auth system, which means you don't have any superusers defined.    

# 您剛剛安裝了Django的auth系統,這意味着您沒有定義任何超級用戶。

Would you like to create one now? (yes/no): yes     # 你想現在創建一個嗎?(是/否):是的

Username (leave blank to use 'root'): root                # 用戶名(留空以使用'root'):root

Email address: [email protected]         # 電子郵件地址:[email protected]

Password:                         # 密碼:

Password (again):             # 再次輸入密碼

Superuser created successfully.        #超級用戶已成功創建。

[root@KVM-Node1 webvirtmgr]# ./manage.py collectstatic

3. 創建一個其他的超級用戶

[root@KVM-Node1 webvirtmgr]# ./manage.py createsuperuser

WARNING:root:No local_settings file found.

Username: chenjiangfeng

Email address: [email protected]

Password: 

Password (again): 

Superuser created successfully.

4. 配置nginx

4.1 移動網頁目錄

[root@KVM-Node1 webvirtmgr]# cd ..

[root@KVM-Node1 ~]# mv webvirtmgr /var/www/

4.2 在/etc/nginx/conf.d中添加webvirtmgr.conf文件:

[root@KVM-Node1 ~]# vim /etc/nginx/conf.d/webvirtmgr.conf 

server {

    listen 80 default_server;

    server_name kvm.chenjf.com;

    access_log /var/log/nginx/webvirtmgr_access_log; 

    location /static/ {

        root /var/www/webvirtmgr/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; # Set higher depending on your needs 

    }

}

0a787208-dc22-4e1c-94cc-a9637f63bc94

4.3 打開/etc/nginx/nginx.conf 註釋/etc/nginx/conf/nginx.conf⽂件中Server段,如示例所示:

#      server {

#     listen 80 default_server;

#      server_name localhost;

#      root /usr/share/nginx/html;

#

#      #charset koi8-r;

#

#      #access_log /var/log/nginx/host.access.log main;

#

#     # Load configuration files for the default server block.

#      include /etc/nginx/default.d/*.conf;

#

#      location / {

#      }

#

# # redirect server error pages to the static page /40x.html

# #

#      error_page 404 /404.html;

#      location = /40x.html {

#     }

#

# # redirect server error pages to the static page /50x.html

# #

#          error_page 500 502 503 504 /50x.html;

#          location = /50x.html {

#     }

# }

4.4 設定⽬錄權限

[root@KVM-Node1 ~]# chown -R nginx:nginx /var/www/webvirtmgr

4.5 啓動nginx,並將其加⼊開機⾃啓

[root@KVM-Node1 ~]# systemctl start nginx

[root@KVM-Node1 ~]# systemctl enable nginx

5. 安裝配置 Supervisor

5.1 使用以下內容創建文件/etc/supervisord.d/webvirtmgr.ini

[root@KVM-Node1 ~]# vim /etc/supervisord.d/webvirtmgr.ini

[program:webvirtmgr]

command=/usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py

directory=/var/www/webvirtmgr

autostart=true

autorestart=true

logfile=/var/log/supervisor/webvirtmgr.log

log_stderr=true

user=nginx

[program:webvirtmgr-console]

command=/usr/bin/python /var/www/webvirtmgr/console/webvirtmgr-console

directory=/var/www/webvirtmgr

autostart=true

autorestart=true

stdout_logfile=/var/log/supervisor/webvirtmgr-console.log

redirect_stderr=true

user=nginx

0b6f4b1b-9575-4c5f-94ce-d9101c401559

5.2 重新啓動supervisor守護程序

[root@KVM-Node1 ~]# systemctl restart supervisord

[root@KVM-Node1 ~]# systemctl enable supervisord

6. 瀏覽器訪問即可

040ec29f-bae5-41db-868d-3c201127f2a9

3ab0e1ba-8b2d-4382-994e-ca3583106771

da079114-e911-41d7-8517-98264ca9bf87

7. 配置 ssh 認證SSH官⽅參考資料

[root@KVM-Node1 ~]# su - nginx -s /bin/bash 

-bash-4.2$ ssh-keygen (一直回車即可)

-bash-4.2$ touch ~/.ssh/config

-bash-4.2$ echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >>~/.ssh/config

-bash-4.2$ chmod 0600 ~/.ssh/config

-bash-4.2$ ssh-copy-id root@localhost

8. 配置完成後刷新瀏覽器

07379b65-4fb8-46fe-ad45-60d1d550d7c7

ede805b9-c8b8-403d-988b-069d02e99459

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章