5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

"さくらのVPS" でサーバ構築をする時に最初にする事 - CentOS 6.5 -

Last updated at Posted at 2015-08-11

「さくらのVPS」を使用して廃棄前提のサーバを構築する時に、最初に行う設定であったり、コマンドであったりを、備忘録として記載する。

構築環境

さくらのVPS
- CentOS release 6.7 (Final)

はじめに

環境変数の設定でコマンドプロンプトに時刻を表示

~/.bash_profile の編集

# vim /root/.bash_profile

環境変数 PS1 を設定。

/root/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
PS1="\t[\u@\h \W]\$ "

export PATH

rootユーザ

PS1="\t[\u@\h \W]# "

一般ユーザ

PS1="\t[\u@\h \W]\$ "

.bash_profile を再読み込み。

# source /root/.bash_profile

Learn More
->.bash_profileで環境変数を設定する。 - Linuxユーザのためのチップス

構築手順

  1. 一般ユーザ "sample" の追加
  2. 一般ユーザ "sample" のパスワードを設定
  3. rootに昇格出来るユーザを限定する
  4. インストール済パッケージの一括アップデート
  5. ベースパッケージ群、開発ツールパッケージ群インストール
  6. SELinuxの無効化
  7. NKFコマンドのインストール
  8. 日本語化の対応

一般ユーザ "sample" の追加

# useradd sample
#

参考1:Linux 新規ユーザの作成 - useradd - kazmax

一般ユーザ "sample" のパスワードを設定

# passwd sample
Changing password for user sample.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
#

参考2:【 passwd 】 ユーザーのパスワードを変更する - ITPro

rootに昇格出来るユーザを限定する

一般ユーザ "sample" を wheelグループに追加する

# usermod -G wheel sample
#

参考3:Linux ユーザ情報の変更 - usermod - kazmax
参考4:いますぐ実践! Linux システム管理 / Vol.104
参考5:[Linux] なぜ sudo する権限のあるグループが「 wheel 」という名前なのか - Codaholic
参考6:ユーザーをwheelグループに追加 [サーバ立ち上げ準備] - ど素人のCentOSびぼーろく

rootになれるユーザを管理者のみにする。( vi にて編集)

# vi /etc/pam.d/su

コメントアウトを外す。
#auth required pam_wheel.so use_uid
 ↓↓↓↓
auth required pam_wheel.so use_uid

修正例。(デフォルトの設定から、コメントアウトを外したもの。)

/etc/pam.d/su
#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth            required        pam_wheel.so use_uid
auth            include         system-auth
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         optional        pam_xauth.so

参考7:インストール直後に絶対やるべき作業と設定 (3/3) - @IT

必要に応じて以下も実行する。

リモートからLinuxマシンのメンテナンスを行うときは、ssh以外使わないようにします。しかし、sshのデフォルト設定はrootアカウントでのログインを許可してしまいます。そこで、rootアカウントでは直接ログインできないようにsshの設定ファイルを変更します。こうすることで、sshによる認証とsuコマンドによる認証の2段階を経なければrootになれないようになり、セキュリティを強化できます。
インストール直後に絶対やるべき作業と設定 (3/3) - @IT

インストール済みパッケージの一括アップデート

# yum -y update

参考8:Yellowdog Updater Modified - Wikipedia
参考9:【 yum 】 パッケージを取得してインストール/アップデートをする - ITPro
参考10:初心者の頃に知っておきたかった rpm と yum の違いと使い分け - 彼女からは、おいちゃんと呼ばれています

ベースパッケージ群、開発ツールパッケージ群インストール

# yum -y groupinstall "Base" "Development tools"

参考11:yum パッケージグループ一覧 - 名もないサイト

SELinuxの無効化

# getenforce
Disabled

(さくらのVPSのCentOS 6.5 はデフォルトで "Disabled"になっている)

参考12:SELinux - Wikipedia
参考13:SELinuxを無効化する - Smart

NKFコマンドのインストール

# yum -y install nkf

参考14:【 nkf 】 文字コードを変換する - ITPro
参考15:文字コード変換コマンドの nkfの使い方と実例をまとめました。 - それマグで!

日本語化の対応

# vi /etc/sysconfig/i18n

デフォルトでは、"C"が設定されている。
LANG="C"

その為、下記のように書き換える。

/etc/sysconfig/i18n
LANG="ja_JP.UTF-8"
SYSFONT="latarcyrheb-sun16"

書き換えたら下記のコマンドを実行する。
# source /etc/sysconfig/i18n

試しに $LANG を出力して、変更が反映されている事を確認する。

# echo $LANG
ja_JP.UTF-8

参考16:日本語環境にする - Server World

こんな感じ

本格的な運用を考えるなら iptables ほか、必要な設定は多々ありますが、動作確認や構築練習だけすぐに畳む予定であれば、この程度で大丈夫かなぁ。

参考

5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?