Skip to content

Instantly share code, notes, and snippets.

@dseg
Last active January 12, 2018 13:04
Show Gist options
  • Save dseg/1529f2804bb04ebdf7c8 to your computer and use it in GitHub Desktop.
Save dseg/1529f2804bb04ebdf7c8 to your computer and use it in GitHub Desktop.
クラウド環境でArchLinuxを使う (Vultr編) ref: https://qiita.com/dseg/items/b4ad1c076dc585cb4432
Description='A basic static ethernet connection'
Interface=ens3
Connection=ethernet
IP=static
Address=('111.112.113.114/255.255.254.0')
Gateway='111.112.113.1'
DNS=('108.61.10.10')
## For IPv6 autoconfiguration
#IP6=stateless
## For IPv6 static address configuration
#IP6=static
#Address6=('1234:5678:9abc:def::1/64' '1234:3456::123/96')
#Routes6=('abcd::1234')
#Gateway6='1234:0:123::abcd'
nirvana% vultr plans|sort -n
VPSPLANID NAME VCPU RAM DISK BANDWIDTH PRICE
29 768 MB RAM,15 GB SSD,1.00 TB BW 1 768 15 1.00 5.00
87 512 MB RAM,125 GB SATA,1.00 TB BW 1 512 125 1.00 5.00
88 1024 MB RAM,250 GB SATA,2.00 TB BW 1 1024 250 2.00 10.00
89 2048 MB RAM,500 GB SATA,3.00 TB BW 1 2048 500 3.00 20.00
90 3072 MB RAM,750 GB SATA,4.00 TB BW 2 3072 750 4.00 30.00
91 4096 MB RAM,1000 GB SATA,5.00 TB BW 2 4096 1000 5.00 40.00
93 1024 MB RAM,20 GB SSD,2.00 TB BW 1 1024 20 2.00 10.00
94 2048 MB RAM,45 GB SSD,3.00 TB BW 2 2048 45 3.00 20.00
95 4096 MB RAM,90 GB SSD,4.00 TB BW 4 4096 90 4.00 40.00
96 8192 MB RAM,150 GB SSD,5.00 TB BW 6 8192 150 5.00 80.00
97 16384 MB RAM,300 GB SSD,6.00 TB BW 8 16384 300 6.00 160.00
98 32768 MB RAM,600 GB SSD,10.00 TB BW 16 32768 600 10.00 320.00
100 65536 MB RAM,700 GB SSD,15.00 TB BW 24 65536 700 15.00 640.00
115 8192 MB RAM,110 GB SSD,10.00 TB BW 2 8192 110 10.00 60.00
116 16384 MB RAM,110 GB SSD,20.00 TB BW 4 16384 110 20.00 120.00
117 24576 MB RAM,110 GB SSD,30.00 TB BW 6 24576 110 30.00 180.00
118 32768 MB RAM,110 GB SSD,40.00 TB BW 8 32768 110 40.00 240.00
http://mirror.rackspace.com/archlinux/iso/2016.01.01/archlinux-2016.01.01-dual.iso
mount /dev/vda3 /mnt
mkdir /mnt/{boot,etc}
mount /dev/vda1 /mnt/boot
# Generate the /etc/fstab
genfstab -p /mnt > /mnt/etc/fstab
cat -n /mnt/etc/fstab
1 # UUID=0511c0d9-2e1a-47ea-bdaf-2ac0dd0f771b
2 /dev/vda3 / ext4 rw,relatime,data=ordered 0 1
3
4 # UUID=51b42fd0-e7d6-4795-b11c-cbf950cae57a
5 /dev/vda1 /boot ext4 rw,relatime,data=ordered 0 2
6
7 # UUID=d659fbc3-66e0-4a9c-b0c2-fb2134fdb477
8 /dev/vda2 none swap defaults 0 0
9
# Find the nearest mirror automatically
mkdir /mnt/etc/pacman.d
cat <<'MIRRORS' >/mnt/etc/pacman.d/mirrorlist
Server = http://ftp.tsukuba.wide.ad.jp/Linux/archlinux/$repo/os/$arch
Server = http://ftp.jaist.ac.jp/pub/Linux/ArchLinux/$repo/os/$arch
MIRRORS
# 自動で生成しても良いけど10分前後時間が掛かる
# rankmirrors -n 3 /run/archiso/sfs/airootfs/etc/pacman.d/mirrorlist >/mnt/etc/pacman.d/mirrorlist
# サーバ用途なので、頻繁に更新されるlinuxパッケージではなく、より更新が少ないlinux-ltsを入れます
pacstrap /mnt base sudo shadow openssh linux-lts
arch-chroot /mnt bash
# locale設定
echo en_US.UTF-8 UTF-8 >/etc/locale.gen
#echo ja_JP.UTF-8 UTF-8 >/etc/locale.gen
locale-gen
#Generating locales...
# en_US.UTF-8... done
#Generation complete.
# 言語設定
echo "LANG=en_US.UTF-8" > /etc/locale.conf
echo vultr-server-01 > /etc/hostname
ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 56:00:01:55:66:65 brd ff:ff:ff:ff:ff:ff
$ ping -w 3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=9.49 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=9.68 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=9.51 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 9.490/9.563/9.682/0.116 ms
$ nslookup gnu.org
Server: 108.61.10.10
Address: 108.61.10.10#53
Non-authoritative answer:
Name: gnu.org
Address: 208.118.235.148
cd /etc/netctl
cp examples/ethernet-static ens3
nano ens3
netctl enable ens3
# ln -s '/etc/systemd/system/netctl@ens3.service' '/etc/systemd/system/multi-user.target.wants/netctl@ens3.service'
netctl enable ens3
# ln -s '/etc/systemd/system/netctl@ens3.service' '/etc/systemd/system/multi-user.target.wants/netctl@ens3.service'
cat <<TIME >>/etc/systemd/timesyncd.conf
NTP=asia.pool.ntp.org
FallbackNTP=0.arch.pool.ntp.org 1.arch.pool.ntp.org 2.arch.pool.ntp.org 3.arch.pool.ntp.org
TIME
timedatectl set-ntp true
timedatectl status|grep NTP
# NTP synchronized: yes
echo '%wheel ALL=(ALL) ALL' >> /etc/sudoers
# Setting up the boot loader
pacman -S grub --noconfirm
grub-install --recheck --target=i386-pc /dev/vda
grub-mkconfig -o /boot/grub/grub.cfg
# 結果
# Generating grub configuration file ...
# Found linux image: /boot/vmlinuz-linux-lts
# Found initrd image: /boot/initramfs-linux-lts.img
# Found fallback initramfs image: /boot/initramfs-linux-lts-fallback.img
useradd -m -g users -G wheel user01
# 初期パスワード追加
echo user01:password | chpasswd
curl -s https://github.com/<<ユーザー名>>.keys
# 例:
curl -s https://github.com/dseg.keys
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIAnJSEJG1MVYf2BrRSAWw+DhDvswo3Bv1g3MO+dCBoI
su - user01
[ -d ~/.ssh ] || mkdir ~/.ssh
curl -s https://github.com/<<ユーザー名>>.keys >> ~/.ssh/authorized_keys
sudo -i
F=/etc/ssh/sshd_config
# コメント行のPasswordAuthentication...は無視する
if [[ `grep -P '^(?<!#)PasswordAuthentication yes' "$F"` ]]; then
sed -ie 's/^PasswordAuthentication yes/PasswordAuthentication no/g' "$F"
fi
echo root:root1234567890 | chpasswd
sudo -i
F=/etc/ssh/sshd_config
# コメント行のPasswordAuthentication...は無視する
if [[ `grep -P '^(?<!#)PasswordAuthentication yes' "$F"` ]]; then
sed -ie 's/^PasswordAuthentication yes/PasswordAuthentication no/g' "$F"
fi
systemctl enable sshd
exit
# Unmound drives
umount /mnt/{boot,}
reboot
ssh user01@IPアドレス -i 秘密鍵ファイル
$ free -h
total used free shared buff/cache available
Mem: 745M 20M 666M 296K 58M 705M
Swap: 2.0G 0B 2.0G
sudo pacman -S base-devel
# /etc/pacman.conf の 末尾に追記
cat <<EOL | sudo tee -a /etc/pacman.conf
[archlinuxfr]
SigLevel = PackageOptional
Server = http://repo.archlinux.fr/\$arch
EOL
sudo pacman --sync --refresh --noconfirm yaourt
yaourt -S --noconfirm nkf
# 不要パッケージ削除
sudo pacman -R linux --noconfirm
# pacmanのキャッシュ削除
sudo pacman -Sc --noconfirm
systemctl start sshd
sudo vi /etc/netctl/ens3
# AddressとGatewayの値を更新
ssh root@サーバのIPアドレス
parted /dev/vda --script mklabel msdos
# Make partitions
parted /dev/vda --align optimal\
--script\
mkpart primary ext4 2048s 128MB\
unit MB\
mkpart primary linux-swap 128MB 2GB\
unit GB\
mkpart primary 2GB 100%\
set 1 boot on\
align-check opt 1 align-check opt 3
parted /dev/vda p
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 16.1GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 128MB 127MB primary ext4 boot
2 128MB 2000MB 1872MB primary linux-swap(v1)
3 2000MB 16.1GB 14.1GB primary ext4
# Format the partitions and mount it
mkswap /dev/vda2
swapon /dev/vda2
mkfs.ext4 /dev/vda1
mkfs.ext4 /dev/vda3
PasswordAuthentication no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment