1.2 操作系统安装过程
图形界面安装、新增test登录用户,
1.3 操作系统配置
#selinux
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
#iptables //关闭防火墙
systemctl stop iptables.service
systemctl disable iptables.service
1.4 qemu-guest-agent安装和配置
#需要外部安装源 @updates
yum install qemu-guest-agent
echo "NOZEROCONF=yes" >> /etc/sysconfig/network
1.5 配置虚拟机163 yum源
1.5.1 给虚拟机配置互联网IP
宿主机和虚拟机对应的网卡配置:
1.5.2 配置yum源
vim /etc/sysconfig/network-scripts/ifcfg-eth0
修改eth0配置文件:留四行,删除各种uuid
#网络IP
[root@localhost network-scripts]# cat ifcfg-eth0
NAME=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=dhcp
vim /etc/resolv.conf
#MAC
Nameserver 114.114.114.114
重启网络
ping baidu.com
rm -f /etc/yum.repos.d/*
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
vim /etc/yum.repos.d/CentOS7-Base-163.repo
:%s/$releasever/7/g
:x
yum clean all
yum makecache
yum list
1.6 cloud-init安装和配置
#调通互联网,最后别忘了删除网络配置。
//针对RHEL-7
yum install cloud-init
yum install cloud-utils-growpart
vim /etc/cloud/cloud.cfg
users:
disable_root: 0
ssh_pwauth: 0
locale_configfile: /etc/sysconfig/i18n
mount_default_fields: [~, ~, ‘auto‘, ‘defaults,nofail‘, ‘0‘, ‘2‘]
resize_rootfs_tmp: /dev
ssh_deletekeys: 0
ssh_genkeytypes: ~
syslog_fix_perms: ~
cloud_init_modules:
cloud_config_modules:
cloud_final_modules:
system_info:
default_user:
name: centos
lock_passwd: true
gecos: Cloud User
groups: [wheel, adm]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
distro: rhel
paths:
cloud_dir: /var/lib/cloud
templates_dir: /etc/cloud/templates
ssh_svcname: sshddatasource_list: [‘OpenStack‘,‘ConfigDrive‘]
_# vim:syntax=yaml
//If there is a defaults.cfg in /etc/cloud/cloud.cfg.d/, delete it.
#修改cloud-init配置文件:
Vim /etc/default/grub
#删除GRUB_CMDLINE_LINUX=……这一行中的rhgb quiet配置项,添加console=tty0 console=ttyS0,115200n8
#使修改后的grub配置文件生效
Grub2-mkconfig –o /boot/grub2/grub.cfg
3.7 个性化配置和清理多余设置
个性化配置:略
清理多余的设置:
比如:DNS配置,磁盘分割,修改密码等。
vim /etc/resolv.conf
#MAC
Nameserver 114.114.114.114
#root密码
Passwd root
password
#管理开关虚拟机服务(可选)
yum install acpid
yum enable acpid
#配置硬盘重新分区(可选)
yum install cloud-utils-growpart
#配置本地YUM源,注意是否需要保留本地ISO源
在宿主机环境下挂载本地iso镜像
virsh destroy rhel7.0
virsh start rhel7.0
virsh attach-disk --type cdrom --mode readonly rhel7.0 "/home/liutuan/iso/xx7.0.iso" hdc
virsh dumpxml rhel7.0 > rhel7.0.xml //方便virsh create *.xml
#进入虚拟机操作系统
#挂载本地iso
mkdir -p /mnt/cdrom /mnt/iso
mount /dev/cdrom /mnt/iso //如果出错,则需要先attach-disk
cp –frv /mnt/iso /mnt/cdrom
rm –rf /mnt/iso
ls /mnt/cdrom
#配置本地yum源
cd /etc/yum.repos.d/
mv CentOS7-Base-163.repo CentOS7-Base-163.repo.bak
cat > /etc/yum.repos.d/local.repo <<EOF
[local]
name=local
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
EOF
Kill –s 9 xx(进程号)
yum clean all
yum makecache
yum repolist
#关机
shutdown
1.8 解除绑定
#安装工具软件
yum install -y libguestfs-tools-c
//ubuntu主机sudo apt-get install libguestfs-tools
//使用VM名称
virt-sysprep -d rhel7.0
virsh undefine rhel7.0
#镜像制作完毕
md5sum rhel7.0.qcow2 > Rrhel7.0.qcow2.md5sum
cat rhel7.0.qcow2.md5sum
781ecc51dde344ffba0e04a7574e6190 rhel7.0.qcow2
1.9 镜像上传
source openrc
glance image-create --property os_type=linux --name " rhel7.0" --is-public true --disk-format raw --container-format bare --file /home/rhel7.0.raw
原文:http://blog.51cto.com/lemonnews/2063261