10. 1010
✓ 事前作業として以下の2つが必要となります
さ く ら の ク ラ ウ ド D N S に ゾ ー ン の 登 録 と 委譲をし て い る こ と
さ く ら の ク ラ ウ ド A P I の ア ク セ ス ト ー ク ン を 取 得 し て い る こ と
✓ 詳しくは下記を参照
さくらのナレッジ: ゼ ロ か ら 始 め る マ ス ト ド ン
さ く ら の ク ラ ウ ド ニ ュ ー ス : M a s t o d o n , D N S ア プ ラ イ ア ン ス
スタートアップスクリプトで
Mastodonインスタンスを⽴ててみる
スクリプトの処理と補⾜
11. 1111
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
12. 1212
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
エラーでセットアップが
⽌まる可能性のある場所
エラーでセットアップが
⽌まる可能性のある場所
エラーでセットアップが
⽌まる可能性のある場所
13. 1313
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
# ログのリンクを作成
ln -s $(find /root/.sacloud-api/notes/*log) /tmp/startup_script.log
# リポジトリの設定
yum install -y yum-utils
yum-config-manager --enable epel
yum install -y http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
curl -sL https://rpm.nodesource.com/setup_6.x | bash -
# パッケージのアップデートとインストール
yum update –y
yum install -y ImageMagick ffmpeg redis rubygem-redis postgresql-{server,devel,contrib} authd nodejs
{openssl,readline,zlib,libxml2,libxslt,protobuf,ffmpeg}-devel protobuf-compiler nginx jq bind-utils
npm install -g yarn
スクリプトの進捗確認⽅法
tail –f /tmp/startup_script.log
14. 1414
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
# DNS登録
if [ $(dig ${DOMAIN} ns +short | egrep -c '^ns[0-9]+.gslb[0-9]+.sakura.ne.jp.$') -ne 2 ]
Then
echo "お客様ドメインのNSレコードにさくらのクラウドDNSが設定されておりません”
exit 1
Fi
ZONE=$(jq -r ".Zone.Name" /root/.sacloud-api/server.json)
BASE=https://secure.sakura.ad.jp/cloud/zone/${ZONE}/api/cloud/1.1
API=${BASE}/commonserviceitem/
RESJS=resource.json
…
…(省略
15. 1515
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
# postgresql, redis
export PGSETUP_INITDB_OPTIONS="--encoding=UTF-8 --no-locale”
postgresql-setup initdb
sed -i "s/ident/trust/" /var/lib/pgsql/data/pg_hba.conf
systemctl enable postgresql redis
systemctl start postgresql redis
su - postgres -c "createuser --createdb mastodon".
16. 1616
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
Mastodon公式ドキュメントを参考にインストールをしている
公式ドキュメントとの主な違い
mastodon のバージョンは tag がついた最新版(rcは除く)
nginx は https のみ設定し http から https へのリダイレクトの設定はしていない
smtpサーバは localhost の 25 を設定している
17. 1717
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
# postfix
cat <<_EOL_>> /etc/postfix/main.cf
myhostname = ${DOMAIN}
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_tls_security_level = maysmtp_tls_loglevel = 1
smtpd_client_connection_count_limit = 5
smtpd_client_message_rate_limit = 5
smtpd_client_recipient_rate_limit = 5
disable_vrfy_command = yes
smtpd_discard_ehlo_keywords = dsn,
enhancedstatuscodes, etrn
_EOL_
sed -i -e 's/^inet_interfaces.*/inet_interfaces = all/' -e
's/^inet_protocols = all/inet_protocols = ipv4/'
/etc/postfix/main.cf
systemctl restart postfix
mastodon@ドメイン宛に届いた
メールの確認⽅法
yum install –y mailx
su – mstodon –c “mail”
18. 1818
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
# firewall
firewall-cmd --permanent --add-port=25/tcp --add-port=443/tcp
firewall-cmd --reload
19. 1919
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
# Lets Encrypt
cd /usr/local
git clone https://github.com/certbot/certbot
export PATH=/usr/local/certbot:${PATH}
CERT=/etc/letsencrypt/live/${DOMAIN}/fullchain.pem
CA="certbot-auto -n certonly --standalone -d ${DOMAIN}
-m ${MADDR} --agree-tos"${CA}
for x in $(seq 1 5)
do
if [ ! -f ${CERT} ]
then
${CA}
sleep 300
else
continue
fi
done
…(省略
20. 2020
1 . 追 加 リ ポ ジ ト リ の 設 定 、 パ ッ ケ ー ジ の ア ッ プ デ ー ト と イ ン ス ト ー ル
2 . D N S の 登 録 ( さ く ら の ク ラ ウ ド D N S : A , M X , T X T )
3 . p o s t g r e s q l , r e d i s の 起 動
4 . r u b y 2 . 4 . 1 の イ ン ス ト ー ル
5 . m a s t o d o n の イ ン ス ト ー ル 、 設 定 と 起 動
6 . n g i n x の 設 定
7 . p o s t f i x の 設 定 と 再 起 動
8 . f i r e w a l l の 設 定 と r e l o a d
9 . L e t s E n c r y p t で 証 明 書 取 得
1 0 . n g i n x の 起 動
1 1 . D N S の 登 録 ( P T R )
スタートアップスクリプトの処理
スクリプトの処理と補⾜
# PTR 登録
API=${BASE}/ipaddress/${IPADDR}
cd /root/.sacloud-api/notesPTRJS=ptr.json
cat <<_EOL_> ${PTRJS}
{ "IPAddress": { "HostName": "${DOMAIN}" }}
_EOL_
set -x
curl -s --user "${KEY}" -X PUT -d "$(cat ${PTRJS} | jq -c .)" ${API} |jq ".”
BLANK=$(curl -s --user "${KEY}" -X GET ${API} | jq -r "select(.IPAddress.HostName == ¥"${DOMAIN}¥") | .is_ok")
set –x
…(省略