2019独角兽企业重金招聘Python工程师标准>>>

Example: CentOS image

This example shows you how to install a CentOS image and focuses mainly on CentOS 6.4. Because the CentOS installation process might differ across versions, the installation steps might differ if you use a different version of CentOS.

Download a CentOS install ISO

  1. Navigate to the CentOS mirrors page.

  2. Click one of the HTTP links in the right-hand column next to one of the mirrors.

  3. Click the folder link of the CentOS version that you want to use. For example, 6.4/.

  4. Click the isos/ folder link.

  5. Click the x86_64/ folder link for 64-bit images.

  6. Click the netinstall ISO image that you want to download. For example, CentOS-6.4-x86_64-netinstall.iso is a good choice because it is a smaller image that downloads missing packages from the Internet during installation.

Start the installation process

Start the installation process using either virt-manager or virt-install as described in the previous section. If you use virt-install, do not forget to connect your VNC client to the virtual machine.

Assume that:

  • The name of your virtual machine image is centos-6.4; you need this name when you use virsh commands to manipulate the state of the image.

  • You saved the netinstall ISO image to the /data/isos directory.

If you use virt-install, the commands should look something like this:

# qemu-img create -f qcow2 /tmp/centos-6.4.qcow2 10G
# virt-install --virt-type kvm --name centos-6.4 --ram 1024 \
--disk /tmp/centos-6.4.qcow2,format=qcow2 \
--network network=default \
--graphics vnc,listen=0.0.0.0 --noautoconsole \
--os-type=linux --os-variant=rhel6 \
--extra-args="console=tty0 console=ttyS0,115200n8 serial" \
--location=/data/isos/CentOS-6.4-x86_64-netinstall.iso

Step through the installation

At the initial Installer boot menu, choose the Install or upgrade an existing system option. Step through the installation prompts. Accept the defaults.

Configure TCP/IP

The default TCP/IP settings are fine. In particular, ensure that Enable IPv4 support is enabled with DHCP, which is the default.

Point the installer to a CentOS web server

Choose URL as the installation method.

Depending on the version of CentOS, the net installer requires the user to specify either a URL or the web site and a CentOS directory that corresponds to one of the CentOS mirrors. If the installer asks for a single URL, a valid URL might be http://mirror.umd.edu/centos/6/os/x86_64.

Note

Consider using other mirrors as an alternative to mirror.umd.edu.

If the installer asks for web site name and CentOS directory separately, you might enter:

  • Web site name: mirror.umd.edu

  • CentOS directory: centos/6/os/x86_64

See CentOS mirror page to get a full list of mirrors, click on the "HTTP" link of a mirror to retrieve the web site name of a mirror.

Storage devices

If prompted about which type of devices your installation uses, choose Basic Storage Devices.

Hostname

The installer may ask you to choose a host name. The default (localhost.localdomain) is fine. You install the cloud-init package later, which sets the host name on boot when a new instance is provisioned using this image.

Partition the disks

There are different options for partitioning the disks. The default installation uses LVM partitions, and creates three partitions (/boot/, swap), which works fine. Alternatively, you might want to create a single ext4 partition that is mounted to "/", which also works fine.

If unsure, use the default partition scheme for the installer because no scheme is better than another.

Step through the installation

Step through the installation, using the default options. The simplest thing to do is to choose the "Basic Server" install (may be called "Server" install on older versions of CentOS), which installs an SSH server.

Detach the CD-ROM and reboot

When the installation has completed, the Congratulations, your CentOS installation is complete screen appears.

To eject a disk by using the virsh command, libvirt requires that you attach an empty disk at the same target that the CDROM was previously attached, which should be hdc. You can confirm the appropriate target using the dom dumpxml vm-image command.

# virsh dumpxml centos-6.4
<domain type='kvm'><name>centos-6.4</name>
...<disk type='block' device='cdrom'><driver name='qemu' type='raw'/><target dev='hdc' bus='ide'/><readonly/><address type='drive' controller='0' bus='1' target='0' unit='0'/></disk>
...
</domain>

Run the following commands from the host to eject the disk and reboot using virsh, as root. If you are using virt-manager, the commands below will work, but you can also use the GUI to detach and reboot it by manually stopping and starting.

# virsh attach-disk --type cdrom --mode readonly centos-6.4 "" hdc
# virsh destroy centos-6.4
# virsh start centos-6.4

Log in to newly created image

When you boot for the first time after installation, you might be prompted about authentication tools. Select Exit. Then, log in as root.

Install the ACPI service

To enable the hypervisor to reboot or shutdown an instance, you must install and run the acpid service on the guest system.

Run the following commands inside the CentOS guest to install the ACPI service and configure it to start when the system boots:

