June 15, 2014

Getting Started with RHEL7

Red Hat Enterprise Linux 7 リリース おめでとうございました。Docker をはじめ最新のテクノロジーを詰め込んだとだけあって、メジャーリリースに相応しい出来栄えのようですね。

systemd などは upstream の Fedora では 3年くらい前の fc15 くらいからですし、慣れてる人も多いでしょうが el7 で初めて触る人は結構辛いでしょうね。

とりあえず細かい話は公式のドキュメント類を目を皿にして読んでもらうとして、el6 までしか触ったことない人が真っ先に躓きそうなポイントを挙げてみます。Docker とか SDN とか目新しいことも大事だけど、基本的なことを当たり前にやってのけられる様になることがまずは重要かな、と。

作業の前に

bash-completion パッケージを導入することを強くおすすめする。なお、minimal だと入っていなかったハズ。

el7 はお作法的に、設定ファイルをゴリゴリ書くよりも、*ctl コマンドをオンザフライで叩いて反映させるものが多くなった気がする。*ctl コマンド多すぎ。

そして大概の *ctl コマンドは bash-completion を入れておくと TAB 補完が効くようになるので効率的。てか無いとツラい。ツラすぎる。

# rpm -qa |grep bash-completion
# yum install -y bash-completion

ネットワーク

ネットワーク周りは、NetworkManager がデフォルトになったのがインパクト大きいでしょう。

el6 だと、デスクトップ入りインストールだと勝手に入ってきて自動起動して不慣れなユーザを翻弄しましたね。そう、導入されたと同時に chkconfig NetworkManager off されるアイツです。

デフォルトっていうのは、デスクトップ入りインストールではなくて、minimal インストールでも標準になった、ということ。昔は VLAN やら Bonding 対応していませんでしたが、最近は対応しています。

一応 /etc/sysconfig/network-scripts/ifcfg-* を直接弄って反映させることもできますが、nmcli コマンドを叩いて設定するのがお作法なのでしょう。タブン。 bash-completion 入れておけば補完効く。

# nmcli --help
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS
  -t[erse]                                   terse output
  -p[retty]                                  pretty output
  -m[ode] tabular|multiline                  output mode
  -f[ields] <field1,field2,...>|all|common   specify fields to output
  -e[scape] yes|no                           escape columns separators in values
  -n[ocheck]                                 don't check nmcli and NetworkManager versions
  -a[sk]                                     ask for missing parameters
  -w[ait] <seconds>                          set timeout waiting for finishing operations
  -v[ersion]                                 show program version
  -h[elp]                                    print this help

OBJECT
  g[eneral]       NetworkManager's general status and operations
  n[etworking]    overall networking control
  r[adio]         NetworkManager radio switches
  c[onnection]    NetworkManager's connections
  d[evice]        devices managed by NetworkManager

あと、ifconfig など net-tools パッケージは Obsolete で非標準になっているので注意。ip コマンド使ってください。

# ip addr
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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff
    inet 192.168.86.30/24 brd 192.168.86.255 scope global eno1
       valid_lft forever preferred_lft forever

最後に、どうしてもよくわからなかったら nmtui-edit というコンソールで使える設定 UI があるのでそれを使いましょう。 NetworkManager-tui パッケージに含まれています。インストール iso にも入ってるので最悪それでなんとかしてください。

# yum install NetworkManager-tui
# nmtui-edit

ネットワークデバイス名命名規則

今までだと NIC の名前は認識した順やら MAC アドレス順に eth0, eth1 … というように名前が付けられて、それを調整するのに /etc/udev/rules.d/70-persistent-net.rules 弄って再起動したりほげほげ的なバットノウハウのカタマリでしたが、そもそもの命名規則が変わりました。

いわゆる biosdevname です。 el6 世代でも、Dell サーバや一部のサーバではコレが有効になってインフラエンジニアを墓場へと誘いましたね。 ( @htaira さん指摘ありがとうございます!)

デフォルトは Predictable Network Interface Names、Dell サーバは引き続き biosdevname だそうです。 Predictable Network Interface Nameseno1 とか enp1s0 みたいなのですね。biosdevname の場合、em1 とか p1p1 とか。

