LoginSignup
0
2

More than 5 years have passed since last update.

EC2起動前自動化処理

Last updated at Posted at 2018-09-19

お決まりの内容だけど、EC2インスタンスを立ち上げる時の初期設定を毎回するのめんどくさいのでユーザーデータから自動化しておこうという内容。

指定箇所

インスタンス作成画面から「3.インスタンスの設定」で高度な詳細を開いた場所

ユーザーデータの内容

・AmazonLinux/Centos6の場合

#!/bin/bash

# ホスト名
sed -i 's/^HOSTNAME=[a-zA-Z0-9\.\-]*$/HOSTNAME=hostname-hogehoge/g' /etc/sysconfig/network
hostname 'hostname-hogehoge'

# タイムゾーン
cp /usr/share/zoneinfo/Japan /etc/localtime
sed -i 's|^ZONE=[a-zA-Z0-9\.\-\"]*$|ZONE="Asia/Tokyo”|g' /etc/sysconfig/clock

# 言語設定
echo "LANG=ja_JP.UTF-8" > /etc/sysconfig/i18n

# yum update
yum update -y

・AmazonLinux2/CentOS7の場合

#!/bin/bash

# ホスト名
hostnamectl set-hostname hostname-hogehoge

# タイムゾーン
timedatectl set-timezone Asia/Tokyo

# yum update
yum update -y

まとめ

簡単ですね。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2