カメニッキ

カメとインコと釣りの人です

Linux標準教科書ver.2を読んだ

読んだのはこれ

Linux標準教科書 無料ダウンロード LPI-Japan LPICレベル1対応|Linux技術者認定機関 LPI-Japan [エルピーアイジャパン]

あらかじめ、↓を読んでたから目新しい内容はなかった。↓の本はすごくよかったとてもよかった

知らなかったこと

※ それくらい知っとけよ、っていうのは無しで・・

chage

ユーザパスワードの有効期限情報を変更する

# 確認
[root@cobblertest vagrant]# chage -l vagrant
Last password change                    : May 14, 2015
Password expires                    : never
Password inactive                   : never
Account expires                     : never
Minimum number of days between password change      : 0
Maximum number of days between password change      : 99999
Number of days of warning before password expires   : 7

# アカウント有効期限を2015/10/10までに設定
[root@cobblertest vagrant]# usermod -e 2015-10-10 vagrant
# パスワード有効日数を30日に(30日ごとに要変更)
[root@cobblertest vagrant]# chage -M 30 vagrant

# 再度確認
[root@cobblertest vagrant]# chage -l vagrant
Last password change                    : May 14, 2015
Password expires                    : Jun 13, 2015
Password inactive                   : never
Account expires                     : Oct 10, 2015
Minimum number of days between password change      : 0
Maximum number of days between password change      : 30
Number of days of warning before password expires   : 7

ssh-copy-id

公開鍵をリモートマシンに登録する

# 鍵作る
[vagrant@cobblertest ~]$ ssh-keygen
# ssh-copy-id ユーザ@接続先で登録
[vagrant@cobblertest ~]$ ssh-copy-id vagrant@localhost
# 接続先サーバで確認(今回は同じサーバ上だけど)
[vagrant@cobblertest ~]$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDlGRuG9・・・
追加されてる

ethtool

NICの情報を表示する

# ファームウェアやリンク状態とか見れる
[vagrant@cobblertest ~]$ sudo ethtool eth0
Settings for eth0:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    Speed: 1000Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: off (auto)
    Supports Wake-on: umbg
    Wake-on: d
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: yes

スティッキービット

スティッキービットが設定されたディレクトリは、「全てのユーザが書き込めるが、所有者しか削除できない」というアクセス権限になる。 /tmpなどがそう。

# 他ユーザの実行権限に「t」がついてる
drwxrwxrwt.  3 root root  4096  624 15:23 2015 tmp

# hogeディレクトリをつくって、chmodで1777を設定
[vagrant@cobblertest tmp]$ mkdir hoge
[vagrant@cobblertest tmp]$ chmod 1777 hoge/

# 別ユーザで確認
[root@cobblertest tmp]# useradd fuga
[root@cobblertest tmp]# su - fuga
[fuga@cobblertest ~]$ cd /tmp/hoge/
# 書き込み・ファイル削除はいける
[fuga@cobblertest hoge]$ touch xxxx
[fuga@cobblertest hoge]$ rm xxxx
[fuga@cobblertest hoge]$ cd ..
# ディレクトリ削除はできない
[fuga@cobblertest tmp]$ rmdir hoge/
rmdir: konnte „hoge/“ nicht entfernen: Die Operation ist nicht erlaubt

CentOS7への変更点

大きく以下の3つが変わった。

SysV initからsystemdへの以降

CentOS6までの/etc/rc.d配下の起動スクリプトを使用する方法から、改められた。 従来「service」と呼ばれていた仕組みが、「ユニット」として再定義された。
主なユニットは以下のとおり。

  • service:従来のサービスと同様
  • target:ランレベルに相当
  • mount:マウントポイント
  • swap:スワップ領域
  • device:デバイス

それぞれのユニットは依存関係が定義できるようになったため、依存関係にないサービスは並列処理で起動できるため、高速起動可能になった。 (これまでは依存関係を解決するため、順番に起動する方法だったので、遅い)

サービス操作

serviceに相当するコマンド「systemctl」を使用する

# 起動
[root@localhost vagrant]# systemctl start httpd