eth* みたいな名前で監視のスクリプトを組んでる場合や、KickStart するときは重々注意すること。

ホスト名

ホスト名変えるときは、いままで /etc/sysconfig/network に書いていたけど、el7 は /etc/hostname に書く。 また、hostnamectl で確認やら変更出来る。これも bash-completion 入れておけば補完効く。

# hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...

Query or change system hostname.

  -h --help              Show this help
     --version           Show package version
     --transient         Only set transient hostname
     --static            Only set static hostname
     --pretty            Only set pretty hostname
  -P --privileged        Acquire privileges before execution
     --no-ask-password   Do not prompt for password
  -H --host=[USER@]HOST  Operate on remote host

Commands:
  status                 Show current hostname settings
  set-hostname NAME      Set system hostname
  set-icon-name NAME     Set icon name for host
  set-chassis NAME       Set chassis type for host

ファイアウォール

ファイアウォールは iptables から Firewalld に移行。一応 iptables パッケージ残っているので iptables -L とか見れる。 コマンドは firewall-cmd を使う。bash-completion 入れておけば補完効く。

# firewall-cmd --help

Usage: firewall-cmd [OPTIONS...]

General Options
  -h, --help           Prints a short help text and exists
  -V, --version        Print the version string of firewalld
  -q, --quiet          Do not print status messages

Status Options
  --state              Return and print firewalld state
  --reload             Reload firewall and keep state information
  --complete-reload    Reload firewall and loose state information

Permanent Options
  --permanent          Set an option permanently
                       Usable for options maked with [P]

Zone Options
  --get-default-zone   Print default zone for connections and interfaces
  --set-default-zone=<zone>
                       Set default zone
  --get-active-zones   Print currently active zones
  --get-zones          Print predefined zones [P]
  --get-services       Print predefined services [P]
  --get-icmptypes      Print predefined icmptypes [P]
  --get-zone-of-interface=<interface>
                       Print name of the zone the interface is bound to [P]
  --get-zone-of-source=<source>[/<mask>]
                       Print name of the zone the source[/mask] is bound to [P]
  --list-all-zones     List everything added for or enabled in all zones [P]
  --new-zone=<zone>    Add a new zone [P only]
  --delete-zone=<zone> Delete an existing zone [P only]
  --zone=<zone>        Use this zone to set or query options, else default zone
                       Usable for options maked with [Z]
  --get-target         Get the zone target [P only]
  --set-target=<target>
                       Set the zone target [P only]

IcmpType Options
  --new-icmptype=<icmptype>
                       Add a new icmptype [P only]
  --delete-icmptype=<icmptype>
                       Delete and existing icmptype [P only]

Service Options
  --new-service=<service>
                       Add a new service [P only]
  --delete-service=<service>
                       Delete and existing service [P only]

Options to Adapt and Query Zones
  --list-all           List everything added for or enabled in a zone [P] [Z]
  --list-services      List services added for a zone [P] [Z]
  --timeout=<seconds>  Enable an option for seconds only
                       Usable for options maked with [T]
  --add-service=<service>
                       Add a service for a zone [P] [Z] [T]
  --remove-service=<service>
                       Remove a service from a zone [P] [Z]
  --query-service=<service>
                       Return whether service has been added for a zone [P] [Z]
  --list-ports         List ports added for a zone [P] [Z]
  --add-port=<portid>[-<portid>]/<protocol>
                       Add the port for a zone [P] [Z] [T]
  --remove-port=<portid>[-<portid>]/<protocol>
                       Remove the port from a zone [P] [Z]
  --query-port=<portid>[-<portid>]/<protocol>
                       Return whether the port has been added for zone [P] [Z]
  --list-icmp-blocks   List Internet ICMP type blocks added for a zone [P] [Z]
  --add-icmp-block=<icmptype>
                       Add an ICMP block for a zone [P] [Z] [T]
  --remove-icmp-block=<icmptype>
                       Remove the ICMP block from a zone [P] [Z]
  --query-icmp-block=<icmptype>
                       Return whether an ICMP block has been added for a zone
                       [P] [Z]
  --list-forward-ports List IPv4 forward ports added for a zone [P] [Z]
  --add-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
                       Add the IPv4 forward port for a zone [P] [Z] [T]
  --remove-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
                       Remove the IPv4 forward port from a zone [P] [Z]


  --query-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
                       Return whether the IPv4 forward port has been added for
                       a zone [P] [Z]
  --add-masquerade     Enable IPv4 masquerade for a zone [P] [Z] [T]
  --remove-masquerade  Disable IPv4 masquerade for a zone [P] [Z]
  --query-masquerade   Return whether IPv4 masquerading has been enabled for a
                       zone [P] [Z]
  --list-rich-rules    List rich language rules added for a zone [P] [Z]
  --add-rich-rule=<rule>
                       Add rich language rule 'rule' for a zone [P] [Z] [T]
  --remove-rich-rule=<rule>
                       Remove rich language rule 'rule' from a zone [P] [Z]
  --query-rich-rule=<rule>
                       Return whether a rich language rule 'rule' has been
                       added for a zone [P] [Z]

