【生意多】-免费发布分类信息
当前位置: 首页 » 新闻 » 教程 » 正文

kvm部署

放大字体  缩小字体 发布日期:2021-12-10 10:37:10    浏览次数:3
导读

  kvm部署  环境说明:   系统类型IPredhat8192.168.47.115centos7192.168.47.140 //关闭防火墙 [[emailprotected] ~]# systemctl disable --now firewalld Removed /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed /etc/systemd/system/dbus-org.fedoraproject.Fir

  kvm部署

  环境说明:

   系统类型IPredhat8192.168.47.115centos7192.168.47.140 //关闭防火墙 [[email protected] ~]# systemctl disable --now firewalld Removed /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. [[email protected] ~]# setenforce 0 [[email protected] ~]# sed -ri s/^(SELINUX=).*/1disabled/g /etc/selinux/config [[email protected] ~]# reboot //验证CPU是否支持KVM;如果结果中有vmx(Intel)或svm(AMD)字样,就说明CPU的支持的 [[email protected] ~]# egrep -o vmxsvm /proc/cpuinfo vmx vmx //安装依赖包 [[email protected] ~]# yum -y install epel-release vim wget net-tools unzip zip gcc gcc-c++ [[email protected] ~]# yum -y install qemu-kvm qemu-img virt-manager libvirt libvirt-client virt-install virt-viewer bridge-utils libguestfs-tools qemu-kvm-common cockpit-bridge //因为虚拟机中网络,我们一般都是和公司的其他服务器是同一个网段,所以我们需要把 KVM服务器的网卡配置成桥接模式。这样的话KVM的虚拟机就可以通过该桥接网卡和公司内部 其他服务器处于同一网段 //此处我的网卡是ens160,所以用br0来桥接ens160网卡 [[email protected] ~]# cd /etc/sysconfig/network-scripts/ [[email protected] network-scripts]# cp ifcfg-ens160 ifcfg-br0 [[email protected] network-scripts]# ls ifcfg-br0 ifcfg-ens160 [[email protected] network-scripts]# vim ifcfg-br0 [[email protected] network-scripts]# cat ifcfg-br0 TYPE=Bridge #修改模式 BOOTPROTO=static NAME=br0 #修改名字 DEVICE=br0 #修改名字 onBOOT=yes IPADDR=192.168.47.115 PREFIX=24 GATEWAY=192.168.47.2 DNS1=114.114.114.114 [[email protected] network-scripts]# vim ifcfg-ens160 [[email protected] network-scripts]# cat ifcfg-ens160 TYPE=Ethernet BOOTPROTO=static NAME=ens160 DEVICE=ens160 onBOOT=yes BRIDGE=br0 #加入这个 #删除剩下的 //重启网络 [[email protected] network-scripts]# systemctl restart NetworkManager [[email protected] network-scripts]# ifdown ens160;ifup ens160 成功停用连接 ens160(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/3) 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4) [[email protected] ~]# ip a 1: lo: LOOPBACK,UP,LOWER_UP mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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: ens160: BROADCAST,MULTICAST,UP,LOWER_UP mtu 1500 qdisc mq master br0 state UP group default qlen 1000 link/ether 00:0c:29:51:ab:da brd ff:ff:ff:ff:ff:ff 3: br0: BROADCAST,MULTICAST,UP,LOWER_UP mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:0c:29:51:ab:da brd ff:ff:ff:ff:ff:ff inet 192.168.47.115/24 brd 192.168.47.255 scope global noprefixroute br0 valid_lft forever preferred_lft forever inet6 fe80::f452:dbff:fe1b:346/64 scope link valid_lft forever preferred_lft forever //启动服务 [[email protected] ~]# systemctl enable --now libvirtd //验证安装结果 [[email protected] ~]# lsmod grep kvm kvm_intel 294912 0 kvm 786432 1 kvm_intel irqbypass 16384 1 kvm //测试并验证安装结果 [[email protected] ~]# virsh -c qemu:///system list Id 名称 状态 ------------------- [[email protected] ~]# virsh --version 6.0.0 [[email protected] ~]# virt-install --version 2.2.1 //查看网桥信息 [[email protected] ~]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000c2951abda no ens160 virbr0 8000.5254002ddf57 yes virbr0-nic [[email protected] ~]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm [[email protected] ~]# ll /usr/bin/qemu-kvm lrwxrwxrwx 1 root root 21 10月 20 16:13 /usr/bin/qemu-kvm - /usr/libexec/qemu-kvm kvm web管理界面安装 //安装依赖包 [[email protected] ~]# yum -y install epel-release [[email protected] ~]# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx python-devel //从github上下载webvirtmgr代码 [[email protected] ~]# cd /usr/local/src/ [[email protected] src] 正克隆到 webvirtmgr... remote: Enumerating objects: 5614, done. remote: Total 5614 (delta 0), reused 0 (delta 0), pack-reused 5614 接收对象中: 100% (5614/5614), 2.97 MiB 1.52 MiB/s, done. 处理 delta 中: 100% (3606/3606), done. [[email protected] src]# ls webvirtmgr //安装webvirtmgr [[email protected] src]# cd webvirtmgr/ [[email protected] webvirtmgr]# ls conf dev-requirements.txt interfaces networks serverlog templates console hostdetail locale README.rst servers Vagrantfile create images manage.py requirements.txt setup.py vrtManager deploy instance MANIFEST.in secrets storages webvirtmgr [[email protected] webvirtmgr]# pip install -r requirements.txt Collecting django==1.5.5 (from -r requirements.txt (line 1)) Downloading https://files.pythonhosted.org/packages/38/49/93511c5d3367b6b21fc2995a0e53399721afc15e4cd6eb57be879ae13ad4/Django-1.5.5.tar.gz (8.1MB) 100% ████████████████████████████████ 8.1MB 172kB/s Collecting gunicorn==19.5.0 (from -r requirements.txt (line 2)) Downloading https://files.pythonhosted.org/packages/f9/4e/f4076a1a57fc1e75edc0828db365cfa9005f9f6b4a51b489ae39a91eb4be/gunicorn-19.5.0-py2.py3-none-any.whl (113kB) 100% ████████████████████████████████ 122kB 2.1MB/s Collecting lockfile=0.9 (from -r requirements.txt (line 5)) Downloading https://files.pythonhosted.org/packages/c8/22/9460e311f340cb62d26a38c419b1381b8593b0bb6b5d1f056938b086d362/lockfile-0.12.2-py2.py3-none-any.whl Installing collected packages: django, gunicorn, lockfile Running setup.py install for django ... done Successfully installed django-1.5.5 gunicorn-19.5.0 lockfile-0.12.2 //检查sqlite3是否安装 [[email protected] webvirtmgr]# python Python 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2 Type help, copyright, credits or license for more information. import sqlite3 (没有输出就是正常的) exit() //初始化帐号信息 [[email protected] ~]# cd /usr/local/src/webvirtmgr/ [[email protected] 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 Djangos auth system, which means you dont have any superusers defined. Would you like to create one now? (yes/no): yes //问你是否创建超级管理员帐号 Username (leave blank to use root): //指定超级管理员帐号用户名,默认留空为root Email address: 1@qq.com //设置超级管理员邮箱 Password: //设置超级管理员密码 Password (again): //再次输入超级管理员密码 Superuser created successfully. Installing custom SQL ... Installing indexes ... Installed 6 object(s) from 1 fixture(s) //拷贝web网页至指定目录 [[email protected] webvirtmgr]# mkdir /var/ [[email protected] webvirtmgr]# cp -r /usr/local/src/webvirtmgr /var/ [[email protected] webvirtmgr]# chown -R nginx.nginx /var/ //生成密钥 [[email protected] ~]# 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: SHA256:ZcHCrdYFcYTFSiddsHdaD5KGrmNhzYaZ6QS6LZrdel8[email protected] The keys randomart image is: +---[RSA 2048]----+ . o+O=o. o *+=o . =+== o o . .[email protected]. o =. . .S = . . o + + o . = E + o.. o o oo... +----[SHA256]-----+ //cp到kvm主机 [[email protected] ~]# ssh-copy-id 192.168.47.115 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: /root/.ssh/id_rsa.pub The authenticity of host 192.168.47.115 (192.168.47.115) cant be established. ECDSA key fingerprint is SHA256:47Zd9Uv2fxtFemLlzz9cOYt4g7gpZpre5p/4hPpvfy0. ECDSA key fingerprint is MD5:83:58:13:1b:5f:fe:17:00:51:23:29:54:5d:d7:b6:ee. 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.47.115s password: Number of key(s) added: 1 Now try logging into the machine, with: ssh[email protected] and check to make sure that only the key(s) you wanted were added. [[email protected] ~]# ssh 192.168.47.115 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:60 Last login: Thu Oct 21 03:11:07 2021 from 192.168.47.1 [[email protected] ~]# ss -anlt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.1:6080 *:* LISTEN 0 128 127.0.0.1:8000 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 ::1:6080 :::* LISTEN 0 128 ::1:8000 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* //配置nginx [[email protected] ~]# cd /etc/nginx/ [[email protected] nginx]# ls conf.d fastcgi_params mime.types scgi_params win-utf default.d fastcgi_params.default mime.types.default scgi_params.default fastcgi.conf koi-utf nginx.conf uwsgi_params fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default [[email protected] nginx] [[email protected] nginx] 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 { } } } [[email protected] nginx] server { listen 80 default_server; server_name $hostname; #access_log /var/log/nginx/webvirtmgr_access_log; location /static/ { root /var//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端口 [[email protected] nginx]# vi /var/ .....此处省略N行 bind = 0.0.0.0:8000 //确保此处绑定的是本机的8000端口,这个在nginx配置中定义了,被代理的端口 backlog = 2048 .....此处省略N行 [[email protected] ~]# systemctl restart nginx [[email protected] ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.1:6080 *:* LISTEN 0 128 127.0.0.1:8000 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 ::1:6080 :::* LISTEN 0 128 ::1:8000 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* [[email protected] ~] //加到最下面 [program:webvirtmgr] command=/usr/bin/python2 /var//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 [[email protected] ~]# systemctl enable --now supervisord Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service. [[email protected] ~]# 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 四 2021-10-21 02:39:18 CST; 6s ago Process: 42642 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS) Main PID: 42645 (supervisord) CGroup: /system.slice/supervisord.service ├─42645 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf └─42667 /usr/bin/python2 /var//webvirtmgr/manage.py run_gunicorn -c /var/www/webv... 10月 21 02:39:18 web systemd[1]: Starting Process Monitoring and Control Daemon... 10月 21 02:39:18 web systemd[1]: Started Process Monitoring and Control Daemon. [[email protected] ~]# ss -anlt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.1:6080 *:* LISTEN 0 128 127.0.0.1:8000 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 ::1:6080 :::* LISTEN 0 128 ::1:8000 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* [[email protected] ~]# su - nginx -s /bin/bash -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: SHA256:Apm01mJE+6uj3umbBN+tAudELHOV9dlwABf0GuepftE[email protected] The keys randomart image is: +---[RSA 2048]----+ .+ ooo*o. o *o o * .X.. + + oo++ = . .= o S . o. .oo. + .. E =o o . . . o++ . . . .ooB+. .. +----[SHA256]-----+ -bash-4.2$ touch ~/.ssh/config && echo -e StrictHostKeyChecking=nonUserKnownHostsFile=/dev/null ~/.ssh/config -bash-4.2$ chmod 0600 ~/.ssh/config -bash-4.2$ ssh-copy-id root@192.168.47.115 /bin/ssh-copy-id: INFO: Source of key(s) to be installed: /var/lib/nginx/.ssh/id_rsa.pub /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.47.115 (ECDSA) to the list of known hosts. root@192.168.47.115s password: Number of key(s) added: 1 Now try logging into the machine, with: ssh[email protected] and check to make sure that only the key(s) you wanted were added. -bash-4.2$ exit 登出 [[email protected] nginx]# systemctl restart nginx kvm主机 [[email protected] ~]# systemctl restart libvirtd

  







