心之所向,皆可身往。

KVM

------------------------------------------------------------------------------------------------------------------------
查看当前活跃的网络
$ virsh net-list
$ virsh net-dumpxml default
修改default网络的配置:
$ virsh net-edit default
$ undefine default网络,再重新定义:
$ virsh net-undefine default
启用default
$ virsh net-start default

virsh的详细命令解析
https://www.cnblogs.com/zknublx/p/9178920.html

$ virsh list --all

KVM
自动启动虚拟主机
$ virsh autostart centos73

虚拟主机开启virsh console访问
$ grubby --update-kernel=ALL --args="console=ttyS0"
$ reboot
$ virsh console vm1

1 在KVM(客户机)下开机启动并启动服务

$ systemctl enable serial-getty@ttyS0.service

2 在宿主机下访问
$ systemctl start serial-getty@ttyS0.service


虚拟主机配置NAT模式
<interface type='network'>
    <mac address='52:54:00:4f:1b:07'/>
    <source network='default'/>
    <model type='virtio'/>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

宿主机的物理网卡配置文件
修改文件/etc/sysconfig/network-scripts/ifcfg-eno1
$ cat ifcfg-eno1
TYPE=Ethernet
BOOTPROTO=static
DEVICE=eno1
HWADDR=00:0c:29:09:0d:3d
UUID=242b3d4d-37a5-4f46-b072-55554c185ecf
NM_CONTROLLED=no
ONBOOT=yes
# 指定桥接网卡的名称
BRIDGE=br0

桥接网卡配置
在/etc/sysconfig/network-scripts/下创建文件ifcfg-br0
$ cat ifcfg-br0
TYPE=bridge
NM_CONTROLLED=no
DEVICE=br0
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.33.1.18
NETMASK=255.255.255.0
GATEWAY=10.33.1.247
DNS1=114.114.114.114
DNS2=

不需要静态地址
DEVICE="br0"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO=dhcp

$ ifup eno1 # 激活网卡
$ ifup br0 # 激活桥接网卡
# 两种重启网络的方法
$ systemctl restart network.service
# 校验桥接接口
$ brctl show

bridge name bridge id   STP enabled interfaces
br0   8000.3863bb44cf6c no    eno1
              vnet0
virbr0    8000.525400193f0f yes   virbr0-nic

虚拟主机配置BRIDGE模式
$ virsh  shutdown  vm1
<interface type='default'> 改为 <interface type='bridge'>

    <mac address='52:54:00:50:58:7e'/>
    <source network='default'/> 改为<source bridge='br0'/>
    <model type='virtio'/>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>

</interface>
即:
<interface type='bridge'>
    <mac address='52:54:00:da:c3:dc'/>
    <source bridge='br0'/>
    <model type='virtio'/>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
$ virsh define /etc/libvirt/qemu/vm1.xml
$ virsh start vm1

随机生成MAC地址
$ echo "00:60:2F$(dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 ":%02X"')"
$ echo "$(hexdump -n3 -e'/3 "00:60:2F" 3/1 ":%02X"' /dev/random)"
$ printf '00:60:2F:%02X:%02X:%02X\n' $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]
$ echo 00:60:2f:`openssl rand -hex 3 | sed 's/\(..\)/\1:/g; s/.$//'`

lsof -i:端口号 查看端口的占用
$ lsof -i:8000

netstat -tunlp |grep 端口号,看指定的端口的进程情况
$ netstat -tunlp | grep 8000

# virsh net-destroy default
# virsh net-undefine default
# service libvirtd restart

vi /etc/sysctl.conf
kernel.watchdog_thresh=30

echo 30 > /proc/sys/kernel/watchdog_thresh
#临时生效
sysctl -w kernel.watchdog_thresh=30

------------------------------------------------------------------------------------------------------------------------
vim /etc/libvirt/qemu/centos71.xml
------------------------------------------------------------------------------------------------------------------------

# shutdown
# shutdown now
# shutdown 13:20
# shutdown -p now  ### 关闭机器
# shutdown -H now  ### 停止机器
# shutdown -r09:35 ### 在 09:35am 重启机器
# shutdown -c      ### 取消即将进行的关机

# halt             ### 停止机器
# halt -p          ### 关闭机器
# halt --reboot    ### 重启机器

# poweroff           ### 关闭机器
# poweroff --halt    ### 停止机器
# poweroff --reboot  ### 重启机器

# reboot           ### 重启机器
# reboot --halt    ### 停止机器
# reboot -p        ### 关闭机器




abrt-cli list --since 1550651319
reason:         NMI watchdog: BUG: soft lockup - CPU#23 stuck for 22s! [runc:[1:CHILD]:16345]
time:           Tue 19 Feb 2019 08:32:24 PM EST
cmdline:        BOOT_IMAGE=/vmlinuz-3.10.0-957.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
package:        kernel
uid:            0 (root)
count:          17
Directory:      /var/spool/abrt/oops-2019-02-19-20:32:24-16885-0
Reported:       cannot be reported


