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
[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
}
}
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
5.2 重新启动supervisor守护程序
[root@KVM-Node1 ~]# systemctl restart supervisord
[root@KVM-Node1 ~]# systemctl enable supervisord
6. 浏览器访问即可
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