# yum install acpid
# chkconfig acpid on

Configure to fetch metadata

An instance must interact with the metadata service to perform several tasks on start up. For example, the instance must get the ssh public key and run the user data script. To ensure that the instance performs these tasks, use one of these methods:

  • Install a cloud-init RPM, which is a port of the Ubuntu cloud-init package. This is the recommended approach.

  • Modify /etc/rc.local to fetch desired information from the metadata service, as described in the next section.

Use cloud-init to fetch the public key

The cloud-init package automatically fetches the public key from the metadata server and places the key in an account. You can install cloud-init inside the CentOS guest by adding the EPEL repo:

# yum install http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum install cloud-init

The account varies by distribution. On Ubuntu-based virtual machines, the account is called ubuntu. On Fedora-based virtual machines, the account is called ec2-user.

You can change the name of the account used by cloud-init by editing the /etc/cloud/cloud.cfg file and adding a line with a different user. For example, to configure cloud-init to put the key in an account named admin, add this line to the configuration file:

user: admin

Write a script to fetch the public key (if no cloud-init)

If you are not able to install the cloud-init package in your image, to fetch the ssh public key and add it to the root account, edit the /etc/rc.d/rc.local file and add the following lines before the line touch /var/lock/subsys/local:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if [ ! -d /root/ . ssh ]; then
mkdir -p /root/ . ssh
chmod 700 /root/ . ssh
fi
# Fetch public key using HTTP
ATTEMPTS=30
FAILED=0
while [ ! -f /root/ . ssh /authorized_keys ]; do
curl -f http: //169 .254.169.254 /latest/meta-data/public-keys/0/openssh-key \
> /tmp/metadata-key 2> /dev/null
if [ \$? -eq 0 ]; then
cat /tmp/metadata-key >> /root/ . ssh /authorized_keys
chmod 0600 /root/ . ssh /authorized_keys
restorecon /root/ . ssh /authorized_keys
rm -f /tmp/metadata-key
echo "Successfully retrieved public key from instance metadata"
echo "*****************"
echo "AUTHORIZED KEYS"
echo "*****************"
cat /root/ . ssh /authorized_keys
echo "*****************"
done

Note

Some VNC clients replace the colon (:) with a semicolon (;) and the underscore (_) with a hyphen (-). Make sure to specify http: and not http;. Make sure to specify authorized_keys and not authorized-keys.

Note

The previous script only gets the ssh public key from the metadata server. It does not get user data, which is optional data that can be passed by the user when requesting a new instance. User data is often used to run a custom script when an instance boots.

As the OpenStack metadata service is compatible with version 2009-04-04 of the Amazon EC2 metadata service, consult the Amazon EC2 documentation on Using Instance Metadata for details on how to get user data.

Disable the zeroconf route

For the instance to access the metadata service, you must disable the default zeroconf route:

# echo "NOZEROCONF=yes" >> /etc/sysconfig/network

Configure console

For the nova console-log command to work properly on CentOS 6.x, you might need to add the following lines to the /boot/grub/menu.lst file:

serial --unit=0 --speed=115200
terminal --timeout=10 console serial
# Edit the kernel line to add the console entries
kernel ... console=tty0 console=ttyS0,115200n8

Shut down the instance

From inside the instance, as root:

# /sbin/shutdown -h now

Clean up (remove MAC address details)

The operating system records the MAC address of the virtual Ethernet card in locations such as /etc/sysconfig/network-scripts/ifcfg-eth0 and /etc/udev/rules.d/70-persistent-net.rules during the instance process. However, each time the image boots up, the virtual Ethernet card will have a different MAC address, so this information must be deleted from the configuration file.

There is a utility called virt-sysprep, that performs various cleanup tasks such as removing the MAC address references. It will clean up a virtual machine image in place:

# virt-sysprep -d centos-6.4

Undefine the libvirt domain

Now that you can upload the image to the Image service, you no longer need to have this virtual machine image managed by libvirt. Use the virsh undefine vm-image command to inform libvirt:

# virsh undefine centos-6.4

Image is complete

The underlying image file that you created with qemu-img create is ready to be uploaded. For example, you can upload the /tmp/centos-6.4.qcow2 image to the Image service.

转载于:https://my.oschina.net/tantexian/blog/625967

