LoginSignup
47
46

More than 5 years have passed since last update.

CentOS 6.5 初期設定

Last updated at Posted at 2014-04-21

前置き

CentOS 6.5 インストール手順 - Qiita
上記、インストールと再起動が完了しているとする。

CentOSインストール後、何を置いてもやっておくべきことを記す。
何かしらサーバーとして動作させるにしても、これらをやっておかなければならない、ということの一覧である。
インストール完了後、rootにてログインしているものとする。
また、ネットワークは

名称 アドレス
ネットワークアドレス 192.168.0.0
サブネットマスク 255.255.255.0(/24)
ゲートウェイアドレス 192.168.0.1
IPアドレス 192.168.0.10
ブロードキャストアドレス 192.168.0.255
DNSサーバー1 192.168.0.1
DNSサーバー2 8.8.8.8

という環境にあるものとする。

ネットワーク設定

/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=xx:xx:xx:xx:xx:xx
TYPE=Ethernet
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ONBOOT=yes
BOOTPROTO=static
NETWORK=192.168.0.0
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
IPADDR=192,168.0.10
BROADCAST=192.168.0.255
/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=example.com

# 169.254.0.0/16のネットワーク経路を作らせない
NOZEROCONF=yes
/etc/resolv.conf
nameserver 192.168.0.1
nameserver 8.8.8.8
/etc/init.d/network restart

chkconfig設定

for app in auditd netfs udev-post;
do
    chkconfig $app off;
done
サービス名 内容
auditd 監査メッセージをログファイルに出力する
netfs NFSクライアント
udev-post 新しいハードウェアの検出

GRUB設定

/etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda2
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
#splashimage=(hd0,0)/grub/splash.xpm.gz
#hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxrd_NO_LUKS rd_NO_MD crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=jp106 LANG=ja_JP.UTF-8 rd_NO_LVM rd_NO_DM audit=0
        initrd /initramfs-2.6.32-431.el6.x86_64.img
オプション名 説明 指定例
timeout 起動メニュー画面の停止時間(秒) デフォルトのまま 5 にしておく
splashimage 起動メニュー画面の背景画像の指定 不要なので行頭に # をつけてコメントアウト
hiddenmenu 起動メニュー画面を表示しない メニューを表示させたいので行頭に # をつけてコメントアウト
kernel行 オプション名 説明 指定例
rhgb グラフィカルな起動画面にする 不要なので削除する
quiet 起動時にログを画面に表示しない ログを表示させたいので削除する
audit カーネルベースで監査ログを取るかどうか 完全に取りたくないので audit=0 を追記する

SELinux設定

/etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
オプション名 説明 指定例
SELINUX SELinuxを有効にするかどうか 無効にしたいので disabled とする

画面が消灯するのを防ぐ

echo "/usr/bin/setterm -blank 0" >> /etc/rc.local

Perlのエイリアスを作る

ln -s /usr/bin/perl /usr/local/bin/.

Yum Repository設定

centospluscontrib を有効にする
またパッケージ取得先を国内( 理研 )へ変更する

/etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/centosplus/$basearch/
gpgcheck=1
#enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
baseurl=http://ftp.riken.jp/Linux/centos/$releasever/contrib/$basearch/
gpgcheck=1
#enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

phpは ZendServer を使用する(2014/04/17 時点で最新のもの)

/etc/yum.repos.d/Zend.6.3.repo
[Zend]
name=zend-server
baseurl=http://repos.zend.com/zend-server/6.3/rpm/$basearch
enabled=1
gpgcheck=1
gpgkey=http://repos.zend.com/zend.key

[Zend_noarch]
name=zend-server - noarch
baseurl=http://repos.zend.com/zend-server/6.3/rpm/noarch
enabled=1
gpgcheck=1
gpgkey=http://repos.zend.com/zend.key

データベースは MariaDB を使用する(2014/04/17 時点で最新のもの)

/etc/yum.repos.d/mariadb.10.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

必須パッケージのインストール

yum -y install man wget lftp vim-enhanced dos2unix screen bind-utils hdparm lsof jwhois ppp nkf expect pwgen
パッケージ名 説明
man コマンドのヘルプを見る際に必要
wget リモートサーバーからファイルをダウンロードする
lftp FTPコマンドの上位版
vim-enhanced vimをより使いやすくする
dos2unix Windowsで作成されたファイルをLinux用に変換する
screen ターミナルで仮想端末を作成することができる
bind-utils digなどのドメインとIPアドレスの調査コマンド
hdparm HDDの情報を取得する
lsof 開いているファイルのプロセスを特定する
jwhois whoisコマンド
ppp PPPoE接続をする際に必要
nkf 日本語ファイルの文字コード・改行コードの変換
expect 対話式処理を自動化する
pwgen ランダムパスワードを発行する

bash設定

/etc/bashrc に以下を追記する

/etc/bashrc
case ${UID} in
    0)
        PS1='\[\e[1;35m\]\H\[\e[0m\] \[\e[4;31m\]\[\e[1;31m\]${PWD}\[\e[0m\]\[\e[1;31m\]\$\[\e[0m\] '
        PS2='\[\e[1;31m\]>\[\e[0m\] '
        ;;
    *)
        PS1='\[\e[0;35m\]\H\[\e[0m\] \[\e[4;34m\]${PWD}\[\e[0m\]\[\e[0;34m\]\$\[\e[0m\] '
        PS2='\[\e[0;34m\]>\[\e[0m\] '
        ;;