Options to Handle Bindings of Interfaces
  --list-interfaces    List interfaces that are bound to a zone [P] [Z]
  --add-interface=<interface>
                       Bind the <interface> to a zone [P] [Z]
  --change-interface=<interface>
                       Change zone the <interface> is bound to [Z]
  --query-interface=<interface>
                       Query whether <interface> is bound to a zone [P] [Z]
  --remove-interface=<interface>
                       Remove binding of <interface> from a zone [P] [Z]

Options to Handle Bindings of Sources
  --list-sources       List sources that are bound to a zone [P] [Z]
  --add-source=<source>[/<mask>]
                       Bind <source>[/<mask>] to a zone [P] [Z]
  --change-source=<source>[/<mask>]
                       Change zone the <source>[/<mask>] is bound to [Z]
  --query-source=<source>[/<mask>]
                       Query whether <source>[/<mask>] is bound to a zone
                       [P] [Z]
  --remove-source=<source>[/<mask>]
                       Remove binding of <source>[/<mask>] from a zone [P] [Z]

Direct Options
  --direct             First option for all direct options
  --get-all-chains
                       Get all chains [P]
  --get-chains {ipv4|ipv6|eb} <table>
                       Get all chains added to the table [P]
  --add-chain {ipv4|ipv6|eb} <table> <chain>
                       Add a new chain to the table [P]
  --remove-chain {ipv4|ipv6|eb} <table> <chain>
                       Remove the chain from the table [P]
  --query-chain {ipv4|ipv6|eb} <table> <chain>
                       Return whether the chain has been added to the table [P]
  --get-all-rules
                       Get all rules [P]
  --get-rules {ipv4|ipv6|eb} <table> <chain>
                       Get all rules added to chain in table [P]
  --add-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
                       Add rule to chain in table [P]
  --remove-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
                       Remove rule with priority from chain in table [P]
  --remove-rules {ipv4|ipv6|eb} <table> <chain>
                       Remove rules from chain in table [P]
  --query-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
                       Return whether a rule with priority has been added to
                       chain in table [P]
  --passthrough {ipv4|ipv6|eb} <arg>...
                       Pass a command through
  --get-all-passthroughs
                       Get all passthrough rules [P only]
  --get-passthroughs {ipv4|ipv6|eb} <arg>...
                       Get passthrough rules [P only]
  --add-passthrough {ipv4|ipv6|eb} <arg>...
                       Add a new passthrough rule [P only]
  --remove-passthrough {ipv4|ipv6|eb} <arg>...
                       Remove a passthrough rule [P only]
  --query-passthrough {ipv4|ipv6|eb} <arg>...
                       Return whether the passthrough rule has been added
                       [P only]

Lockdown Options
  --lockdown-on        Enable lockdown.
  --lockdown-off       Disable lockdown.
  --query-lockdown     Query whether lockdown is enabled