制作openstack Centos镜像 -- Example: CentOS image相关推荐

  1. 制作OpenStack上使用的CentOS系统镜像

    很多进行Openstack测试的人都发现,自己的openstack测试环境搭建的很成功,安全策略也添加了,但是上传镜像之后,却出现无法Ping通,无法ssh到实例等问题,实际上这很可能是由于我们没有使 ...

  2. 制作 OpenStack Linux 镜像 - 每天5分钟玩转 OpenStack(151)

    这是 OpenStack 实施经验分享系列的第 1 篇. OpenStack 的 instance 是通过 Glance 镜像部署的,所以准备镜像是必须要做的工作.本节介绍 Linux 镜像的制作方法 ...

  3. docker制作mysql-client的镜像(基于centos)

    由于我的程序需要往mysql数据库中存数据,用到了libmysqlclient.so,所以把我的程序放到docker中运行的时候,需要在docker镜像中包含libmysqlclient.so. 网上 ...

  4. 制作openstack镜像win7.qcow2(centos/ubuntu/win镜像分享)

    转载请注明:姬子的博客 » 制作openstack镜像win7.qcow2(centos/ubuntu/win镜像分享) 在搭建openstack之后,我们即可使用镜像开启实例.然而centos/ub ...

  5. 一分钟,制作一个centos镜像

    大家好,笔者最近学习docker相关的技术.今天,我们一起制作一个 centos镜像. 记得上大学期间我们学习Linux的时候,我们通常是在Window上安装一个vmvare软件,然后下载一个几个G的 ...

  6. docker 的安装以及简单centos镜像制作、启动

    1.安装docker [root@iZ2ze82p1dogve7neb5tuoZ ~]# yum install docker 2.查看 docker 是否成功 [root@iZ2ze82p1dogv ...

  7. 企业私有云应用之使用OZ制作openstack镜像

    最近工作忙,好久没写博客,现在正好有空介绍一下我这里使用私有云的经验. 现在分享一下如何使用oz自动化制作openstack镜像,下面有我自己制作centos 6.4 6.5 6.7 7.2与ubun ...

  8. 制作openstack镜像(qcow2格式的win10系统)

    制作openstack镜像(qcow2格式的win10系统) 1.准备KVM虚拟机 1.1 所需工具 1.2 安装KVM虚拟机详细步骤 1.3 制作qcow2系统 1.准备KVM虚拟机 搭建opens ...

  9. Centos7制作Openstack下win7 镜像

    1 安装Centos7系统 2 验证系统是否支持虚拟化? [root@localhost ~]# egrep '(vmx|svm)' -o  /proc/cpuinfo 出现vmx说明支持. 3 安装 ...

最新文章

  1. python跟java-python(一):python与java语法的异同之处
  2. jsp笔记----97DatePicker日期插件简单使用
  3. LRU LeetCode
  4. mysql2005卸载步骤,二次安装mysql步骤
  5. 零基础零代码,也能一周学会动态报表?这个方法很多人都不知道
  6. 我的Python成长之路---第三天---Python基础(13)---2016年1月16日(雾霾)
  7. python3解码base64_python3base64解码混乱的换行符
  8. pip install rrdtool
  9. android 朋友圈弹出框,Android popupwidown 实现朋友圈评论弹窗显示在软键盘上面
  10. HDU2612---(两次BFS)
  11. 服务器虚拟化基础hcna,华为云计算全新大纲课程 乾颐堂HCNA-Cloud服务器虚拟化云计算实战课程 HCNA认证课程...
  12. python让solidworks自动建模_让机器学习自动帮我们建模,这4个Python库能让你大开眼界...
  13. 《月亮与六便士》的读后感作文3000字
  14. Qt2D游戏开发引擎QtGameEngine使用入门10——游戏中如何响应用户输入(鼠标/键盘输入)
  15. EAX、ECX、EDX、EBX
  16. BTC公钥生成地址的过程详解
  17. 新零售时代,异业联盟怎么做?
  18. VMware虚拟机过检测详细教程,巨全面,小白专享教程
  19. 光纤收发器具体是怎么使用的?光纤收发器使用方法详解!
  20. 月费99,融资过亿,这个老阿里人做出了便利店式健身房

热门文章

  1. DCMTK:OFStandard类的测试程序
  2. VTK:可视化之QuadraticSurface
  3. VTK:相互作用之SelectAVertex
  4. VTK:图片之ImageMapToColors
  5. OpenCV基本线性变换的实例(附完整代码)
  6. C语言判断二叉树是否为二叉搜索树(附完整源码)
  7. QT实现Three.js将Qt Quick项目用作纹理
  8. 登陆用友服务器超时未响应,用友T3软件10.8plus1普及版服务器提示“客户端已经较长时间未连接加密服务器,超时2880秒,请退出产品重新登录”?-用友T3...
  9. 03_Android NDK中C语言调用Java代码,javah的使用,javap的使用以及生成签名,Android.mk的编写,C代码的编写
  10. 强制ul中li不换行