esac

HISTTIMEFORMAT='%Y-%m-%d %T '
export HISTTIMEFORMAT

alias ls='ls --color=tty -F'
alias ll='ls --color=tty -Flh'
alias la='ls --color=tty -FlhA'
alias mv='mv -i'
alias cp='cp -i'
alias rm='rm -i'
alias vi='/usr/bin/vim'

vim設定

/etc/vimrc に以下を追記する

/etc/vimrc
" 文字コードの自動認識
if &encoding !=# 'utf-8'
  set encoding=japan
  set fileencoding=japan
endif
if has('iconv')
  let s:enc_euc = 'euc-jp'
  let s:enc_jis = 'iso-2022-jp'
  " iconvがeucJP-msに対応しているかをチェック
  if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb"
    let s:enc_euc = 'eucjp-ms'
    let s:enc_jis = 'iso-2022-jp-3'
  " iconvがJISX0213に対応しているかをチェック
  elseif iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb"
    let s:enc_euc = 'euc-jisx0213'
    let s:enc_jis = 'iso-2022-jp-3'
  endif
  " fileencodingsを構築
  if &encoding ==# 'utf-8'
    let s:fileencodings_default = &fileencodings
    let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
    let &fileencodings = &fileencodings .','. s:fileencodings_default
    unlet s:fileencodings_default
  else
    let &fileencodings = &fileencodings .','. s:enc_jis
    set fileencodings+=utf-8,ucs-2le,ucs-2
    if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$'
      set fileencodings+=cp932
      set fileencodings-=euc-jp
      set fileencodings-=euc-jisx0213
      set fileencodings-=eucjp-ms
      let &encoding = s:enc_euc
      let &fileencoding = s:enc_euc
    else
      let &fileencodings = &fileencodings .','. s:enc_euc
    endif
  endif
  " 定数を処分
  unlet s:enc_euc
  unlet s:enc_jis
endif
" 日本語を含まない場合は fileencoding に encoding を使うようにする
if has('autocmd')
  function! AU_ReCheck_FENC()
"    if &fileencoding =~# 'iso-2022-jp' && search("[^\x01-\x7e]", 'n') == 0
      let &fileencoding=&encoding
"    endif
  endfunction
  autocmd BufReadPost * call AU_ReCheck_FENC()
endif
" 改行コードの自動認識
set fileformats=unix,dos,mac
" □とか○の文字があってもカーソル位置がずれないようにする
if exists('&ambiwidth')
  set ambiwidth=double
endif

" auto indent を有効にする
set autoindent

" 行番号を表示する
set number

" インクリメンタルサーチを有効にする
set incsearch

" 検索時に大文字小文字を無視する
set ignorecase

" 検索時にハイライトを無効にする
set nohlsearch

" 対になる括弧を表示する
set showmatch

" モードを表示する
set showmode

" 上の行の末尾の文字を 1 文字消去する
set backspace=2

" 編集中のファイル名を表示する
set title

" ルーラーを表示する
set ruler

" タブをスペース 4 つ分にする
set tabstop=4

" シフト移動幅を 4 にする
set shiftwidth=4

" タブの代わりに空白文字を挿入する
set expandtab

" Shift+矢印キーで選択できるようにする
set keymodel=startsel

" 高度な自動インデントを行う
set smartindent

" 見た目の tabstop を変える
set softtabstop=4

全システムのアップデート

yum clean all
yum -y update

再起動

上記、全て終われば再起動しておく

reboot

再起動後、また root でログインしておく

NTPインストール・設定

yum -y install ntp
cp -a /etc/ntp.conf /etc/ntp.conf.org
cp -a /etc/ntp/step-tickers /etc/ntp/step-tickers.org
cp -a /etc/sysconfig/ntpdate /etc/sysconfig/ntpdate.org
/etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1 
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server -4 ntp.nict.jp burst iburst maxpoll 8 iburst
server -4 ntp.nict.jp burst iburst maxpoll 8 iburst
server -4 ntp.nict.jp burst iburst maxpoll 8 iburst

#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 autokey            # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

NTPサーバー起動時に時刻同期実行するサーバーを設定する

/etc/ntp/step-tickers
# List of servers used for initial synchronization.
ntp.nict.jp

時刻をハードウェア時刻に反映させる。

/etc/sysconfig/ntpdate
# Options for ntpdate
OPTIONS="-U ntp -s -b"

# Number of retries before giving up
RETRIES=2

# Set to 'yes' to sync hw clock after successful ntpdate
SYNC_HWCLOCK=yes

ntp.nict.jp のIPアドレスを先に取得させ ntpdatentpd サービスを開始する。

dig ntp.nict.jp
ntpdate ntp.nict.jp && /etc/init.d/ntpdate start && /etc/init.d/ntpd start

ntpdatentpd を自動起動にする

chkconfig ntpdate on
chkconfig ntpd on
47
46
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
47
46