なにかの技術メモ置き場

なにかの技術メモ置き場

@インフラエンジニア

インフラ構築 - サーバ - 基本設定

まずはサーバの基本設定から。各サーバの共通設定とも言える。

OSインストール


[ソフトウェアの選択]:最小限のインストール
[ネットワークとホスト名]:ノータッチ(DHCPのまま)
[インストール先]:下記

物理パーティション
/dev/sda1 /boot xfs 500MB
/dev/sda2 LVM LVM 残り全て

論理パーティション(/dev/sda2内)
/dev/vg0/lv0 swap swap 2048MB
/dev/vg0/lv1 / xfs 残り全て


[ユーザーの作成]:しない(をい

なお、インストールの手法はPXEブート → Kickstart
以下参考までに、試行錯誤中のKickstartファイル。

#version=RHEL7
# System authorization information
auth --enableshadow --passalgo=sha512

# Use network installation
url --url="http://ftp.riken.jp/Linux/centos/7/os/x86_64/"
# Run the Setup Agent on first boot
firstboot --enable
###ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=jp106 --xlayouts='jp'
# System language
lang ja_JP.UTF-8

# Network information
network  --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network  --hostname=localhost
# Root password
rootpw --iscrypted $6$xDdslmG5U/QFKKU1$Kb.JedmEVjf6z6SB95nDz4RzLOiJDcS8bokS51aNg7ky0s.o9DcYJ8mZpVHgbpnUBoxS9SF9IPDLdXjb7jrjj1
# System timezone
timezone Asia/Tokyo --isUtc

# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel 
part /boot --fstype=xfs --asprimary --size=500
part pv.01 --size=1 --grow
volgroup vg0 pv.01
logvol swap --name=lv0 --vgname=vg0 --size=2048
logvol / --fstype=xfs --name=lv1 --vgname=vg0 --size=1 --grow

reboot

%packages
@core

%end

ネットワークインターフェース

CentOS6の頃と変わらず。

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s25
# Generated by dracut initrd
DEVICE="enp0s25"
ONBOOT=yes
NETBOOT=yes
UUID="fa859c3d-9374-4ee3-a043-ca107a97ef50"
IPV6INIT=yes
BOOTPROTO=static
HWADDR="00:23:7d:1f:b0:f1"
TYPE=Ethernet
NAME="enp0s25"

IPADDR=172.16.0.101
NETMASK=255.255.255.0
GATEWAY=172.16.0.201
DNS1=192.168.0.1

再起動し設定を反映。/etc/init.d/network restartは使えない。

[root@localhost ~]# systemctl restart network
[root@localhost ~]#

ちょ、何の表示も無しかい。確認にひと手間かかるな。

さぁ来ました、ifconfigは使えないよ!!(ドヤァ)
インストールすれば使えるって? けどお断りだ!

[root@localhost ~]# ip -4 addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp0s25:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 172.16.0.101/24 brd 172.16.0.255 scope global enp0s25
       valid_lft forever preferred_lft forever
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ip -4 route
default via 172.16.0.201 dev enp0s25  proto static  metric 1024
172.16.0.0/24 dev enp0s25  proto kernel  scope link  src 172.16.0.101
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.0.1
nameserver 2001:268:fd07:4::1
nameserver 2001:268:fd08:4::1

諸事情によりDNSサーバ(市販ルータ)は別のネットワークにある。

SSHサーバ

ポートのみ変更。セキュリティとしては不十分だが追加の対応は後日。

[root@localhost ~]# cat /etc/ssh/sshd_config | grep "^Port"
Port XXXXX

ここで私史上最難関のfirewalldの設定。
サービスとポートの初期状態。

[root@localhost ~]# firewall-cmd --list-services
dhcpv6-client ssh
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --list-port
[root@localhost ~]#

設定の変更・反映。

[root@localhost ~]# firewall-cmd --add-port=XXXXX/tcp --permanent
success
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --remove-service=ssh --permanent
success
[root@localhost ~]#
[root@localhost ~]# systemctl restart firewalld		# 実際は不要だが、permanentオプションの効果確認のため実施

設定反映の確認。

[root@localhost ~]# firewall-cmd --list-services
dhcpv6-client
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --list-port
XXXXX/tcp

むむ、netstatも無いようだ。以下で代用できるとのこと。
# オプション -4:IPv4 -n:ポートを番号で表示 -t:TCP -a:全ての状態

[root@localhost ~]# ss -4nta | head -n 1; ss -4nta | grep XXXXX
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port
LISTEN     0      128                       *:XXXXX                    *:*
ESTAB      0      0              172.16.0.101:XXXXX         172.16.0.100:54943

最後に自動起動の設定。
CentOS7からはchkconfigに代わりsystemdによる管理となるそうな。

[root@localhost ~]# chkconfig

注記: この出力は 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

確かに、sshdが初期状態で含まれていないということは別のもの(systemd)が管理していることの裏付けか。
自動起動を有効化する。

[root@localhost ~]# systemctl list-unit-files | grep sshd
sshd-keygen.service                         static
sshd.service                                disabled
sshd@.service                               static
sshd.socket                                 disabled
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# systemctl enable sshd
ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service'
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# systemctl list-unit-files | grep sshd
sshd-keygen.service                         static
sshd.service                                enabled
sshd@.service                               static
sshd.socket                                 disabled

SELinux

お約束、と言っては技術者の風上にも置けないが、SELinuxを無効化する。

[root@localhost ~]# setenforce 0
[root@localhost ~]#
[root@localhost ~]# getenforce
Disabled
[root@localhost ~]#
[root@localhost ~]# cat /etc/sysconfig/selinux | grep "^SELINUX="
SELINUX=disabled

ホスト名、ドメイン

いつものように/etc/sysctl.confの最下行に追記しようと思ったのだが、

[root@localhost ~]# cat /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

ファイル構成が変わったようで。
大元のファイルは弄らず、新規ファイルにまとめて記入すれば管理上も楽だろう。

[root@localhost ~]# vi /etc/sysctl.d/hostname.conf
kernel.hostname = HOSTNAME
kernel.domainname = DOMAINNAME

設定の反映

[root@localhost ~]# init 6

ここで思うことは、『OSの再起動までする必要があったのか?』ということ。
今回は少なくともホスト名を反映させるために必要だったが、なるべくなら再起動を避けられる道を模索したいものだ。
# OSの再起動 > デーモンの再起動 > 設定ファイルのリロード > 即時反映


それでは、ひとまずここまで。
# firewalldを勉強しなければならないけど、とっつきにくい・・・orz