LoginSignup
21
22

More than 5 years have passed since last update.

CentOS 6 系のインストール直後にする作業

Posted at

Qiita への久々の投稿ですが、これも blog からの転載です。

最近は CentOS の導入~初期設定の機会が多いので、 CentOS 6系サーバの導入時に必ず行っている初期環境設定作業をメモしてみます。

インストール作業は CentOS の DVD から起動して行います。
CentOS 6 からはテキストベースのインストーラの場合、パーティションの設定やファイルシステムの指定、 初期インストールされるパッケージの追加・削除などが指定できない様ですので GUI を利用した通常のインストールを実行します。
インストール完了後に再起動したら以下の初期環境設定を行います。

自分のユーザを作製する

通常の作業は root ではなく一般のユーザで行いましょう。

# adduser アカウント
# passwd アカウント

自分のアカウントを wheel グループに追加する

sudo(1) 可能な様に自分のアカウントを wheel グループに追加します。

# (rm /etc/group; sed 's/^wheel.*/&,アカウント/g' > /etc/group) < /etc/group

sudo(1) の設定を変更する

root の権限で作業する場合 su(1) よりも sudo(1) の方がお勧めです。

好みの問題ですが sudo(1) しても元の環境変数を保持する様以下の設定をします。
また、wheel グループに属するメンバーは sudo(1) 可能とします。

Defaults !env_reset に変更
Defaults env_keep += "HOME" を追加
%wheel  ALL=(ALL)   ALL を追加

selinux を無効にする

正しく設定すれば便利だとは思うのですが、未だに使いこなせておらず、トラブルの原因となる事が多いので無効にしています。

# ex -s /etc/syconfig/selinux << EOF
> /^SELINUX=/s/.*/SELINUX=disabled
> wq
> EOF

システム更新

システムを最新の状態に更新します。

# yum update

最低限必要なソフトウェアのインストール

システムを運用する上でこれだけは必要だとうソフトウェアを導入します。

# yum install openssh-clients libtermcap-devel tcpdump
# yum install ntpdate telnet wget tcpdump unzip mlocate rsync bind-utils

開発環境のインストール

ソフトウェアを開発する場合は導入します。
(通常はサーバでは開発しないので導入は不要な筈ですが…)

# yum install make gcc bison flex

sshサーバの設定

パスワード認証、root でのアクセスを拒否するために /etc/ssh/sshd_config に以下の設定を行います。

PasswordAuthentication no に変更
PermitRootLogin no に変更

ファイアウォールの設定

グローバル環境に晒されるサーバであれば 最低限のファイアウォールは設定する必要があります。
基本的には以下のポリシーで必要に応じて追加・削除する様にしています。

#!/bin/sh
iptables=/sbin/iptables

# 全て初期化
${iptables} -F

# デフォルトルール
${iptables} -P INPUT DROP
${iptables} -P OUTPUT ACCEPT
${iptables} -P FORWARD DROP

# ループバックを有効にする 
${iptables} -A INPUT -i lo -p all -j ACCEPT

# 接続済みのパケットを受け付ける
${iptables} -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT

# http, httpsはどこからでもアクセス可
${iptables} -A INPUT -p tcp --dport 80 -j ACCEPT
${iptables} -A INPUT -p tcp --dport 443 -j ACCEPT

# sshはどこからでもアクセス可
${iptables} -A INPUT -p tcp --dport 22 -j ACCEPT

# dns パケットを許可
${iptables} -A INPUT -p tcp --sport 53 -j ACCEPT
${iptables} -A INPUT -p udp --sport 53 -j ACCEPT
${iptables} -A INPUT -p tcp --dport 53 -j ACCEPT
${iptables} -A INPUT -p udp --dport 53 -j ACCEPT

# ntp パケットを許可
${iptables} -A INPUT -p tcp --dport 123 -j ACCEPT
${iptables} -A INPUT -p udp --dport 123 -j ACCEPT

# そのほか必要なルールを記載
        :
        :

上記設定を /tmp/firewall.sh に格納した場合、 ファイアウォールを有効にして設定をセーブする。

# sh /tmp/firewall.sh
# /etc/init.d/iptables save
iptables: ファイアウォールのルールを /etc/sysconfig/iptableに保存中: [  OK  ]

起動サービスの設定

起動サービスを設定する。
基本的には atd crond iptables network ntpd rsyslog sshd のみを有効にしていますが、提供するサービスなど必要に応じて変更します。

# for i in `chkconfig --list | awk '/:on/{ print $1 }'`
> do
>  case $i in
>      atd|crond|iptables|network|ntpd|rsyslog|sshd )
>          ;;
>      * )
>          chkconfig $i off
>          chkconfig --del $i
>          ;;
>  esac
> done

ここまで設定して再起動した後で MTA や httpd など個別のサービスについて設定します。

21
22
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
21
22