# ステータス確認
# cgroupを使用してサービスを実行するようになった(CPUやメモリのリソースを制限して割り当てる仕組み)
[root@localhost vagrant]# systemctl status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: active (running) since 水 2015-06-24 13:57:22 UTC; 1s ago
 Main PID: 2250 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─2250 /usr/sbin/httpd -DFOREGROUND
           ├─2251 /usr/sbin/httpd -DFOREGROUND
           ├─2252 /usr/sbin/httpd -DFOREGROUND
           ├─2253 /usr/sbin/httpd -DFOREGROUND
           ├─2254 /usr/sbin/httpd -DFOREGROUND
           └─2255 /usr/sbin/httpd -DFOREGROUND

 624 13:57:22 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
 624 13:57:22 localhost.localdomain httpd[2250]: AH00558: httpd: Could not reliably determine t...age
 624 13:57:22 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

# 再起動
[root@localhost vagrant]# systemctl restart httpd

# 停止
[root@localhost vagrant]# systemctl stop httpd

# ユニット一覧
# static:システム起動時の実行有無は指定不可
# enabled:システム起動時に実行する
# disabled:システム起動時に実行しない
[root@localhost vagrant]# systemctl list-unit-files
UNIT FILE                                   STATE
proc-sys-fs-binfmt_misc.automount           static
dev-hugepages.mount                         static
dev-mqueue.mount                            static
proc-fs-nfsd.mount                          static
proc-sys-fs-binfmt_misc.mount               static
sys-fs-fuse-connections.mount               static
sys-kernel-config.mount                     static
sys-kernel-debug.mount                      static
tmp.mount                                   disabled
var-lib-nfs-rpc_pipefs.mount                static
brandbot.path                               disabled
systemd-ask-password-console.path           static
systemd-ask-password-wall.path              static
session-3.scope                             static
session-4.scope                             static
auditd.service                              enabled
auth-rpcgss-module.service                  static
autovt@.service                             disabled
blk-availability.service                    disabled
brandbot.service                            static

# 自動起動設定・削除
[root@localhost vagrant]# systemctl disable httpd
[root@localhost vagrant]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

まだいろいろあるが、別途やる。。

journaklによるログ記録

サービスが出力するログを記録

# オプション無しで実行するとすべてのログ表示
[root@localhost vagrant]# journalctl
-- Logs begin at 水 2015-06-24 13:56:04 UTC, end at 水 2015-06-24 14:08:09 UTC. --
 624 13:56:04 localhost.localdomain systemd-journal[80]: Runtime journal is using 4.0M (max 22.8M, lea
 624 13:56:04 localhost.localdomain systemd-journal[80]: Runtime journal is using 4.0M (max 22.8M, lea
 624 13:56:04 localhost.localdomain kernel: Initializing cgroup subsys cpuset
 624 13:56:04 localhost.localdomain kernel: Initializing cgroup subsys cpu
 624 13:56:04 localhost.localdomain kernel: Initializing cgroup subsys cpuacct
 624 13:56:04 localhost.localdomain kernel: Linux version 3.10.0-229.el7.x86_64 (builder@kbuilder.dev.
 624 13:56:04 localhost.localdomain kernel: Command line: BOOT_IMAGE=/vmlinuz-3.10.0-229.el7.x86_64 ro
 624 13:56:04 localhost.localdomain kernel: e820: BIOS-provided physical RAM map:
 
# 特定のサービス
[root@localhost vagrant]# journalctl -u httpd
-- Logs begin at 水 2015-06-24 13:56:04 UTC, end at 水 2015-06-24 14:08:09 UTC. --
 624 13:57:22 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
 624 13:57:22 localhost.localdomain httpd[2250]: AH00558: httpd: Could not reliably determine the serv
 624 13:57:22 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
 
# 再起動した時にログが消えないようにする(デフォはtmpfsでメモリ上に作られた一時領域なので、明示的にディレクトリを用意)
[root@localhost log]# mkdir journal
[root@localhost log]# chmod 700 journal/
[root@localhost log]# reboot
[root@localhost journal]# cd /var/log/journal/
[root@localhost journal]# ll
合計 0
drwxr-sr-x 2 root systemd-journal 51  624 14:14 568f0e29c84d4ab9853523f962b56140

firewalldによるパケットフィルタリング

ゾーンという仕組みで管理する。

# デフォルトのゾーンを確認
[root@localhost journal]# firewall-cmd --get-default-zone
public

# publicゾーンだとsshとdhcp-clientサービスが許可
[root@localhost journal]# firewall-cmd --list-all
public (default, active)
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
  
# 認識しているサービス一覧表示
[root@localhost journal]# firewall-cmd --get-services
RH-Satellite-6 amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https

# httpを追加
[root@localhost journal]# firewall-cmd --add-service=http --permanent
success