Lockdown Whitelist Options
  --list-lockdown-whitelist-commands
                       List all command lines that are on the whitelist [P]
  --add-lockdown-whitelist-command=<command>
                       Add the command to the whitelist [P]
  --remove-lockdown-whitelist-command=<command>
                       Remove the command from the whitelist [P]
  --query-lockdown-whitelist-command=<command>
                       Query whether the command is on the whitelist [P]
  --list-lockdown-whitelist-contexts
                       List all contexts that are on the whitelist [P]
  --add-lockdown-whitelist-context=<context>
                       Add the context context to the whitelist [P]
  --remove-lockdown-whitelist-context=<context>
                       Remove the context from the whitelist [P]
  --query-lockdown-whitelist-context=<context>
                       Query whether the context is on the whitelist [P]
  --list-lockdown-whitelist-uids
                       List all user ids that are on the whitelist [P]
  --add-lockdown-whitelist-uid=<uid>
                       Add the user id uid to the whitelist [P]
  --remove-lockdown-whitelist-uid=<uid>
                       Remove the user id uid from the whitelist [P]
  --query-lockdown-whitelist-uid=<uid>
                       Query whether the user id uid is on the whitelist [P]
  --list-lockdown-whitelist-users
                       List all user names that are on the whitelist [P]
  --add-lockdown-whitelist-user=<user>
                       Add the user name user to the whitelist [P]
  --remove-lockdown-whitelist-user=<user>
                       Remove the user name user from the whitelist [P]
  --query-lockdown-whitelist-user=<user>
                       Query whether the user name user is on the whitelist [P]

Panic Options
  --panic-on           Enable panic mode
  --panic-off          Disable panic mode
  --query-panic        Query whether panic mode is enabled

長い。

# firewall-cmd --permanent --add-port=443/tcp

とかすればよろしい。--permanent しないと再起動時にルールが消えるので気をつけること。 適当に TAB 叩きまくればそれっぽいルールが書けるが、詳細を “日本語で” 読みたいときは、FedoraProject の wiki を読むのが良い。

FirewallD/jp - FedoraProject

サービスの自動起動

systemd の洗礼。・・・とは言え、2014年も半ばな今なら、ググれば適切な回答を得ることはそんなに難しくないだろう。

el6 までは chkconfig でやっていたアレである。/etc/rc.d/init.d/README を読むと本当に消えてなくることがよく分かる。

# cat /etc/rc.d/init.d/README
You are looking for the traditional init scripts in /etc/rc.d/init.d,
and they are gone?

Here's an explanation on what's going on:

You are running a systemd-based OS where traditional init scripts have
been replaced by native systemd services files. Service files provide
very similar functionality to init scripts. To make use of service
files simply invoke "systemctl", which will output a list of all
currently running services (and other units). Use "systemctl
list-unit-files" to get a listing of all known unit files, including
stopped, disabled and masked ones. Use "systemctl start
foobar.service" and "systemctl stop foobar.service" to start or stop a
service, respectively. For further details, please refer to
systemctl(1).

Note that traditional init scripts continue to function on a systemd
system. An init script /etc/rc.d/init.d/foobar is implicitly mapped
into a service unit foobar.service during system initialization.

Thank you!

Further reading:
        man:systemctl(1)
        man:systemd(1)
        http://0pointer.de/blog/projects/systemd-for-admins-3.html
        http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities

ちなみに chkconfig を叩くと・・・

# chkconfig
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

とまぁ、言われた通り、systemctl list-unit-files を叩くことで現在の自動起動設定は見れる。

# systemctl list-unit-files |grep enabled
acpid.service                               enabled
arp-ethers.service                          enabled
avahi-daemon.service                        enabled
crond.service                               enabled
dbus-org.fedoraproject.FirewallD1.service   enabled
dbus-org.freedesktop.Avahi.service          enabled
dbus-org.freedesktop.NetworkManager.service enabled
dbus-org.freedesktop.nm-dispatcher.service  enabled
dnsmasq.service                             enabled
firewalld.service                           enabled
~~ snip ~~

有効化は enable すればよろしい。あとは雰囲気で分かる通り、status だの disable, start, stop などすれば良い。 これも bash-completion 入れておけば補完効く。再三であれだけど、bash-completion ないとダルくて無理。

# systemctl status httpd.service

そういえば systemd に切り替わったとは言え、一応互換性のためか servicehalt, init, reboot, runlevel, shutdown などのコマンドは使える。これは Fedora でもそう。

デフォルトランレベル(ターゲット)変更

前に書いた。

ログ関連(syslog)

