LoginSignup
1
0

More than 1 year has passed since last update.

EC2 サーバー構築(基本設定)

Last updated at Posted at 2021-02-25

EC2 サーバー構築

概要

EC2インスタンスを初期に立ち上げた際にすることをまとめてみました。
過不足あれば今後編集していきたいと思います。

環境

  • Amazon Linux2

システム設定

yumのパッケージ更新

sudo yum -y update

タイムゾーン・ロケール設定

タイムゾーン確認

timedatectl status

タイムゾーンを日本時間に設定

sudo timedatectl set-timezone Asia/Tokyo

ロケール確認

localectl status

ロケール変更

sudo localectl set-locale LANG=ja_JP.UTF-8

ニックネーム設定

ホスト名に影響を与えずにシェルプロンプトを変更する
参考

1. 環境変数定義

sudo sh -c 'echo "export NICKNAME={ニックネーム}" > /etc/profile.d/prompt.sh'
sudo sh -c 'echo "export NICKNAME=app01" > /etc/profile.d/prompt.sh'

2. シェルプロンプトの設定編集

sudo vi /etc/bashrc

\h (hostname を表す記号) を NICKNAME 変数の値に変更

/etc/bashrc
 [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\$NICKNAME \W]\\$ "

3. シェルウィンドウのタイトルを新しいニックネームに設定

# ファイル作成
sudo touch /etc/sysconfig/bash-prompt-xterm

#  実行権限付与
sudo chmod +x /etc/sysconfig/bash-prompt-xterm

# ファイル編集
sudo vi /etc/sysconfig/bash-prompt-xterm
/etc/sysconfig/bash-prompt-xterm
echo -ne "\033]0;${USER}@${NICKNAME}:${PWD/#$HOME/~}\007"

4. 確認

一度SSH接続を切って、再度SSH接続してみてください。
コンソールが指定したものに変わっていればOKです。

[ec2-user@app01 ~]$
1
0
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
1
0