The Autoreporting feature is disabled. Please consider enabling it by issuing
'abrt-auto-reporting enabled' as a user with root privileges





常用日志文件
系统日志是由一个名为syslog的服务管理的,如以下日志文件都是由syslog日志服务驱动的:

/var/log/boot.log:录了系统在引导过程中发生的事件,就是Linux系统开机自检过程显示的信息
/var/log/lastlog :记录最后一次用户成功登陆的时间、登陆IP等信息
/var/log/messages :记录Linux操作系统常见的系统和服务错误信息
/var/log/secure :Linux系统安全日志,记录用户和工作组变坏情况、用户登陆认证情况
/var/log/btmp :记录Linux登陆失败的用户、时间以及远程IP地址
/var/log/syslog:只记录警告信息,常常是系统出问题的信息,使用lastlog查看
/var/log/wtmp:该日志文件永久记录每个用户登录、注销及系统的启动、停机的事件,使用last命令查看
/var/run/utmp:该日志文件记录有关当前登录的每个用户的信息。如 who、w、users、finger等就需要访问这个文件



/etc/resolv.conf
/etc/systemd/system/kubelet.service.d/10-kubeadm.conf

永久关闭SWAP
vim /etc/fstab

# 注释掉SWAP分区项,即可
# swap was on /dev/sda11 during installation
# UUID=0a55fdb5-a9d8-4215-80f7-f42f75644f69 none  swap    sw      0       0


# 允许 Master 部署 Pod
kubectl taint nodes localhost.master node-role.kubernetes.io/master- --overwrite
# 禁止 Master 部署 Pod
kubectl taint nodes localhost.master node-role.kubernetes.io/master=:NoSchedule --overwrite
# 其中 localhost.master 是操作的节点名称

将 --cgroup-driver 改为cgroupfs 确保和 /usr/lib/systemd/system/docker.service 的用户一致
vi /usr/lib/systemd/system/docker.service

# 更新缓存
$ yum makecache




sudo systemctl stop kubelet
sudo rm -rf /var/lib/kubelet/pods/*
sudo systemctl start kubelet

------------------------------------------------------------------------------------------------------------------------
KVM libvirt assign static guest IP addresses using DHCP on the virtual machine

View the current dnsmasq DHCP configuration
Type the following command to list networks
# virsh net-list

Sample outputs:

 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
To see the default network information, enter:
# virsh net-dumpxml default

Sample outputs:

<network connections='2'>
  <name>default</name>
  <uuid>e346291e-f86b-4f2f-a16e-654136441805</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:12:fe:35'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.100' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>
The DHCP range is between 192.168.122.100 and 192.168.122.254.

How to configure static guest IP addresses on the VM host
First find out your guest VM’s MAC addresses, enter:
# virsh dumpxml {VM-NAME-HERE} | grep -i '<mac'
# virsh dumpxml xenial | grep -i '<mac'

Sample outputs:

<mac address='52:54:00:4c:40:1c'/>
Please note down the MAC addresses of the xenial VM that you want to assign static IP addresses.

Edit the default network
Type the following command:
# virsh net-edit default

Find the following section:

 <dhcp>
      <range start='192.168.122.100' end='192.168.122.254'/>
Append the static IP as follows after range:

     <host mac='52:54:00:4c:40:1c' name='xenial' ip='192.168.122.4'/>
Where,

mac='52:54:00:4c:40:1c' – VMs mac address
name='xenial' – VMs name.
ip='192.168.122.4' – VMs static IP.
Here is my complete file with three static DHCP entries for three VMs:

<network>
  <name>default</name>
  <uuid>e346291e-f86b-4f2f-a16e-654136441805</uuid>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:12:fe:35'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.100' end='192.168.122.254'/>
      <host mac='52:54:00:a0:cc:19' name='centos7' ip='192.168.122.2'/>
      <host mac='52:54:00:f7:a1:c8' name='puffy' ip='192.168.122.3'/>
      <host mac='52:54:00:4c:40:1c' name='xenial' ip='192.168.122.4'/>
    </dhcp>
  </ip>
</network>
Restart DHCP service:
# virsh net-destroy default
# virsh net-start default

Sample outputs:

Network default destroyed
Network default started
If you are running the guest/VM called xenial shutdown it:
# virsh shutdown xenial
# /etc/init.d/libvirt-bin restart
# virsh start xenial
# ping -a 192.168.122.4

Sample outputs:

PING 192.168.122.4 (192.168.122.4) 56(84) bytes of data.
64 bytes from 192.168.122.4: icmp_seq=1 ttl=64 time=0.518 ms
64 bytes from 192.168.122.4: icmp_seq=2 ttl=64 time=0.202 ms
64 bytes from 192.168.122.4: icmp_seq=3 ttl=64 time=0.327 ms
^C
--- 192.168.122.4 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.202/0.349/0.518/0.129 ms
Each time the guest or VM called xenial comes online (or rebooted for the kernel update) it will get 192.168.122.4 as static IP address by dnsmasq DHCP server.

------------------------------------------------------------------------------------------------------------------------
# virsh set-user-password <domain> <user> <password>