journald になった。つまり /var/log/messages がない、という事案が発生する。 ・・・と言われていたと思うんだけど syslog.service デフォで動いているような・・・。即って /var/log/messages がしっかり出力されている。。。あれ、この環境正しいのか?

ともかく、journald では journalctl コマンドを叩くことでログを確認できる。これも bash-completion 入れておけば補完効く。

# journalctl --help
journalctl [OPTIONS...] [MATCHES...]

Query the journal.

Flags:
     --system              Show only the system journal
     --user                Show only the user journal for the current user
     --since=DATE          Start showing entries on or newer than the specified date
     --until=DATE          Stop showing entries on or older than the specified date
  -c --cursor=CURSOR       Start showing entries from the specified cursor
     --after-cursor=CURSOR Start showing entries from after the specified cursor
     --show-cursor         Print the cursor after all the entries
  -b --boot[=ID]           Show data only from ID or, if unspecified, the current boot
  -k --dmesg               Show kernel message log from the current boot
  -u --unit=UNIT           Show data only from the specified unit
     --user-unit=UNIT      Show data only from the specified user session unit
  -p --priority=RANGE      Show only messages within the specified priority range
  -e --pager-end           Immediately jump to end of the journal in the pager
  -f --follow              Follow the journal
  -n --lines[=INTEGER]     Number of journal entries to show
     --no-tail             Show all lines, even in follow mode
  -r --reverse             Show the newest entries first
  -o --output=STRING       Change journal output mode (short, short-iso,
                                   short-precise, short-monotonic, verbose,
                                   export, json, json-pretty, json-sse, cat)
  -x --catalog             Add message explanations where available
  -l --full                Do not ellipsize fields
  -a --all                 Show all fields, including long and unprintable
  -q --quiet               Do not show privilege warning
     --no-pager            Do not pipe output into a pager
  -m --merge               Show entries from all available journals
  -D --directory=PATH      Show journal files from directory
     --file=PATH           Show journal file
     --root=ROOT           Operate on catalog files underneath the root ROOT
     --interval=TIME       Time interval for changing the FSS sealing key
     --verify-key=KEY      Specify FSS verification key
     --force               Force overriding of the FSS key pair with --setup-keys

Commands:
  -h --help                Show this help text
     --version             Show package version
     --new-id128           Generate a new 128-bit ID
     --header              Show journal header information
     --disk-usage          Show total disk usage of all journal files
  -F --field=FIELD         List all values that a specified field takes
     --list-catalog        Show message IDs of all entries in the message catalog
     --dump-catalog        Show entries in the message catalog
     --update-catalog      Update the message catalog database
     --setup-keys          Generate a new FSS key pair
     --verify              Verify journal file consistency

時間合わせ(ntp)

旧来の ntpd ももちろんあるが chrony というのがデフォルトになったようだ。ntpd の設定出来る人なら /etc/chronyd.conf 読めばだいたい分かる。

ntpq -p みたいなのは chronyc sources -v で確認できる。bash-completion 入れておけば補完効く。 最大の問題は名前をよく忘れること。

サブスクリプションアクティベート

rhn_register も叩けるようだけど、おそらく satellite 用だろう。subscription-manager を叩くべし。

とは言え、el6 系でも途中からこちらが標準になったし、OS インストール時に出てくるアクティベーション方法もこちらになったので、そこそこ皆使えるんじゃないかという淡い期待もある。 個人的にはクラシックの方が好きなんだけどなぁ。。。

# subscription-manager register

まとめ

  • bash-completion だいじ
  • NetworkManager: nmcli コマンド覚える
    • 最悪 nmtui-edit 使って
  • ifconfig は Obsolete: ip コマンド覚える
  • hostname/etc/hostname
    • hostnamectl コマンドもあるよ
  • iptablesfirewalld に: firewall-cmd 覚える
  • chkconfig 相当は systemctl コマンド
    • リスト出したいなら systemctl list-unit-files
  • デフォルトランレベル(ターゲット)変えるなら /etc/systemd/system/default.target のシンボリックリンクいじる
  • syslogjournald
    • journalctl コマンドでログ見れる
  • ntpd はデフォ chrony になった
  • rhn_registersubscription-manager

© Kazuhisa Hara 2014-2022