自宅サーバー ≫ Linux Server ≫ CentOS 7 ≫ 初期設定

 

PC(ホスト)名の設定

現在のPC(ホスト)名の確認

 
 [root@centos]#
hostname
 
localhost.localdomain   <--- 現在のPC(ホスト)名
 

PC(ホスト)名の設定

 
 [root@centos]#
hostnamectl set-hostname papa-net-server   下線部が新PC(ホスト)名
 

PC(ホスト)名の確認

 
 [root@centos]#
hostname
 
papa-net-server   <--- 新しいPC(ホスト)名
 

詳細なPC(ホスト)情報の確認

 
 [root@centos]#
hostnamectl
   
Static hostname: papa-net-server
          Icon name: computer
            Chassis: n/a
         Machine ID: fa0c51cf40d04eef80b17fdad6563b7b
            Boot ID: c66c8d0b30284d9cb81496d5985a47ed
   Operating System: CentOS Linux 7 (Core)
        CPE OS Name: cpe:/o:centos:centos:7
             Kernel: Linux 3.10.0-862.el7.x86_64
       Architecture: x86_64
 

ネットワークデバイス(カード)の確認

ネットワークデバイス(カード)が正常に認識されているか確認

 
 [root@centos]#
ifconfig -a
 enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        inet 192.168.1.*** netmask 255.255.255.0 broadcast 192.168.1.255
        inet6 2408:11:a908:3700:4216:7eff:fe6e:a40 prefixlen 64 scopeid 0x0<global>
        inet6 fe80::4216:7eff:fe6e:a40 prefixlen 64 scopeid 0x20<link>
        ether 40:16:7e:6e:0a:40 txqueuelen 1000 (Ethernet)
        RX packets 550085 bytes 528287746 (503.8 MiB)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 413525 bytes 96722244 (92.2 MiB)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 
 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
         inet 127.0.0.1 netmask 255.0.0.0
         inet6 ::1 prefixlen 128 scopeid 0x10<host>
         loop txqueuelen 0 (Local Loopback)
         RX packets 6 bytes 560 (560.0 B)
         RX errors 0 dropped 0 overruns 0 frame 0
         TX packets 6 bytes 560 (560.0 B)
         TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 

上記のようにネットワークデバイス(カード)情報が表示されれば正常に認識されている
CentOS7よりネットワークインターフェイスの名称が eth* から enp+++ 変更になった私の場合は enp3s0 となっていた
※OSを最小インストールした場合はネットワーク関連のツールがインストールされていないので上記のコマンドは使えない

NetworkManager に付属する nmcli コマンドを使って確認

 
 [root@centos]#
nmcli device
 DEVICE  TYPE      STATE      CONNECTION
 
enp3s0  ethernet  connected  enp3s0
 lo      loopback  unmanaged  --
 

赤字がネットワークインターフェイスの名称
ネットワーク設定
設定ファイルを開き確認し必要に応じ書き換え

 
 [root@centos]#
vi /etc/sysconfig/network-scripts/ifcfg-enp3s0   (下線部は各自の環境による)
 TYPE=Ethernet
 BOOTPROTO=none
 DEFROUTE=yes
 IPV4_FAILURE_FATAL=no
 IPV6INIT=yes
 IPV6_AUTOCONF=yes
 IPV6_DEFROUTE=yes
 IPV6_FAILURE_FATAL=no
 NAME=enp3s0
 UUID=c6fe0b19-51c1-4695-8552-e8988d588062
 ONBOOT=
yes   <--- 確認し必要に応じ書き換える サーバー起動時にこのデバイスを起動する
 HWADDR=00:13:8F:33:EC:B4-
 PROXY_METHOD=no
 BROWSER_ONLY=no
 IPADDR0=
192.168.1.***   <--- 確認し必要に応じ書き換える サーバーのIPアドレス
 PREFIX0=24
 GATEWAY0=
192.168.1.***   <--- 確認し必要に応じ書き換える ゲートウェイ(ルーター)のアドレス
 HWADDR=00:13:8F:33:EC:B4

 

ネットワークの起動

 
 [root@centos]#
systemctl start network
 

