Create CoreOS Virtual Machine images for OpenStack (images officially provided based on CoreOS)

Source: Internet
Author: User
Tags time zones openstack swift

Create CoreOS Virtual Machine images for OpenStack (images officially provided based on CoreOS)

1. Download The CoreOS image (version 633.1.0)

The CoreOS official website already has Virtual Machine images used by openstack. You can download them directly and modify them.

Http://stable.release.core-os.net/amd64-usr/current/coreos_production_openstack_image.img.bz2

# If you need to use an iso file to create an image, refer to another article

2. Modify CoreOS image by guestfish

2.1 install the guestfish Tool

Yum install libguestfs-tools-c-1.20.11-11.el6.x86_64

2.2 Use guestfish to mount CoreOS Images

Guestfish-a coreos_production_openstack_image.img-I
 
# Mount the corresponding Partition
Mount/dev/sda9/
Mkdir/cloudinit
Mount/dev/sda6/cloudinit
 
# Cloud-config.yml is the boot configuration file provided by the system, we can take the services that need to be started, or customize the modifications to the system to write a certain syntax to this file (set sshd below ), if the File Syntax is correct, CoreOS will execute it each time it is started.
# The cloujd-config.yml is located in the/usr/share/oem directory of the system, on the sda6 partition, this is temporary mounting under the/cloudinit directory

2.3 enable the root account

By default, CoreOS disables the root account, so you need to modify the/etc/shadow file, modify the row of the root user, and leave the second field blank.

2.4 set sshd

# Edit/cloudinit/cloud-init.yml file, set sshd_config file, allow root user login, allow Password Authentication

# Cloud-config
Coreos:
Units:
-Name: user-configdrive.service
Mask: yes
-Name: user-configvirtfs.service
Mask: yes
Write_files:
-Path:/etc/ssh/sshd_config
Permissions 0600
Owner: root
Content: |
UsePrivilegeSeparation sandbox
Subsystem sftp internal-sftp
PermitRootLogin yes
AllowUsers root
PasswordAuthentication yes
ChallengeResponseAuthentication no

3. Start the VM.

The preceding steps use the guestfish tool to modify the CoreOS image. Now you can use this image to start the VM and use the root account to log on to the system without a password (set in/etc/shadow above)
• If you use libvirt to manage virtual machines, you need to define the xml file and run the virsh command to start the virtual machine.
• Use qemu-kvm-m 1024 coreos_production_openstack_image.img to start the VM directly using the command line

4. Set the cloudinit. sh script

4.1 new/etc/cloud-init.sh script

# Need to write a cloud-init.sh script, this script in the system boot from the metadata server to get data, complete the modification of the Host Name, modify the root password, ssh key Injection

#! /Bin/bash
# Cloud-init.sh
# Author: xxx
# Date:
 
# Get the env
Export PATH =/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin
 
STATUS_CODE = 'curl-I-m 10-o/dev/null-s-w % {http_code} http: // 169.254.169.254/latest'
If [! "$ STATUS_CODE"-eq "200"]; then
/Bin/sleep 3
Fi
 
# Set the root password using user data
STATUS_CODE = 'curl-I-m 10-o/dev/null-s-w % {http_code} http: // 169.254.169.254/latest/user-data'
If ["$ STATUS_CODE"-eq "200"]; then
PASS = 'curl-m 10-s http: // 169.254.169.254/latest/user-data | awk-F' "'' {for (I = 1; I <= NF; I ++) {if ($ I ~ /Password/) print $ (I + 2 )}}''
If ["$ PASS "! = ""]; Then
/Usr/bin/echo "root: $ {PASS}"> tmp.txt
/Usr/sbin/chpasswd <tmp.txt
Rm-f tmp.txt
Fi
Fi
 
# Set the hostname using the meta-data service
STATUS_CODE = 'curl-I-m 10-o/dev/null-s-w % {http_code} http: // 169.254.169.254/latest/meta-data/hostname'
If ["$ STATUS_CODE"-eq "200"]; then
Curl-f http: // 169.254.169.254/latest/meta-data/hostname>/tmp/metadata-hostname 2>/dev/null
If [$? -Eq 0]; then
TEMP_HOST = 'cat/tmp/metadata-hostname | awk-F'. novalocal ''{print $1 }''
/Usr/bin/hostnamectl set-hostname $ {TEMP_HOST}
/Usr/bin/hostname $ TEMP_HOST
Rm-f/tmp/metadata-hostname
Fi
Fi
 
# Get the user ssh key using the meta-data service
STATUS_CODE = 'curl-I-m 10-o/dev/null-s-w % {http_code} http: // 169.254.169.254/latest/meta-data/public-keys/0/openssh-key'
If ["$ STATUS_CODE"-eq "200"]; then
Mkdir-p/root/. ssh
/Usr/bin/echo>/root/. ssh/authorized_keys
Curl-m 10-s http: // 169.254.169.254/latest/meta-data/public-keys/0/openssh-key | grep 'ssh-rsa '>>>/root /. ssh/authorized_keys
Chmod 0700/root/. ssh
Chmod 0600/root/. ssh/authorized_keys
Fi

 

4.2 set startup

Create a new configuration unit, cloudinit. service, which is used to execute a cloud-init.sh script at startup

 

# Cat/etc/systemd/system/cloudinit. service
[Unit]
Description = OpenStack nova
Request = coreos-setup-environment.service
After = coreos-setup-environment.service
Beforedomainuser-config.tar get
[Service]
Type = oneshot
RemainAfterExit = yes
EnvironmentFile =-/etc/environment
ExecStart =/usr/bin/bash/etc/cloud-init.sh # Run the script file cloud-init.sh
[Install]
Wantedbypolicmulti-user.tar get

 

4.3 set cloudinit. service to start up

# Start startup
Systemctl enable cloudinit. service
# Check for effectiveness
Systemctl is-enabled cloudinit

 

5. Set the network


5.1 use dhcp

Create the eth0.network file in the/etc/systemd/network/directory. The file content is as follows:

[Match]
Name = eth0
[Network]
DHCP = yes

5.2 use a fixed IP Address

 

Cat eth0.network
[Match]
Name = eth0
[Network]
Address = 192.168.1.15/24
Gateway = 192.168.1.1
DNS = 223.5.5.5

6. Set Time Synchronization and Time Zone

6.1 set ntpd

# View ntpd status and enable

Systemctl status ntpd
Systemctl enable ntpd

6.2 modify ntp time servers

# You can modify the/etc/ntp. conf configuration file for ntp servers. The format is as follows:

Server 0.pool.example.com
Server 1.pool.example.com

6.3 set the time zone

# View the current status
Timedatectl status
# View available time zones
Timedatectl list-timezones
# Change to Shanghai City
Timedatectl set-timezone Asia/ShangHai
# View the current status again
Timedatectl status

Install and deploy Openstack on Ubuntu 12.10

Ubuntu 12.04 OpenStack Swift single-node deployment Manual

OpenStack cloud computing quick start tutorial

Deploying OpenStack for enterprises: what should be done and what should not be done

CentOS 6.5 x64bit quick OpenStack Installation

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.