虚拟化简介
什么是虚拟化?
一台PC机的组成包括:Keyboard(键盘)、Monitor(显示器)、CPU、RAM、I/O(Disk,Network),这是基本的五大部件。
虚拟化就是在这些基础物理设备上运行多个OS。
根据 Hypervisor 的实现方式和所处的位置,虚拟化又分为两种:
全虚拟化:Hypervisor 直接安装在物理机上,多个虚拟机在 Hypervisor 上运行。Hypervisor 实现方式一般是一个特殊定制的 Linux 系统。Xen 和 VMWare 的 ESXi 都属于这个类型
半虚拟化:物理机上首先安装常规的操作系统,比如 Redhat、Ubuntu 和 Windows。Hypervisor 作为 OS 上的一个程序模块运行,并对管理虚拟机进行管理。KVM、VirtualBox 和 VMWare Workstation 都属于这个类型
kvm简介
KVM,是Keyboard Video Mouse的缩写,KVM 通过直接连接键盘、视频和鼠标 (KVM) 端口,能够访问和控制计算机。KVM 技术无需目标服务器修改软件。这就意味着可以在BIOS环境下,随时访问目标计算机。KVM 提供真正的主板级别访问,并支持多平台服务器和串行设备。KVM 技术已经从最初的基础SOHO办公型,发展成为企业 IT 基础机房设施管理系统。可以从kvm 客户端管理软件轻松的直接访问位于多个远程位置的服务器和设备。KVM over IP 解决方案具备完善的多地点故障转移功能、符合新服务器管理标准 (IPMI) 的直接界面,以及将本地存储媒体映射至远程位置的功能。
kvm环境部署
主机名 | IP |
---|---|
hostlocal | 192.168.175.100 |
kvm安装
部署前请确保你的CPU虚拟化功能已开启。分为两种情况:
虚拟机要关机设置CPU虚拟化(图片如下)
物理机要在BIOS里开启CPU虚拟化
开始安装
关闭防火墙和selinux
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#systemctl disable firewalld
[root@localhost ~]# getenforce
Disabled
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
配置网络源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2523 100 2523 0 0 2761 0 --:--:-- --:--:-- --:--:-- 2760
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo server.repo
[root@localhost yum.repos.d]# vim CentOS-Base.repo
[root@localhost yum.repos.d]# cd
[root@localhost ~]# yum clean all
已加载插件:fastestmirror
Repository 'base': Error parsing config: Error parsing "baseurl = 'local'": URL must be http, ftp, file or https not ""
正在清理软件源: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache fast
已加载插件:fastestmirror
Repository 'base': Error parsing config: Error parsing "baseurl = 'local'": URL must be http, ftp, file or https not ""
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): base/x86_64/group_gz | 153 kB 00:00:00
(2/4): extras/x86_64/primary_db | 205 kB 00:00:01
(3/4): updates/x86_64/primary_db | 3.7 MB 00:00:07
(4/4): base/x86_64/primary_db | 6.1 MB 00:00:10
Determining fastest mirrors
元数据缓存已建立
配置epel源
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2020-08-03 19:38:48-- http://mirrors.aliyun.com/repo/epel-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 211.91.163.81, 211.91.163.82, 211.91.163.83, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|211.91.163.81|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:664 [application/octet-stream]
正在保存至: “/etc/yum.repos.d/epel.repo”
100%[================================================>] 664 --.-K/s 用时 0s
2020-08-03 19:38:48 (59.5 MB/s) - 已保存 “/etc/yum.repos.d/epel.repo” [664/664])
安装需要的包
[root@localhost ~]#yum -y install net-tools unzip zip gcc gcc-c++
验证是否支持虚拟化
[root@localhost ~]# egrep -o 'vmx|svm' /proc/cpuinfo
vmx
vmx
vmx
vmx
kvm安装
[root@localhost ~]#yum -y install qemu-kvm qemu-kvm-tools qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils libguestfs-tools
此处我的网卡是ens33,所以用br0来桥接ens33网卡
[root@localhost yum.repos.d]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-ens33 ifdown-ppp ifup-ib ifup-Team
ifcfg-lo ifdown-routes ifup-ippp ifup-TeamPort
ifdown ifdown-sit ifup-ipv6 ifup-tunnel
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-br0
[root@localhost network-scripts]# vim ifcfg-br0
[root@localhost network-scripts]# cat ifcfg-br0
TYPE=Bridge
DEVICE=br0
NM_CONTROLLED=no
BOOTPROTO=static
NAME=br0
ONBOOT=yes
IPADDR=192.168.175.100
NETMASK=255.255.255.0
GATEWAY=192.168.175.2
DNS1=114.114.114.114
[root@localhost network-scripts]# vim ifcfg-ens33
[root@localhost network-scripts]# cat ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
BRIDGE=br0
NM_CONTROLLED=no
[root@localhost network-scripts]# cd
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:1e:69:85 brd ff:ff:ff:ff:ff:ff
inet 192.168.175.100/24 brd 192.168.175.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::ea80:e71e:f5fc:9a2c/64 scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link/ether 00:0c:29:1e:69:85 brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:29ff:fe1e:6985/64 scope link
valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 00:0c:29:1e:69:85 brd ff:ff:ff:ff:ff:ff
inet 192.168.175.100/24 brd 192.168.175.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe1e:6985/64 scope link
valid_lft forever preferred_lft forever
启动服务
[root@localhost ~]# systemctl start libvirtd
[root@localhost ~]# systemctl enable libvirtd
验证安装结果
[root@localhost ~]# lsmod|grep kvm
kvm_intel 170181 0
kvm 554609 1 kvm_intel
irqbypass 13503 1 kvm
测试并验证安装结果
[root@localhost ~]# virsh -c qemu:///system list
Id 名称 状态
----------------------------------------------------
[root@localhost ~]# virsh --version
4.5.0
[root@localhost ~]# virt-install --version
1.5.0
创建软链接
[root@localhost ~]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
[root@localhost ~]# ll /usr/bin/qemu-kvm
lrwxrwxrwx 1 root root 21 8月 3 20:26 /usr/bin/qemu-kvm -> /usr/libexec/qemu-kvm
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c291e6985 no ens33
virbr0 8000.5254002d11ff yes virbr0-nic
找到x11并勾选
编辑
[root@localhost ~]#vim /etc/ssh/sshd_config
取消X11前面的#号
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
重启服务
[root@localhost ~]#systemctl restart sshd
关机添加硬盘,添加完之后再开机
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 50G 1.7G 49G 4% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.7M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 140M 875M 14% /boot
/dev/mapper/cl-home 42G 33M 42G 1% /home
tmpfs 781M 0 781M 0% /run/user/0
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─cl-root 253:0 0 50G 0 lvm /
├─cl-swap 253:1 0 7.9G 0 lvm [SWAP]
└─cl-home 253:2 0 41.1G 0 lvm /home
sdb 8:16 0 200G 0 disk
sr0 11:0 1 4.1G 0 rom
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x868bc81a 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-419430399,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-419430399,默认为 419430399):
将使用默认值 419430399
分区 1 已设置为 Linux 类型,大小设为 200 GiB
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# partprobe
Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
[root@localhost ~]# mkfs.xfs /dev/sdb1
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─cl-root 253:0 0 50G 0 lvm /
├─cl-swap 253:1 0 7.9G 0 lvm [SWAP]
└─cl-home 253:2 0 41.1G 0 lvm /home
sdb 8:16 0 200G 0 disk
└─sdb1 8:17 0 200G 0 part
sr0 11:0 1 4.1G 0 rom
[root@localhost ~]# blkid
/dev/sdb1: UUID="3293e723-4d22-4aed-a289-597a4d883118" TYPE="xfs"
/dev/sda1: UUID="34ecc1f0-7ded-46a7-9e8a-d6f99ef626d0" TYPE="xfs"
/dev/sda2: UUID="UOyXxG-jdxe-Ulai-47Hd-DC7J-OjBo-QlH823" TYPE="LVM2_member"
/dev/sr0: UUID="2016-12-05-13-55-45-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/cl-root: UUID="c96f81cc-bcbf-431c-9f91-6a87143ab882" TYPE="xfs"
/dev/mapper/cl-swap: UUID="e751d91e-5b21-44b6-98c1-3721048e4360" TYPE="swap"
/dev/mapper/cl-home: UUID="06981b41-334b-41f4-b9bf-b33fb9a2f26d" TYPE="xfs"
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mkdir /storage
[root@localhost ~]# mount -a
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 50G 1.7G 49G 4% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.7M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 140M 875M 14% /boot
/dev/mapper/cl-home 42G 33M 42G 1% /home
tmpfs 781M 0 781M 0% /run/user/0
/dev/sdb1 200G 33M 200G 1% /storage
安装web界面
安装依赖包
[root@localhost ~]#yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx python-devel
升级pip
[root@localhost ~]# pip install --upgrade pip -i https://blog.csdn.net/unicorn_mitnick/article/details/89738544 (-i指向国内源)
升级pip
[root@localhost ~]# pip install --upgrade pip
从github上下载webvirtmgr代码
[root@localhost ~]# git clone git://github.com/retspen/webvirtmgr.git
正克隆到 'webvirtmgr'...
remote: Enumerating objects: 5614, done.
安装webvirtmgr
[root@localhost ~]# ls
! anaconda-ks.cfg webvirtmgr
[root@localhost ~]# cd webvirtmgr/
[root@localhost webvirtmgr]# ls
conf images networks setup.py
console instance README.rst storages
create interfaces requirements.txt templates
deploy locale secrets Vagrantfile
dev-requirements.txt manage.py serverlog vrtManager
hostdetail MANIFEST.in servers webvirtmgr
[root@localhost webvirtmgr]# pip install -r requirements.txt
检查sqlite3是否安装
[root@localhost webvirtmgr]# python
Python 2.7.5 (default, Apr 2 2020, 13:16:51)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> exit()
初始化账号信息
[root@localhost webvirtmgr]# python manage.py syncdb
WARNING:root:No local_settings file found.
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table servers_compute
Creating table instance_instance
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 //指定超级管理员帐号用户名,默认留空为root
Email address:1@2.com //设置超级管理员邮箱
Password: //设置超级管理员密码
Password (again): //再次输入超级管理员密码
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)
拷贝web网页指定目录
[root@localhost ~]# ls
! anaconda-ks.cfg webvirtmgr
[root@localhost ~]# mkdir /var/www
[root@localhost ~]# cp -r webvirtmgr /var/www/
[root@localhost ~]# ls /var/www/
webvirtmgr
[root@localhost ~]# chown -R nginx.nginx /var/www/webvirtmgr
生成秘钥
[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
38:86:fb:07:83:55:e4:05:83:93:db:18:ac:4a:65:f1 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| .o ++.. |
| o.*..o |
| o .EB. |
| . ..+.. |
| . ..o+ S |
| . .oo. |
| . o |
| . . |
| .. |
+-----------------+
[root@localhost ~]# ssh-copy-id 192.168.175.100
The authenticity of host '192.168.175.100 (192.168.175.100)' can't be established.
ECDSA key fingerprint is a2:d4:97:48:99:c9:70:87:57:88:a0:d2:8c:5d:e0:38.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.175.100's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.175.100'"
and check to make sure that only the key(s) you wanted were added.
配置端口转发
[root@localhost ~]# ssh 192.168.175.100 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:60
Last login: Mon Aug 3 22:26:32 2020 from 192.168.175.1
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 127.0.0.1:6080 *:*
LISTEN 0 128 127.0.0.1:8000 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 128 ::1:6080 :::*
LISTEN 0 128 ::1:8000 :::*
配置nginx
[root@localhost ~]# vim /etc/nginx/nginx.conf
[root@localhost ~]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name localhost;
include /etc/nginx/default.d/*.conf;
location / {
root html;
index index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
[root@localhost ~]# vim /etc/nginx/conf.d/webvirtmgr.conf
[root@localhost ~]# cat /etc/nginx/conf.d/webvirtmgr.conf
server {
listen 80 default_server;
server_name $hostname;
#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 $remote_addr;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
client_max_body_size 1024M;
}
}
确保bind绑定的是本机的8000端口
[root@localhost ~]# vim /var/www/webvirtmgr/conf/gunicorn.conf.py
修改bind=0.0.0.0
即bind = '0.0.0.0:8000' //确保此处绑定的是本机的8000端口,这个在nginx配置中定义了,被代理的端口
backlog = 2048
重启nginx
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 127.0.0.1:6080 *:*
LISTEN 0 128 127.0.0.1:8000 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 128 ::1:6080 :::*
LISTEN 0 128 ::1:8000 :::*
设置supervisor
[root@localhost ~]# vim /etc/supervisord.conf
[program:webvirtmgr]
command=/usr/bin/python2 /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/python2 /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
设置supervisor开机自启
[root@localhost ~]# systemctl enable supervisord
[root@localhost ~]# systemctl start supervisord
[root@localhost ~]# systemctl status supervisord
● supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2020-08-03 22:51:18 CST; 36s ago
Main PID: 11840 (supervisord)
CGroup: /system.slice/supervisord.service
├─11840 /usr/bin/python /usr/bin/supervisord -c /etc/s...
└─11915 /usr/bin/python2 /var/www/webvirtmgr/manage.py...
8月 03 22:51:18 localhost.localdomain systemd[1]: Starting Proce...
8月 03 22:51:18 localhost.localdomain systemd[1]: Started Proces...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 127.0.0.1:6080 *:*
LISTEN 0 128 127.0.0.1:8000 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 128 ::1:6080 :::*
LISTEN 0 128 ::1:8000 :::*
配置nginx用户
[root@localhost ~]# su - nginx -s /bin/bash
-bash-4.2$ id
uid=993(nginx) gid=990(nginx) 组=990(nginx)
-bash-4.2$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/nginx/.ssh/id_rsa):
Created directory '/var/lib/nginx/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/nginx/.ssh/id_rsa.
Your public key has been saved in /var/lib/nginx/.ssh/id_rsa.pub.
The key fingerprint is:
9c:e6:83:e4:4b:f9:2d:90:99:b7:6d:14:6e:7c:25:04 nginx@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| E. |
| . |
| . |
| . .. . . |
| .+So . o |
| o==. = . |
| =oo= . |
| . oooo |
| . .o. |
+-----------------+
-bash-4.2$ touch ~/.ssh/config
-bash-4.2$ echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.2$ cat ~/.ssh/config
StrictHostKeyChecking=no
UserKnownHostsFile=/dev/null
-bash-4.2$ chmod 0600 ~/.ssh/config
-bash-4.2$ ssh-copy-id root@192.168.175.100
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Warning: Permanently added '192.168.175.100' (ECDSA) to the list of known hosts.
root@192.168.175.100's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.175.100'"
and check to make sure that only the key(s) you wanted were added.
[root@localhost ~]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[root@localhost ~]# ll /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
-rw-r--r-- 1 root root 133 8月 3 22:59 /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[root@localhost ~]# systemctl restart nginx libvirtd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 127.0.0.1:6080 *:*
LISTEN 0 128 127.0.0.1:8000 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 128 ::1:6080 :::*
LISTEN 0 128 ::1:8000 :::*
kvm web页面访问
会发现一个问题,页面一直转圈圈,远程一直报错
解决方法
[root@localhost ~]# vim /etc/nginx/nginx.conf
....此处省略N行
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
worker_rlimit_nofile 655350; //添加此行配置
对系统参数进行设置
[root@localhost ~]# vim /etc/security/limits.conf
文件最后添加
* soft nofile 655350
* hard nofile 655350
重启服务
[root@localhost ~]# systemctl restart nginx
用户和密码都是上面设置的,此时我设置的都是admin
添加连接
新建存储
上传镜像
[root@localhost storage]# ls
rhel-server-7.4-x86_64-dvd.iso
创建系统安装镜像
添加桥接网络
实例创建
虚拟机插入光盘
设置密码
启动虚拟机
点击控制台又会报错
解决方法
解决方法是安装novnc并通过novnc_server启动一个vnc
[root@localhost ~]# yum -y install novnc
设置权限
[root@localhost ~]# chmod +x /etc/rc.d/rc.local
[root@localhost ~]# ll /etc/rc.local
lrwxrwxrwx 1 root root 13 8月 3 20:07 /etc/rc.local -> rc.d/rc.local
[root@localhost ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 473 6月 30 23:11 /etc/rc.d/rc.local
[root@localhost ~]# vim /etc/rc.d/rc.local
最后一行添加
nohup novnc_server 192.168.175.100:5920 & 此时是自己虚拟机的IP地址
[root@localhost ~]# source /etc/rc.d/rc.local
[root@localhost ~]# nohup: 忽略输入并把输出追加到"nohup.out"
[root@localhost ~]# ps -ef|grep novnc
root 13567 12772 0 23:41 pts/2 00:00:00 bash /usr/bin/novnc_server 192.168.175.100:5920
root 13577 13567 0 23:41 pts/2 00:00:00 /usr/bin/python /usr/bin/websockify --web /usr/bin/../share/novnc/ 6080 localhost:5900
root 13602 12772 0 23:43 pts/2 00:00:00 grep --color=autonovnc