一、配置网络
ip addr add {ip} dev eth0
ip link set dev eth0 up
ip route add default via {网关}
二、修改dns:
systemctl stop systemd-resolved
systemctl disable systemd-resolved
删除/etc/resolv.conf(该文件为软链接)
vim /etc/resolv.conf
写入:nameserver 114.114.114.114
三、修改DHCP
vim /etc/cloud/cloud.cfg.d/50-curtin-networking.cfg
修改为如下形式:
vim /etc/netplan/50-cloud-init.yaml
执行命令“netplan apply”
1、手动设置系统盘分区,采用标准分区,sda1(1024MB)作为swap,sda2作为系统根目录
2、装系统时选时区下方有是否用CST时间
执行“ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime”命令
3、安装软件包
apt install qemu-guest-agent openssh-server bash-completion ntpdate sysstat sudo vim ntp
4、将在编译后版本与宿主机qemu版本保持一致的qemu-ga执行文件scp到虚拟机内某个目录(如/opt/目录)下,然后将虚拟机内原来的qemu-ga(CentOS的/usr/bin/qemu-ga ,Ubuntu的/usr/sbin/qemu-ga)换掉,并重命名为ycloud-ga:
注:ubuntu 修改/etc/init.d/qemu-guest-agent中 NAME=ycloud-ga,PIDFILE=/var/run/qemu-ga.pid
5、修改/etc/ssh/sshd_config文件内容,字段值如下:
PermitRootLogin yes
PasswordAuthentication no
GSSAPIAuthentication no
UseDNS no
6、修改/etc/default/grub文件内一些内容项如下:
在GRUB_CMD_LINUX=""引号内田间"net.ifnames=0 biosdevname=0"
执行“grub-mkconfig -o /boot/grub/grub.cfg”命令
7、设置编码格式
apt-get install --reinstall locales && sudo dpkg-reconfigure locales
/etc/default/locale
LANG="en_US.UTF-8"
LANGUAGE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
修改apt源source.list中的所有的http://archive.ubuntu.com/ubuntu字段为http://cn.archive.ubuntu.com/ubuntu
8、关闭防火墙
systemctl disable ufw && systemctl disable iptables
9、安装denyhosts并修改/etc/denyhosts.conf,具体步骤如下:
2)apt 安装denyhosts安装包,命令: apt install denyhosts
3)修改denyhosts配置项
############ THESE SETTINGS ARE REQUIRED ############
SECURE_LOG = /var/log/secure
HOSTS_DENY = /etc/hosts.deny
PURGE_DENY = 5m
BLOCK_SERVICE = sshd
DENY_THRESHOLD_INVALID = 20
DENY_THRESHOLD_VALID = 20
DENY_THRESHOLD_ROOT = 20
DENY_THRESHOLD_RESTRICTED = 20
WORK_DIR = /var/lib/denyhosts
SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES
HOSTNAME_LOOKUP=NO
LOCK_FILE = /var/lock/subsys/denyhosts
############ THESE SETTINGS ARE OPTIONAL ############
SMTP_SUBJECT = DenyHosts Report from $[HOSTNAME]
AGE_RESET_VALID=1w
AGE_RESET_ROOT=1w
AGE_RESET_RESTRICTED=1w
AGE_RESET_INVALID=1w
RESET_ON_SUCCESS = yes
######### THESE SETTINGS ARE SPECIFIC TO DAEMON MODE ##########
DAEMON_LOG = /var/log/denyhosts
DAEMON_SLEEP = 30s
DAEMON_PURGE = 5m
######### THESE SETTINGS ARE SPECIFIC TO ##########
######### DAEMON SYNCHRONIZATION ##########
10、安装 cloud-init
apt install cloud-init cloud-initramfs-growroot
cloud-init安装完成后,编辑/etc/cloud/cloud.cfg,删除cloud_init_modules中的update_hostname,以免用户手动设置hostname后重启被覆盖。
disable_root: 0
删除default_user这段
apt-pipelining -> disable-apt-pipelining
apt-configure -> disable-apt-configure
11、 清理历史记录和日志文件
$rm /tmp/* -r
$rm ~/.bash_history –rf
$rm ~/.viminfo –rf
$rm /var/log/*.log –rf
$rm /var/log/*.old -rf
$apt clean all
$history -c
12、qemu-guest-agent服务的名称修改:
参考: http://wiki.yovole.tech/pages/viewpage.action?pageId=2621991