通过远程连接软件上传ISO镜像文件至存储目录/var/lib/libvirt/images/

   [[email protected] ~]# cd /var/lib/libvirt/images [[email protected] images]# ls [[email protected] images]# ls CentOS-7-x86_64-DVD-1804-7.5.iso

  

   解决方法 [[email protected] ~]# yum update libgcrypt [[email protected] ~]# systemctl restart libvirtd

  kvm网络管理
添加桥接网络



实例(虚拟机)创建









问题解决

   [[email protected] ~]# ll /etc/rc.local lrwxrwxrwx 1 root root 13 8月 10 23:31 /etc/rc.local - rc.d/rc.local [[email protected] ~]# ll /etc/rc.d/rc.local -rw-r--r--. 1 root root 474 8月 10 23:31 /etc/rc.d/rc.local [[email protected] ~]# chmod +x /etc/rc.d/rc.local [[email protected] ~]# ll /etc/rc.d/rc.local -rwxr-xr-x. 1 root root 474 8月 10 23:31 /etc/rc.d/rc.local [[email protected] ~]# vi /etc/rc.d/rc.local ......此处省略N行 # that this script will be executed during boot. touch /var/lock/subsys/local nohup novnc_server 192.168.47.115:5920 & [[email protected] ~]# . /etc/rc.d/rc.local

 
关键词: 考试
(文/小编)
打赏
免责声明
• 
本文为小编原创作品,作者: 小编。欢迎转载,转载请注明原文出处:https://www.31duo.com/news/show-2240318.html 。本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们。
 

(c)2016-2019 31DUO.COM All Rights Reserved浙ICP备19001410号-4

浙ICP备19001410号-4