Etsa setšoantšo sa hau ka mokhoa o hloekileng CentOS 5.9 ka har'a leru la Amazon

Joalo ka ha u tseba, ho leru la Amazon ho hlahisoa maemo a hlakileng a ipapisitseng le litšoantšo (tse bitsoang MOTSOALLE). Amazon e fana ka palo e kholo ea tsona, 'me u ka boela ua sebelisa litšoantšo tsa sechaba tse lokisitsoeng ke mekhatlo ea batho ba bang, tseo mofani oa leru, ehlile, a sa jareng boikarabello ho tsona. Empa ka linako tse ling u hloka setšoantšo se hloekileng sa sistimi se nang le liparamente tse hlokahalang tse sa kenyelletsoeng lenaneng la litšoantšo. Maemong a joalo, khetho feela ke ho iketsetsa AMI ea hau.

Litokomane tsa molao lia hlalosa tsela ho theha "AMI e tšehetsoang ke lebenkele la mohlala." Bothata ba mokhoa ona ke hore setšoantšo se felileng le sona se tla hloka ho fetoloa ho ba "AMI e tšehetsoang ke EBS."

Mokhoa oa ho iketsetsa AMI e tšehelitsoeng ke EBS ka leru la Amazon ntle le mehato e mahareng e tla tšohloa sehloohong sena.

Moralo oa Khato:

  • Lokisetsa tikoloho
  • Kenya sistimi e hloekileng 'me u etse litlhophiso tse hlokahalang
  • Nka setšoantšo sa disk
  • Ngolisa AMI

Ho Lokisetsa Tikoloho

Bakeng sa merero ea rona, mohlala ofe kapa ofe oa sebopeho leha e le sefe o tla sebetsa, esita le t1.micro. U ka e qala ka CLI:

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

Ha re etseng ebs-volume moo re tla kenya sistimi ea rona hamorao:

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

Taelo ena e tla re etsetsa disk ea 10 GB. Bohlokoa: disk e tlameha ho ba sebakeng se le seng le mohlala (tabeng ea rona, ke us-east-1a).
Ka mor'a moo, disk e hloka ho hokahanngoa le mohlala:

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

Jwale ha re kene ho mohlala ka ssh, re fomate disk, mme re e kenye bukeng:

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

Ho kenya clean Centos 5.9

Pele o kenya sistimi, o hloka ho theha sefate sa di-directory, ho kenya proc le sysfs, le ho theha sete e fokolang ya disebediswa:

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

Re tla kenya sistimi re sebelisa yum le faele e latelang ea tlhophiso:
monate-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

Hang ha ts'ebetso ea ho kenya e phethehile, o ka kenya liphutheloana life kapa life tse hlokahalang ka tsela e tšoanang:

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

Ha re hlophise 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

В CentOS 5.9 e ntse e hloka ho kenya kernel ka tšehetso ea xen:

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

A re kenyeng Grub:

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

'me u hlahise initrd e ncha:

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

Ho bohlokoa haholo ho totobatsa liparamente tsena tsohle le fstab e ncha, ho seng joalo sistimi e ke ke ea qala.
E latelang, o hloka ho theha faele ea menu.lst bakeng sa 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

Ha re hlophiseng marang-rang le 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

Ka tsela ena, re tla ba le netweke e sebetsang le bokhoni ba ho kena ho mohlala re sebelisa linotlolo. Leha ho le joalo, senotlolo ka bosona se hloka ho fetisetsoa ho mohlala ka tsela e itseng. Sena se ka etsoa ho sebelisoa sengoloa se tla fumana senotlolo le ho se boloka mohlaleng:

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

ec2-get-ssh#! / bin / bash
# chkconfig: 2345 95 20
# lebitso la ts'ebetso: ec2-get-ssh
# tlhaloso: Tšoaea mangolo a bohlokoa a AWS bakeng sa mosebelisi oa EC2

# Laeborari ea mesebetsi ea mohloli
/etc/rc.d/init.d/functions

# Tlhophiso ea marang-rang a mohloli
[ -r /etc/sysconfig/network ] &&. /etc/sysconfig/network

# Nka sebaka sa diphetoho tse latelang tsa tikoloho bakeng sa sistimi ya hao
romela PATH=:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin

# Netefatsa hore marang-rang a hlophisitsoe
haeba [ "${NETWORKING}" = "che"]; ebe
echo "Marang-rang ha a hlophisoa."
tsoa 1
fi

qala() {
haeba [! -d /root/.ssh]; ebe
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Fumana senotlolo sa sechaba ho tsoa ho seva sa metadata u sebelisa HTTP
kobeha -f 169.254.169.254/tsa moraorao/meta-data/linotlolo-tsa sechaba/0/senotlolo-sa-openssh > /tmp/senotlolo-sa-sechaba-sa-ka
haeba [$? -eq 0]; ebe
echo "EC2: Fumana senotlolo sa sechaba ho tsoa ho seva sa metadata u sebelisa HTTP."
katse /tmp/my-public-key >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
rm /tmp/my-public-key
fi
}

Ema() {
pheta-pheto "Ha ho letho leo u ka le etsang mona"
}

qala hape() {
Ema
qale
}

# Bona hore na re ne re bitsoa joang.
nyeoe "$1" ho
qala)
qale
;;
Ema)
Ema
;;
qala hape)
qala hape
;;
*)
echo $"Tšebeliso: $0 {qala|emisa|qala bocha}"
tsoa 1
hore C

tsoa ka $?
A re e etse hore e sebetse 'me re e kenye ho qala:

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

Hape ho eletsoa ho tima Selinux kapa ho e hlophisa ka nepo. Ho seng jwalo, mohlala, senotlolo se kanna sa se bolokwe ho instance.
Nakong ena, re ka emisa ho seta sistimi. Re se re ntse re na le CentOS, e se e loketse ho qala lerung. Se setseng feela ke ho theola drive ea EBS e nang le sistimi ea rona le ho ngolisa AMI.

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

Ngoliso ea AMI

Ho fumana ami ho tsoa ho ebs disk, o hloka ho nka setšoantšo sa disk pele:

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

Tsela e bonolo ka ho fetisisa ea ho ngolisa ami ke ka AWS Management Console. Ho etsa sena, e-ea feela karolong ea "Lifoto" tšebeletsong ea EC2, khetha e lakatsehang (tabeng ea rona, ke centos-snap), tobetsa ka ho le letona ho eona ebe u khetha "Theha Setšoantšo ho tsoa ho Snapshot"
Ebe, fensetereng e bulehang, o hloka ho khetha hoo e ka bang liparamente tse latelang:

Etsa setšoantšo sa hau ka mokhoa o hloekileng CentOS 5.9 ka har'a leru la Amazon

U ka fumana hore na u khetha ID efe ea Kernel ka tsela ena:

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

Ke phetho. Joale o ka qala liketsahalo.
Ka tsela ena o ka etsa setšoantšo, mohlomong ka Linux-kabo. Bonyane, ehlile. Debian- (ho sebedisa debootstrap ho kenya sistimi e hlwekileng) le lelapa la Rhel.

Source: www.habr.com

Reka sebaka se tšepahalang sa libaka tse nang le ts'ireletso ea DDoS, li-server tsa VPS VDS 🔥 Reka sebaka se tšepahalang sa ho amohela webosaete ka tšireletso ea DDoS, li-server tsa VPS VDS | ProHoster