PCの再起動に netwaork の自動的起動設定

 
 [root@centos]# chkconfig network on
 

自動起動設定の確認


 [root@centos]# chkconfig --list network
 
network    0:off   1:off   2:on   3:on   4:on   5:on   6:off   <--- 2・3・4・5 が on になっていればOK
 

再起動

 
 [root@centos]# systemctl restart network
 

サービスの起動・停止
CentOS7より各種サービスの管理が systemd サービスに変更になりました
従来の SysV サービスで管理されているサービスを調べます

 
 [root@centos]#
chkconfig --list
 注記: この出力は SysV サービスのみであり、ネイティブな systemd のサービスは含まれていません。
 systemd services. SysV 設定のデータはネイティブな systemd の設定によって上書きされます。
 systemd サービスを一覧表示するには 'systemctl list-unit-files' を使用してください。
 特定のターゲットにおいて有効化されているサービスを確認するには、
 'systemctl list-dependencies [target]' 。

 iprdump          0:off    1:off    2:on    3:on    4:on    5:on    6:off
 iprinit          0:off    1:off    2:on    3:on    4:on    5:on    6:off
 iprupdate        0:off    1:off    2:on    3:on    4:on    5:on    6:off
 netconsole       0:off    1:off    2:off   3:off   4:off   5:off   6:off
 network          0:off    1:off    2:on    3:on    4:on    5:on    6:off
 

上記で設定したネットワークサービスは従来の SysV サービスで管理されている
続いて systemd サービスで管理されているサービスを調べます

 
 [root@centos]#
systemctl list-unit-files
 abrt-ccpp.service                               enabled
 abrt-oops.service                               enabled
 
途中略
 blk-availability.service                        disabled
 bluetooth.service                               enabled
 
途中略
 canberra-system-bootup.service                  disabled
 canberra-system-shutdown-reboot.service         disabled
 
途中略
 dbus-org.bluez.service                          enabled
 dbus-org.freedesktop.Avahi.service              enabled
 
途中略
 ebtables.service                                disabled
 emergency.service                               static
 
途中略
 fcoe.service                                    disabled
 firewalld.service                               disabled
 
途中略
 gdm.service                                     enabled
 getty@.service                                  enabled
 
途中略
 halt-local.service                              static
 hypervkvpd.service                              enabled
 
途中略
 initial-setup-graphical.service                 disabled
 initial-setup-text.service                      disabled
 
以下略
 

ほとんどのサービスが systemd サービスで管理されています
今後、新たにインストールするサービスについてはその都度確認する必要があります
<各種サービスの起動>
・SysV サービスの起動(従来型)

 
 [root@centos]#
