サーバエンジニアの構築めも

Linux関連を中心としたサーバの構築記録

[CentOS 7] IPv6の無効化

CentOS7ではIPv6の無効化は推奨されていないようだが、以下の手順でIPv6を無効化することができる。

/etc/sysctl.confに以下の設定を記載する。

# echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf

再起動

# reboot

確認

# sysctl -a | grep net.ipv6.conf.*disable_ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.ens32.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:a8:74:93 brd ff:ff:ff:ff:ff:ff
    inet 192.168.40.102/24 brd 192.168.40.255 scope global ens32
       valid_lft forever preferred_lft forever

[CentOS 7] SSHサーバの設定

sshdの起動設定、サービスの稼働状況の確認

# systemctl status sshd.service
sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
   Active: active (running) since Tue 2015-12-15 14:54:24 JST; 3 weeks 0 days ago
 Main PID: 1172 (sshd)
   CGroup: /system.slice/sshd.service

設定変更

# vi /etc/ssh/sshd_config
以下の行を変更
PermitRootLogin no
PermitEmptyPasswords no

sshd 再起動

# systemctl restart sshd.service

[CentOS 7] NTPクライアントの設定(chronyd)

chronydの設定変更

# vi /etc/chrony.conf
デフォルトのリストをコメントアウトし、参照したいサーバを追記する。
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 10.1.1.1 iburst
server 10.1.1.2 iburst

chronydの再起動

# systemctl restart chronyd.service

時刻同期の確認

# chronyc sources
210 Number of sources = 2
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 10.1.1.1                   2   6    17    45  -6150ns[  -76us] +/- 4346us
^- 10.1.1.2                   2   6    17    45    -12us[  -12us] +/- 9217us

chronydの起動設定、サービスの稼働状況の確認

# systemctl status chronyd.service
chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled)
   Active: active (running) since Tue 2016-01-05 16:42:16 JST; 2min 15s ago
  Process: 25697 ExecStartPost=/usr/libexec/chrony-helper add-dhclient-servers (code=exited, status=0/SUCCESS)
  Process: 25694 ExecStart=/usr/sbin/chronyd -u chrony $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 25696 (chronyd)
   CGroup: /system.slice/chronyd.service
           `-25696 /usr/sbin/chronyd -u chrony

Jan 05 16:42:16 centos7 chronyd[25696]: chronyd version 1.29.1 starting
Jan 05 16:42:16 centos7 chronyd[25696]: Linux kernel major=3 minor=10 patch=0
Jan 05 16:42:16 centos7 chronyd[25696]: hz=100 shift_hz=7 freq_scale=1.00000000 nominal_tick=10000 slew_delta_tick=8..._pll=2
Jan 05 16:42:16 centos7 systemd[1]: Started NTP client/server.
Jan 05 16:42:21 centos7 chronyd[25696]: Selected source 10.32.64.36
Jan 05 16:42:21 centos7 chronyd[25696]: System clock wrong by -24.864519 seconds, adjustment started
Jan 05 16:41:56 centos7 chronyd[25696]: System clock was stepped by -24.865 seconds
Hint: Some lines were ellipsized, use -l to show in full.

[CentOS 7] DNSリゾルバの設定

DNSの参照先を「8.8.8.8」と「8.8.4.4」に設定する。

# nmcli c mod ens32 ipv4.dns "8.8.8.8 8.8.4.4"
# nmcli c mod ens32 ipv4.dns-search internal.net

ネットワークの再起動を行い設定を反映する。

# systemctl restart network

設定を確認

# nmcli d show ens32 | grep DNS
IP4.DNS[1]:                             8.8.8.8
IP4.DNS[2]:                             8.8.4.4
# cat /etc/resolv.conf
# Generated by NetworkManager
search internal.net
nameserver 8.8.8.8
nameserver 8.8.4.4

[CentOS 7] グループ・ユーザの追加

「eng」というグループに所属する「user1」というユーザを作成する。

グループの追加

# groupadd -g 1000 eng
# grep eng /etc/group
eng:x:1000:

ユーザの追加

# useradd -u 1000 -g 1000 -d /home/user1 -m -s /bin/bash user1
# passwd user1
Changing password for user user1.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
# grep user1 /etc/passwd
user1:x:1000:1000::/home/user1:/bin/bash