使用virsh console管理虚机

在KVM的虚拟化实践中,使用终端状态的虚机管理软件virsh可以完成创建、删除、管理等一系列动作。但在默认情况下,virsh使用virsh console连接虚机会出现卡住的情况。这是由于virsh console连接不上虚机的虚拟串行端口所致。

对于Ubuntu虚机,解决的方式如下:

首先,KVM环境中的虚机开启相关服务:

$ sudo systemctl start serial-getty@ttyS0
$ sudo systemctl enable serial-getty@ttyS0
Created symlink /etc/systemd/system/getty.target.wants/serial-getty@ttyS0.service → /lib/systemd/system/serial-getty@.service.

然后,无需重启客户机就可以在管理端可以看到结果

root@tc8304:~# virsh start ubuntu
域 ubuntu 已开始

root@tc8304:~# virsh console ubuntu
连接到域 ubuntu
换码符为 ^]

Ubuntu 17.04 ubuntu ttyS0

ubuntu login: 

对于CentOS7的虚机而言,则需要执行如下命令:

root# grubby --update-kernel=ALL --args="console=ttyS0"
root# reboot

virsh管理virt-manager创建的虚机

virsh是kvm虚拟化套件libvirtd提供的字符模式虚拟机管理工具。virt-manager是redhat开发的一套图形界面的kvm虚拟机管理工具。虽然virt-manager和virsh同时是libvirtd这套管理程序的不同类型的管理实现方式,但具体使用起来还是有些许不兼容的地方。
默认使用Desktop版ubuntu安装virt-manager所创建的虚拟机,使用virsh list是看不到的,必须使用virsh list --all命令才能看到。同样,virsh start Beijing也是无法启动虚拟机,会出现“域无法找到”的类似错误。
解决的方法是使用virsh define /etc/libvirt/qemu/Beijing.xml命令,将虚拟机的配置文件在virsh中重新注册一下就可以使用其他的virsh管理命令了。

[root@tc8304 ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 1     Beijing                        running
 2     Shanghai                       running
 -     CentOS                         关闭

tips:
Ubuntu中默认的虚拟机磁盘存放位置是在
/var/lib/libvirt/images
而kvm的配置文件存储位置在
/etc/libvirt/qemu/

MySQL的配置文件

#
# The MySQL database server configuration file.
#
# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 192.168.122.106
#
# * Fine Tuning
#
key_buffer_size     = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
max_connections        = 100
table_open_cache       = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#

general_log_file        = /var/log/mysql/mysql.log
general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
slow_query_log      = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
server-id       = 100
log_bin         = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size   = 100M
#binlog_do_db      = include_database_name
#binlog_ignore_db  = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

关闭Firefox的Flash插件过期提醒

在企业域环境下没有管理员权限的PC机上使用firefox经常会遇到视频以及其他flash应用无法打开,地址栏出现红色叹号的提示,这种现象就是提醒flash插件的新版出现了,需要更新插件。
解决问题的方法一个是更新插件,一个是关闭提醒。
关闭的方法是:

在地址栏输入about:config
在搜索栏输入extensions.blocklist.enabled
将这个值设为false