E like me kāu e ʻike ai, ma ka Amazon cloud virtual i hoʻokumu ʻia ma muli o nā kiʻi (ka mea i kapa ʻia
Hōʻike ka palapala kūhelu
Pehea e hana ai i kāu AMI ponoʻī i kākoʻo ʻia e EBS ma ke ao Amazon me ka ʻole o nā pae waena e kūkākūkā ʻia ma kēia ʻatikala.
Hōʻuluʻulu Hana:
- E hoʻomākaukau i ke kaiapuni
- E hoʻouka i kahi pūnaewele maʻemaʻe a hana i nā hoʻonohonoho pono
- E kiʻi i kahi kiʻi o ka disk
- Kakau AMI
Hoʻomākaukau i ke Kaiapuni
No kā mākou kumu, kūpono kēlā me kēia ʻano o ke ʻano, ʻo t1.micro. Hiki iā ʻoe ke holo ma o ka CLI:
aws ec2 run-instances --image-id ami-1624987f --max-count 1 --min-count 1 --key-name mel --instance-type t1.micro
E hana kāua ebs-volume, kahi e hoʻokomo ai i kā mākou ʻōnaehana ma hope:
aws ec2 create-volume --availability-zone us-east-1a --size 10
E hana kēia kauoha i kahi diski 10 Gb no mākou. Mea nui: pono ka disk ma ka ʻāpana like me ka laʻana (i kā mākou hihia ʻo us-east-1a).
A laila, pono ʻoe e hoʻopili i ka disk i ka laʻana:
aws ec2 attach-volume --instance-id i-2bc0925b --volume-id vol-08ab3079 --device /dev/xvdf
I kēia manawa, e hoʻokomo i ka laʻana ma o ssh, e hōʻano i ka disk a kau i loko o ka papa kuhikuhi:
mkfs.ext3 /dev/xvdf
mkdir /mnt/centos-image
mount /dev/xvdf /mnt/centos-image
cd !$
Ke hoʻokomo nei i ka Centos maʻemaʻe 5.9
Ma mua o ka hoʻokomo ʻana i ka ʻōnaehana, pono ʻoe e hana i kahi lāʻau papa kuhikuhi, mount proc a me sysfs, a hana i kahi liʻiliʻi o nā mea hana:
mkdir centos-image/{boot,tmp,dev,sys,proc,etc,var}
mount -t proc none /mnt/centos-image/proc/
mount -t sysfs none /mnt/centos-image/sys/
for i in console null zero ; do /sbin/MAKEDEV -d /mnt/centos-image/dev -x $i ; done
E hoʻokomo mākou i ka ʻōnaehana me ka hoʻohana ʻana i ka yum a me kēia faila hoʻonohonoho:
yum-centos.conf
[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
exclude=*-debuginfo
gpgcheck=0
obsoletes=1
reposdir=/dev/null
[base]
name=CentOS-5.9 - Base
mirrorlist=http://mirrorlist.centos.org/?release=5.9&arch=x86_64&repo=os
#baseurl=http://mirror.centos.org/centos/5.9/os/x86_64/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
[updates]
name=CentOS-5.9 - Updates
mirrorlist=http://mirrorlist.centos.org/?release=5.9&arch=x86_64&repo=updates
#baseurl=http://mirror.centos.org/centos/5.9/updates/x86_64/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-5.9 - Extras
mirrorlist=http://mirrorlist.centos.org/?release=5.9&arch=x86_64&repo=extras
#baseurl=http://mirror.centos.org/centos/5.9/extras/x86_64/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-5
[centosplus]
name=CentOS-5.9 - Plus
mirrorlist=http://mirrorlist.centos.org/?release=5.9&arch=x86_64&repo=centosplus
#baseurl=http://mirror.centos.org/centos/5.9/centosplus/x86_64/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-5
[contrib]
name=CentOS-5.9 - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=5.9&arch=x86_64&repo=contrib
#baseurl=http://mirror.centos.org/centos/5.9/contrib/x86_64/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-5
yum -c ~/yum-centos.conf --installroot=/mnt/centos-image/ -y groupinstall Base
Ma hope o ka hoʻopau ʻana i ke kaʻina hana, hiki iā ʻoe ke hoʻokomo i nā pūʻolo pono ma ke ʻano like:
yum -c ~/yum-centos.conf --installroot=/mnt/centos-image/ install $packet_name
E hoʻoponopono iā fstab:
vi /mnt/centos-image
/dev/xvda1 / ext3 defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
Ma CentOS 5.9 pono ʻoe e hoʻokomo i kahi kernel me ke kākoʻo xen:
yum -c ~/yum-centos.conf --installroot=/mnt/centos-image/ -y install kernel-xen
E hoʻouka iā Grub:
chroot /mnt/centos-image/ grub-install /dev/xvdf
a hana i kahi initrd hou:
chroot /mnt/centos-image/
cd boot/
mkinitrd --omit-scsi-modules --with=xennet --with=xenblk --fstab=/etc/fstab --preload=xenblk initrd-2.6.18-348.1.1.el5xen.img 2.6.18-348.1.1.el5xen
He mea koʻikoʻi ke kuhikuhi ʻana i kēia mau ʻāpana āpau a me kahi fstab hou, inā ʻaʻole e holo ka ʻōnaehana.
A laila pono ʻoe e hana i kahi faila menu.lst no grub:
default=0
timeout=5
hiddenmenu
title CentOS_5.9_(x86_64)
root (hd0)
kernel /boot/vmlinuz-2.6.18-348.1.1.el5xen ro root=/dev/xvda1
initrd /boot/initrd-2.6.18-348.1.1.el5xen.img
E hoʻonohonoho i ka pūnaewele a me sshd:
vi etc/sysconfig/network-scripts/ifcfg-eth0
ONBOOT=yes
DEVICE=eth0
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
vi etc/sysconfig/network
NETWORKING=yes
chroot /mnt/centos5img/ chkconfig --level 2345 network on
vi /mnt/centos5img/etc/ssh/sshd_config
...
UseDNS no
PermitRootLogin without-password
No laila, e loaʻa iā mākou kahi pūnaewele hana a me ka hiki ke komo i loko o ka hihia me ka hoʻohana ʻana i nā kī. Akā ʻo ke kī ponoʻī pono e hoʻoneʻe ʻia i ke ʻano. Hiki ke hana i kēia me ka hoʻohana ʻana i kahi ʻatikala e lawe i ke kī a mālama iā ia ma ke ʻano:
vi /mnt/centos5img/etc/init.d/ec2-get-ssh
ec2-loaʻa-ssh#! / bin / awiʻu
# chkconfig: 2345 95 20
# inoa kaʻina hana: ec2-get-ssh
# wehewehe: Hopu i nā hōʻoia kī lehulehu AWS no ka mea hoʻohana EC2
# Puna hana waihona
. /etc/rc.d/init.d/functions
# Hoʻonohonoho pūnaewele kumu
[-r /etc/sysconfig/network ] &&. /etc/sysconfig/network
# Hoʻololi i nā ʻano hoʻololi kaiapuni aʻe no kāu ʻōnaehana
export PATH=:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
# E nānā ua hoʻonohonoho ʻia ka pūnaewele
inā [ "${NETWORKING}" = "ʻaʻole"]; alaila
echo "ʻAʻole i hoʻonohonoho ʻia ka pūnaewele."
puka 1
fi
hoʻomaka () {
ina [! -d /root/.ssh ]; alaila
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# E kiʻi i nā kī ākea mai ka server metadata me ka hoʻohana ʻana iā HTTP
wili -f
ina [$? -eq 0]; alaila
echo "EC2: E kiʻi i ke kī lehulehu mai ka server metadata me HTTP."
cat /tmp/my-public-key >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
rm /tmp/my-nui-nui
fi
}
kū () {
echo "ʻAʻohe mea e hana ma ʻaneʻi"
}
hoʻomaka hou () {
e oki
hoʻomaka
}
# E ʻike pehea mākou i kapa ʻia ai.
hihia "$1" ma
hoʻomaka)
hoʻomaka
;;
kū)
e oki
;;
hoʻomaka hou)
e hoʻomaka hou
;;
*)
echo $"Hoʻohana: $0 {hoʻomaka|hoʻoki|hoʻomaka hou}"
puka 1
ʻākeʻe
puka $?
E hoʻokō a hoʻohui i ka hoʻomaka:
chmod +x /mnt/centos-image/etc/init.d/ec2-get-ssh
/usr/sbin/chroot /mnt/centos-image/ /sbin/chkconfig --level 34 ec2-get-ssh on
Pono nō hoʻi e hoʻopau iā Selinux, a i ʻole e hoʻonohonoho pono iā ia. A i ʻole, no ka laʻana, ʻaʻole hiki ke mālama ʻia ke kī ma ka laʻana.
I kēia manawa hiki iā ʻoe ke hoʻōki i ka hoʻonohonoho ʻana i ka ʻōnaehana. Loaʻa iā mākou ka CentOS maʻemaʻe e holo i ke ao. ʻO ka mea i koe, ʻo ka wehe ʻana i ka disk ebs me kā mākou ʻōnaehana a hoʻopaʻa inoa ami.
umount /mnt/centos-image/proc/
umount /mnt/centos-image/sys/
umount /mnt/centos-image/
kakau inoa AMI
No ka loaʻa ʻana o ka ami mai kahi ebs disk, pono ʻoe e lawe i kahi kiʻi o ka disk:
aws ec2 create-snapshot --volume-id vol-0b4bd07a --description centos-snap
ʻO ke ala maʻalahi loa e hoʻopaʻa inoa ami ma o ka AWS Management Console. No ka hana ʻana i kēia, pono ʻoe e hele i ka ʻāpana "Snapshots" i ka lawelawe EC2, koho i ka mea āu e pono ai (i kā mākou hihia he centos-snap), kaomi pololei ma luna a koho i ka "Hana i ke kiʻi mai Snapshot"
A laila, i ka puka aniani e wehe ai, pono ʻoe e koho i nā ʻāpana aʻe:
Hiki iā ʻoe ke ʻike i ka Kernel ID e koho ai penei:
aws ec2 describe-images --owner amazon --region us-east-1 --output text | grep "/pv-grub-hd0.*-x86_64" | awk '{print $7}' | grep aki
aki-88aa75e1
aki-b4aa75dd
ʻo ia wale nō. I kēia manawa hiki iā ʻoe ke hoʻomaka i nā hiʻohiʻona.
Ma kēia ala, hiki iā ʻoe ke hana i kahi kiʻi, ʻoi aku paha, me kekahi mahele Linux. Ma ka liʻiliʻi loa, ʻo Debian (e hoʻohana ana i ka debootstrap e hoʻokomo i kahi ʻōnaehana maʻemaʻe) a me Rhel-ʻohana.
Source: www.habr.com