/etc/rc.d/init.d/****** start   (******はサービス名)
 

・systemd サービスの起動

 
 [root@centos]#
systemctl start ******.service   (******はサービス名)
 

<各種サービスの停止>
・SysV サービスの停止(従来型)

 
 [root@centos]#
/etc/rc.d/init.d/****** stop   (******はサービス名)
 

・systemd サービスの停止

 
 [root@centos]#
systemctl stop ******.service   (******はサービス名)
 

<各種サービスの再起動>
・SysV サービスの再起動(従来型)

 
 [root@centos]#
/etc/rc.d/init.d/****** restart   (******はサービス名)
 

・systemd サービスの再起動

 
 [root@centos]#
systemctl restart ******.service   (******はサービス名)
 

<各種サービスの自動起動>
・SysV サービスの自動起動(従来型)

 
 [root@centos]#
chkconfig ****** on   (******はサービス名)
 

・systemd サービスの自動起動

 
 [root@centos]#
systemctl enable ******.service   (******はサービス名)
 

<各種サービスの自動起動解除>
・SysV サービスの自動起動解除(従来型)

 
 [root@centos]#
chkconfig ****** off   (******はサービス名)
 

・systemd サービスの自動起動解除

 
 [root@centos]#
systemctl disable ******.service   (******はサービス名)
 

<各種サービスの自動起動(解除)の確認>
・SysV サービスの自動起動(解除)の確認(従来型)

 
 [root@centos]#
chkconfig --list ******   (******はサービス名)
 ******    0:off   1:off   2:on   3:on   4:on   5:on   6:off
   <--- 2・3・4・5 が on になっていればOK
 

・systemd サービスの自動起動(解除)の確認

 
 [root@centos]#
systemctl list-unit-files | grep ******.service   (******はサービス名) 
 ******.service                    enabled
   <--- enabled(自動起動) disabled(自動起動解除)
 

※ systemd サービスコマンドの最後の .service は省略できる
root宛メール
各種サーバーを運営していると各種情報や案内・エラーメッセージ等が各ソフトから管理者(root)宛にメールで送られて来るが、これらのメールはrootのメールボックスに収められている為いちいち確認しなくてはな らないのでroot宛メールを通常使っているメールアドレスに転送してクライアントのメーラーで確認できるようにする
 
 
[root@centos]# vi /etc/aliases
 
以下最終行に追記
 
root:           ****@xxxx.com
 
****@xxxx.com は通常使っているメールアドレス

転送設定をの反映

 
 
[root@centos]# newaliases
 

起動ランレベルの変更

今までの CentOS では /etc/inittab を書き換える事でで起動レベル(ランレベル)を指定していましたが CentOS7 では直接指定する事で設定します。
          ターゲット名 摘要 ランレベル
          poweroff.target システム停止 0
          rescue.target シングルユーザモード 1
          multi-user.target マルチユーザテキストモード(CUI) 3
          graphical.target マルチユーザグラフィカルモード(GUI) 5
          reboot.target 再起動 6
          emergency.target 緊急シェル -
現在の起動レベル(ランレベル)を確認

 
 [root@centos]#
systemctl get-default
 graphical.target   <--- マルチユーザグラフィカルモード(GUI )
 

起動レベル(ランレベル)をマルチユーザテキストモード(CUI)に変更

 
 [root@centos]#
systemctl set-default multi-user.target
 rm '/etc/systemd/system/default.target'
 ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'
 

X (GUI) の起動&終了

上記の設定では起動時の設定をしたが、ここではテキストモード(CUI)で起動後グラフィカルなGUIに変更する方法

 
 [root@centos]#
startx
 

元のテキストモード(CUI)に戻す場合は Ctrl + Alt + F1

wget のインストール

centos のソフトは基本的には yum コマンドでインストールできるが、centos のライブラリーに無いソフトをインストールするために各種ソフトをダウンロードする場合に wget コマンドを使用

wget のインストール

 
 [root@centos]# yum -y install wget
 

開発環境
CentOS でサーバーを構築する場合には開発環境は必要ないが、色々なソフトをインストールし、確認等する時に必要になる場合もある

そこで、開発環境をインストール

 
 [root@centos]# yum -y groupinstall "Development Tools"
 

X Window System

CentOS でサーバーを構築する場合にはX Window System 環境は必要ないが、テキストモードではなくグラフィカルモードで運用したい場合はX Window System をインストール

 
 [root@centos]# yum -y groupinstall "X Window System"
 

GNOME デスクトップ環境
“X Window System” を丸々インストールしなくても GNOME デスクトップ環境だけをインストールする事もできる

 
 [root@centos]# yum -y groupinstall "GNOME Desktop"
 

日本語環境
X Window System、GNOME デスクトップ環境をインストールすると、日本語環境も必要になってくるので日本語関連のパッケージをインストール

 
 [root@centos]# yum -y install ibus-kkc vlgothic-*
 

システムの文字コードを変更

 
 [root@centos]# echo $LANG
 ja_JP.UTF-8   <--- ja_JP.UTF-8 と表示されればOK  なっていなければ下記を実行
 [root@centos]# localectl set-locale LANG=ja_JP.UTF-8   <--- 入力
 [root@centos]# source /etc/locale.conf   <--- 入力(変更の反映)
 [root@centos]# echo $LANG   <--- 入力(確認)
 ja_JP.UTF-8   <--- ja_JP.UTF-8 と表示されればOK
 

ログアウト&再起動&終了

ログアウト&再起動&終了する場合

 
 [root@centos]#
logout   <--- ログアウト
 [root@centos]#
reboot   <--- 再起動
 [root@centos]#
halt     <--- 終了
 

戻る