【失败】制作CentOS镜像

1.在vmware上安装centos虚拟机,安装过程中设置CPU时,点选 虚拟化Intel VT-x~ 和 虚拟化CPU性能计数器,网络使用NAT模式

2.#mkdir /opt/iso,上传镜像(用VMwareTool

3.安装软件:

#yum groupinstall Virtualization "Virtualization Client"

#yum install libvirt -y

#yum -y install tigervnc

4.设置虚拟网络支持

启动libvirtd服务:#service libvirtd restart

允许ip路由转发:编辑/etc/sysctl.conf文件,修改net.ipv4.ip_forward = 1

使修改生效:#sysctl -p

5.创建镜像文件

#mkdir /opt/image

#cd /opt/image

#qemu-img create -f qcow2 CentOS6.6_try.img 10G

#chown qemu. /opt/image -R

注意:10G表示创建的镜像大小,因为bcec支持根分区扩展,因此,对于普通的linux,windows镜像来说,10G足够,如果填写过大,反而会无法创建小模板的虚拟机,将linux所有的包都装上需要配置30G

6.virsh创建虚拟机 

切换到图形界面

#virt-install  -n CentOSimg -r 1024 --cpu host -c /opt/iso/CentOS-6.6-x86_64-bin-DVD1.iso --disk path=/opt/image/CentOS6.6_try.img,device=disk,bus=virtio,size=10,format=qcow2 --vnc --vncport=5900 --vnclisten=0.0.0.0 -v

注意:1024 代表内存1024M,10 代表硬盘大小为10G

使用上述命令会自动启动一个安装界面,但建议改为使用vncview访问安装界面:vncviewer 127.0.0.1

 

图形安装过程中,选择磁盘分区时,需要选择手动分区,而且不要使用lvm,不要分配swap分区:

1.选择Create Custom Layout

2.只留下dev/hda(vda),删除其它分区

3.双击此分区,设置挂载点为/,类型为ext3,size填1,选中fill to maximum allowable size和force to be a primary partition。

 

wget http://10.254.3.75/images/configdrive/disk.config,下载disk.config,开始配置:

更换iso

#virsh dumpxml CentOSimg >centos2.xml

vim centos2.xml,修改device='cdrom'的iso路径 <source file='/opt/iso/disk.config'/>  

#virsh undefine CentOSimg

#virsh define centos2.xml

启动镜像:

#virsh start CentOSimg

注意:这一次重新启动和上一次启动的区别在于,将安装光盘去掉,将disk.config加入

 

以下在创建的虚机CentOSimg中操作(vncviewer 127.0.0.1)

1、关闭防火墙

[root@localhost ~]# chkconfig iptables off

2、关闭Avahi

[root@localhost ~]# chkconfig avahi-daemon off

3、关闭Selinux

[root@localhost ~]# vi /etc/selinux/config

SELINUX=disabled

4、配置SSH

[root@localhost ~]# vi /etc/ssh/sshd_config

UseDNS=no(是否开启DNS域名查找)

GSSAPIAuthentication=no(是否允许使用基于GSSAPI的用户认证)

PermitRootLogin=yes(是否允许Root登陆)

PasswordAuthentication=yes(是否开启密码认证)

[root@localhost ~]# vi /etc/nsswitch.conf

hosts:files  dns(解析主机名的顺序,如果不希望DNS解析,则删除dns)

5、查看网络状态

先在VMware里查看之前安装的libvirtd是否运行:/etc/init.d/libvirtd status

libvirtd (pid  2787) is running...

在CentOSimg里配置网络:vi /etc/sysconfig/network-scripts/ifcfg-eth0

修改ONBOOT=yes

重启网络: /etc/init.d/network restart

之后ping一下baidu试试通否

6、电源配置

安装电源模块

[root@localhost ~]#  yum install acpid -y     #-y的作用是自动在安装过程中输入yes#

设置电源模块开机启动

[root@localhost ~]# chkconfig acpid on  

修改配置文件

[root@localhost ~]# vi /etc/acpi/events/power.conf

event=button/power.*

# action=/etc/acpi/actions/power.sh(注释此行,并增加下面一行)

action=/sbin/shutdown –h now

7、安装cloud-init

[root@localhost ~]# yum install http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

[root@localhost ~]#  yum install cloud-init

8、安装文件系统扩容工具linux-rootfs-resize

[root@localhost ~]# cd /opt

[root@localhost~]#  rpm -ivh http://ftp-stud.hs-esslingen.de/pub/epel/6/i386/epel-release-6-8.noarch.rpm

[root@localhost ~]# yum install git parted cloud-utils

[root@localhost ~]# git clone https://github.com/flegmatik/linux-rootfs-resize.git

[root@localhost ~]# cd linux-rootfs-resize/distro/centos-6

[root@localhost ~]# vi mod

删掉  resize2fs -p /dev/${root_dev}${part_num}  这一行

[root@localhost ~]# cd ../..

[root@localhost ~]# ./install

9、修改grub.conf,使启动日志能够在dashboard上显示

[root@localhost ~]# vi /boot/grub/grub.conf

在kernel /boot/vmlinuz-2.6.32-431.el6.x86_64-mod ro后面加console=tty0 console=ttyS0,

即变为:kernel /boot/vmlinuz-2.6.32-431.el6.x86_64-mod ro console=tty0 console=ttyS0 root=UUID=82574b46-8e40-4c73-b2ac-9f06f5a805b7

10、安装ovirt-guest-agent

# yum install ovirt-guest-agent -y

11、修改文件/etc/udev/rules.d/55-ovirt-guest-agent.rules

在SYMLINK=="virtio-ports/com.redhat.rhevm.vdsm", OWNER="ovirtagent", GROUP="ovirtagent"后添加:

SYMLINK=="virtio-ports/com.redhat.rhevm.vdsm.0", OWNER="ovirtagent", GROUP="ovirtagent"

12、配置cloud-init

编辑/etc/cloud/cloud.cfg,内容如下:

users:

 - default

 

disable_root: 0

ssh_pwauth:   1

 

datasource_list: ['ConfigDrive']

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:

 - bootcmd

 - write-files

 - resizefs

 - set_hostname

 - update_hostname

 - update_etc_hosts

 - rsyslog

 - users-groups

 - ssh

 

cloud_config_modules:

 - mounts

 - locale

 - set-passwords

 - timezone

 - puppet

 - chef

 - salt-minion

 - mcollective

 - disable-ec2-metadata

 - runcmd

 

cloud_final_modules:

 - rightscale_userdata

 - scripts-per-once

 - scripts-per-boot

 - scripts-per-instance

 - scripts-user

 - ssh-authkey-fingerprints

 - keys-to-console

 - phone-home

 - final-message

 

system_info:

  distro: rhel

  default_user:

    name: root

  paths:

    cloud_dir: /var/lib/cloud

    templates_dir: /etc/cloud/templates

  ssh_svcname: sshd

 

# vim:syntax=yaml

13、上述配置完成后,关机

 

二次配置

Vmware里启动这个镜像

#virsh start CentOSimg

以下在虚机中操作(vncviewer 127.0.0.1)

 

没有以下了,因为:

promote login: root

Password:

Login incorrect

无法登陆,放弃。。。

 

转载于:https://www.cnblogs.com/cmss/p/4860374.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值