Te hanga i to ake ahua me te CentOS 5.9 parakore i te kapua Amazon

Kei te mohio koe, i roto i te Amazon kapua mariko ka whakarewahia nga ahuatanga i runga i nga whakaahua (ko te mea e kiia ana Ami). Ka whakaratohia e Amazon he maha o ratou; ka taea hoki e koe te whakamahi i nga whakaahua a te iwi i whakaritea e nga roopu tuatoru, kaore he kawenga a te kaiwhakarato kapua. Engari i etahi wa ka hiahia koe ki tetahi ahua punaha ma me nga taapiri e tika ana, kaore i te raarangi o nga whakaahua. Ko te huarahi anake ki waho ko te hanga i to ake AMI.

Ko nga tuhinga whaimana e whakaatu ana ara te hanga i te "AMI toa-tautokohia". Ko te kino o tenei huarahi ko te ahua kua oti me huri ano ki te "AMI tautoko-EBS"

Me pehea te hanga i a koe ake AMI kua tautokohia e te EBS i roto i te kapua Amazon kaore he takahanga takawaenga ka korerohia i roto i tenei tuhinga.

Mahere mahi:

  • Whakaritea te taiao
  • Tāutahia he pūnaha ma me te hanga i nga tautuhinga e tika ana
  • Tangohia he whakaahua o te kōpae
  • Rēhita AMI

Te Whakarite Taiao

Mo o maatau kaupapa, he pai te ahua o te ahua, ahakoa t1.micro. Ka taea e koe te whakahaere ma te CLI:

aws ec2 run-instances --image-id ami-1624987f --max-count 1 --min-count 1 --key-name mel --instance-type t1.micro

Me hanga ebs-rōrahi, ki reira ka whakauruhia to tatou punaha i muri mai:

aws ec2 create-volume --availability-zone us-east-1a --size 10

Ma tenei whakahau ka hanga he kōpae 10 Gb ma tatou. He mea nui: me noho te kōpae ki te rohe rite ki te tauira (i roto i ta maatau ko us-rawhiti-1a).
I muri mai, me whakauru koe i te kōpae ki te tauira:

aws ec2 attach-volume --instance-id i-2bc0925b --volume-id vol-08ab3079 --device /dev/xvdf

Inaianei me takiuru ki te tauira ma te ssh, whakahōputuhia te kōpae ka whakairihia ki roto i te raarangi:

mkfs.ext3 /dev/xvdf
mkdir /mnt/centos-image
mount /dev/xvdf /mnt/centos-image
cd !$

Te whakauru i nga Centos ma 5.9

I mua i te whakauru i te punaha, me hanga e koe he rakau whaiaronga, whakairihia te proc me te sysfs, me te hanga i tetahi huinga taputapu iti:

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

Ka whakauruhia e matou te punaha ma te whakamahi i te yum me te konae whirihoranga e whai ake nei:
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

I muri i te whakaoti i te tukanga whakauru, ka taea e koe te whakauru i nga kohinga e tika ana kia rite ano:

yum -c ~/yum-centos.conf --installroot=/mnt/centos-image/ install $packet_name

Me whakatika te 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

I roto i te CentOS 5.9 me whakauru tonu koe i te kakano me te tautoko xen:

yum -c ~/yum-centos.conf --installroot=/mnt/centos-image/ -y install kernel-xen

Tāuta Grub:

chroot /mnt/centos-image/ grub-install /dev/xvdf

ka hangaia he 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 tino nui ki te tautuhi i enei tawhā katoa me te fstab hou, mena ka kore te punaha e pupuhi.
Whai muri ka hiahia koe ki te hanga i tetahi konae.lst mo te 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

Me whirihora i te whatunga me te 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

Na, ka whiwhi tatou i te whatunga mahi me te kaha ki te takiuru ki te tauira ma te whakamahi i nga ki. Engari ko te matua ake me whakawhiti ki te tauira. Ka taea tenei ma te whakamahi i tetahi tuhinga ka tango i te ki ka tiakina i runga i te tauira:

vi /mnt/centos5img/etc/init.d/ec2-get-ssh

ec2-tiki-ssh#! / bin / bash
# chkconfig: 2345 95 20
# ingoa tukanga: ec2-get-ssh
# whakaahuatanga: Hopukia nga tohu tohu matua a AWS mo te kaiwhakamahi EC2

# Puna mahi puna
. /etc/rc.d/init.d/functions

# Te whirihoranga whatunga puna
[ -r /etc/sysconfig/network ] &&. /etc/sysconfig/network

# Whakakapihia nga taurangi taiao e whai ake nei mo to punaha
kaweake PATH=:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin

# Tirohia kua whirihorahia te whatunga
if [ "${NETWORKING}" = "kao" ]; katahi
echo "Kaore i whirihorahia te whatunga."
putanga 1
fi

tiimata () {
mehemea [! -d /root/.ssh ]; katahi
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Tikina nga taviri a te iwi mai i te tūmau metadata ma te whakamahi i te HTTP
korikori -f 169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/taku-pātuhi-iwi
ki te [$? -eq 0 ]; katahi
echo "EC2: Tikina te kī tūmatanui mai i te tūmau metadata mā te whakamahi HTTP."
ngeru /tmp/my-public-key >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
rm /tmp/taku-nui-matua
fi
}

mutu() {
echo "Kaore he mahi i konei"
}

tīmata anō() {
mutu
tīmatanga
}

# Tirohia te ahua o to matou karangatanga.
take "$1" ki roto
timata)
tīmatanga
;;
mutu)
mutu
;;
tīmata anō)
tīmata
;;
*)
echo $"Whakamahinga: $0 {tīmata|kati|whakahou}"
putanga 1
aporo

putanga $?
Kia taea e tatou te kawe me te taapiri atu ki te whakaoho:

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

He mea tika ano kia whakakorehia a Selinux, whirihora tika ranei. Ki te kore, hei tauira, kare pea te kii e tiakina ki te tauira.
I tenei wa ka taea e koe te whakamutu i te whakarite i te punaha. Kua rite a matou CentOS parakore ki te rere i roto i te kapua. Ko nga mea e toe ana ko te wetewete i te kōpae ebs me to tatou punaha me te rehita ami.

umount /mnt/centos-image/proc/
umount /mnt/centos-image/sys/
umount /mnt/centos-image/

Rehitatanga AMI

Hei tiki ami mai i te kōpae ebs, me tango e koe he whakaahua o te kōpae:

aws ec2 create-snapshot --volume-id vol-0b4bd07a --description centos-snap

Ko te huarahi ngawari ki te rehita ami ma te AWS Management Console. Ki te mahi i tenei, me haere noa koe ki te waahanga "Snapshots" i roto i te ratonga EC2, tohua te mea e hiahiatia ana e koe (i roto i ta maatau he centos-snap), paato-matau ki runga ka kowhiri i te "Waihanga Whakaahua mai i te Whakaahua"
Na, i te matapihi e tuwhera ana, me whiriwhiri koe i nga waahanga e whai ake nei:

Te hanga i to ake ahua me te CentOS 5.9 parakore i te kapua Amazon

Ka kitea e koe ko tehea Kernel ID hei whiriwhiri 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

Heoi ano. Inaianei ka taea e koe te whakarewa i nga tauira.
Ma tenei ara, ka taea e koe te hanga i tetahi ahua, te nuinga pea, me tetahi tohatoha Linux. Ko te iti rawa, ko Debian (ma te whakamahi i te debootstrap ki te whakauru i tetahi punaha ma) me te Rhel-whanau.

Source: will.com

Tāpiri i te kōrero