tech_memo / linux


tech_memo

systemd

カーネル

Docker

RPM

Link


performance

ISO置場

Locale設定

ビープ音抑制

PXEブート


ファイルディスクリプタからのファイル復旧

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

  • サブスクリプションはRedhatのページにログインして、Active状態にしてあるものとする
    • 30日間評価用はなにもしなくてもActive状態になっている (2016/8/3 確認時点)
  • 初期状態
    [root@testserver14 work]# subscription-manager list
    
    +-------------------------------------------+
        Installed Product Status
    +-------------------------------------------+
    Product Name:   Red Hat Enterprise Linux Server
    Product ID:     69
    Version:        7.2
    Arch:           x86_64
    Status:         Unknown
    Status Details:
    Starts:
    Ends:
  • サーバへのサブスクリプションの登録
    [root@testserver14 work]# subscription-manager register
    Registering to: subscription.rhn.redhat.com:443/subscription
    Username: 44maru@ks.cnt.jp.mec.com
    Password:
    The system has been registered with ID: 40af9913-3665-4007-9cea-9b75ae931fe0
  • 登録状況確認
    [root@testserver14 work]# subscription-manager list --available
    +-------------------------------------------+
        Available Subscriptions
    +-------------------------------------------+
    Subscription Name:   30 Day Red Hat Enterprise Linux Server Self-Supported Evaluation
    Provides:            Red Hat Container Images Beta
                         Red Hat Beta
                         Red Hat Enterprise Linux Atomic Host Beta
                         Oracle Java (for RHEL Server)
                         Red Hat Container Images
                         Red Hat Enterprise Linux Server
                         Red Hat Enterprise Linux Atomic Host
    SKU:                 RH00065
    Contract:            11042975
    Pool ID:             8a85f981564d20c501564dbbc7f02951
    Provides Management: No
    Available:           2
    Suggested:           2
    Service Level:       Self-Support
    Service Type:        L1-L3
    Subscription Type:   Instance Based
    Ends:                09/01/2016
    System Type:         Physical
  • 上記登録したサブスクリプションを利用するように設定。--poolで、上記Pool IDを指定する
    [root@testserver14 work]# subscription-manager subscribe --pool=8a85f981564d20c501564dbbc7f02951
    Successfully attached a subscription for: 30 Day Red Hat Enterprise Linux Server Self-Supported Evaluation
  • 確認
    [root@testserver14 work]# subscription-manager list
    
    +-------------------------------------------+
        Installed Product Status
    +-------------------------------------------+
    Product Name:   Red Hat Enterprise Linux Server
    Product ID:     69
    Version:        7.2
    Arch:           x86_64
    Status:         Subscribed
    Status Details:
    Starts:         08/02/2016
    Ends:           09/01/2016

ブートローダ

マルチブートの際のハードディスク番号

  • grub-legacyの場合、grub.confに以下のように記述する
    root (hd1,0) #2番目のディスクの1番目のパーティション
  • なお、パーティション番号については、論理パーティションはカウントしない
    /dev/sda1
    /dev/sda2
    /dev/sda3
    /dev/sda4 # 論理パーティション
    /dev/sda5 # 拡張パーティション1
    /dev/sda6 # 拡張パーティション2
  • 上記例で、拡張パーティション2を指定する場合は、下記のようになる
    root (hd0,4) #1番目のディスクの5番目のパーティション(論理はスキップ)

ユーザリソース

  • ユーザのスレッド数が1024を超えるとコマンド実行時に、下記のエラーが出力される
    fork: Resource temporarily unavailable
  • これはulimit -u でuser process数を増やせば解決するが、1024を超えた状態でほかのユーザからsuしようとすると、ulimitを拡張していても、以下のエラーが出力される
    su: cannot set user id: Resource temporarily unavailable
  • suするときにはulimitおよび、/etc/security/limits.confとは別の設定ファイルでリソース上限が設定されている。以下のファイルをrootで編集すれば解決する
    [root@testserver12 ~]# vim /etc/security/limits.d/90-nproc.conf
    *          soft    nproc     1024        # ★ここを増やす
    root       soft    nproc     unlimited

Samba

全ユーザ共通環境変数設定

  • /etc/profile.dに、環境変数設定用のシェルを置いておくとよい。
    • 全ユーザのhistoryコマンドの結果に、タイムスタンプを付ける
      [root@vmdb4 profile.d]# pwd
      /etc/profile.d
      [root@vmdb4 profile.d]# cat history_timestamp.sh
      export HISTTIMEFORMAT='%F %T '
      [root@vmdb4 profile.d]# history | head -n2
          1  2014-12-22 18:43:54 vim /etc/sysconfig/network-scripts/route-eth0
          2  2014-12-22 18:44:10 service network restart
  • 仕組み
    • /etc/profileの終わりに以下の記述があり、実行されている。
      for i in /etc/profile.d/*.sh ; do
         if [ -r "$i" ]; then
             if [ "${-#*i}" != "$-" ]; then
                 . "$i"
             else
                 . "$i" >/dev/null 2>&1
             fi
         fi
      done

Ansble

CPU

perfコマンド + Flamegraph


HyperThreading? ON/OFFの確認方法

  1. CPUソケット数確認
    cat /proc/cpuinfo | grep "physical id" | uniq | wc -l
  2. ソケット当たりのCPUコア数確認
    cat /proc/cpuinfo | grep "cpu cores" | uniq
  3. 論理CPUコア数確認
    cat /proc/cpuinfo | grep "processor" | wc -l
  4. 上記結果
    1 * 2 == 3であれば、HT=OFF

CPU Hotplug の変更 (動的にCPUの特定coreの有効化/無効化)

ベンチマークページ

LVS

rsync


FTP

sudo

  • /etc/sudoersに以下のように追記(rootで、visudoコマンドで編集すること)
    #ユーザ名 ホスト名=(実行ユーザ名) [パスワードなしで実行:]コマンド
    testuser ALL=(ALL) NOPASSWD:ALL
  • sudo <コマンド>で実行できる。aliasを切っておくと便利。
    [testuser@testserver18]$ sudo pdsh -w "testserver[01-15]" echo | dshbak -c  
    failed to install module options for "misc/netgroup"
    ----------------
    testserver[01-15]
    ----------------

sudoファイルを壊してsudoできなくなった場合

  • pkexecを使う
    $ pkttyagent -p $(echo $$) | pkexec rm /etc/sudoers.d/FILENAME

sudo: sorry, you must have a tty to run sudo の回避

  • tty以外(SSHクライアントやコンソール上以外)でsudoを実行した場合に、タイトルのエラーが表示され、sudoコマンドの実行に失敗する
  • visudoで、/etc/sudoersの以下の行をコメントアウトすれば、tty以外からでもsudoが実行可能になる
    Defaults    requiretty # この行をコメントアウトする

syslog

  • 出力ファイル設定ファイル
    /etc/syslog.conf
    • RHEL6以降は
      /etc/rsyslog.conf
  • ローテーション設定ファイル
    /etc/logrotate.conf

Segmentation faultが発生したときに、/var/log/messageへの出力を無効化する

  • カーネルパラメータで設定可能
    sysctl debug.exception-trace=0
  • echoリダイレクトでの設定
    echo 0 > /proc/sys/debug/exception-trace

sar

kSar

yum

Ctrl-Cを押すと^Cが標準出力される

  • 以下のコマンドで出力を抑制できる
    [root@testserver08 ~]$ stty -choctl

VNC

Cobbler

RHEL 6.X

dstat

  • CPUやDISK、Memoryなど複数のHWリソースがモニタできる神コマンド
    [root@testserver07 ~]# dstat -Tclmdrns
    --epoch--- ----total-cpu-usage---- ---load-avg--- ------memory-usage----- -dsk/total- --io/total- -net/total- ----swap---
      epoch   |usr sys idl wai hiq siq| 1m   5m  15m | used  buff  cach  free| read  writ| read  writ| recv  send| used  free
    1375438836|  2   0  98   0   0   0|   0 0.01 0.03|10.9G  322M 3012M 3421M|  33k  153k|2.68  4.08 |   0     0 |  63M   16G
    1375438837|  0   0 100   0   0   0|   0 0.01 0.03|10.9G  322M 3012M 3421M|   0     0 |   0     0 |   0     0 |  63M   16G
    1375438838|  0   0 100   0   0   0|   0 0.01 0.03|10.9G  322M 3012M 3422M|   0     0 |   0     0 | 492B 2056B|  63M   16G
    1375438839|  0   0 100   0   0   0|   0 0.01 0.03|10.9G  322M 3012M 3422M|   0    16k|   0  4.00 |   0     0 |  63M   16G^C
  • -Tを-tに変えると普通のtimestampになる
    [root@testserver07 ~]# dstat -tclmdrns
    ----system---- ----total-cpu-usage---- ---load-avg--- ------memory-usage----- -dsk/total- --io/total- -net/total- ----swap---
      date/time   |usr sys idl wai hiq siq| 1m   5m  15m | used  buff  cach  free| read  writ| read  writ| recv  send| used  free
    02-08 19:19:54|  2   0  98   0   0   0|   0 0.02 0.03|10.9G  322M 3012M 3422M|  33k  153k|2.68  4.08 |   0     0 |  63M   16G
    02-08 19:19:55|  0   0 100   0   0   0|   0 0.02 0.03|10.9G  322M 3012M 3422M|   0     0 |   0     0 |   0     0 |  63M   16G
    02-08 19:19:56|  0   1  99   0   0   0|   0 0.02 0.03|10.9G  322M 3012M 3422M|   0     0 |   0     0 | 492B 2340B|  63M   16G^C
  • --top-bioオプションおよび、--top-ioオプションで、Diskに負荷をかけているプロセスを知ることもできる
    [root@testserver11 work]# dstat -t --top-io --top-bio
    ----system---- ----most-expensive---- ----most-expensive----
      date/time   |     i/o process      |  block i/o process
    26-08 11:35:18|init       1405k   17k|init        443B   15k
    26-08 11:35:19|sshd: root@ 404B  448B|
    26-08 11:35:20|sshd: root@ 328B  368B|java          0  8192B
    26-08 11:35:21|irqbalance 8079B   24B|

other

shell command

Linux-HA

  • tech_memo/linux/Linux-HA?

/tmp配下のファイルが消える

カーソルキー操作

  • ^A
    • 行の先頭に移動する
  • ^B
    • 後方に1文字移動する
  • ^E
    • 行の終わりに移動する
  • ^F
    • 前方の1文字に移動する
  • ^H
    • バックスペースと同じ
  • ^J
    • RETURNと同じ(=Ctrl + O,Ctrl + M)
  • ^K
    • カーソル以下にある文字を削除する
  • ^T
    • カーソルの左右の文字を入れ換える
  • ^U
    • 文字列全削除
  • ^W
    • カーソル位置の前にある単語を削除する
  • ^XX
    • 行の先頭、後方を往来する
  • ^Y
    • 最後に削除されたものを取り出す

cron

Memory

実メモリ利用量

Memory転送量のモニタ(Intel CPU E5シリーズ限定)

デバイスの性能情報

NUMA

Performance

  • ベンチマークツール 「STERAM」
  • 以下のように実行スレッド数を増やさないとある程度で頭打ちになるので本当の性能が取れないので注意
    gcc -O3 -fopenmp -D_OPENMP stream.c -o stream 
    export OMP_NUM_THREADS=8
    ./stream
    -------------------------------------------------------------
    STREAM version $Revision: 5.9 $
    -------------------------------------------------------------
    This system uses 8 bytes per DOUBLE PRECISION word.
    -------------------------------------------------------------
    Array size = 2000000, Offset = 0
    Total memory required = 45.8 MB.
    Each test is run 10 times, but only
    the *best* time for each is used.
    -------------------------------------------------------------
    Number of Threads requested = 8
    -------------------------------------------------------------
    Printing one line per active thread....
    Printing one line per active thread....
    Printing one line per active thread....
    Printing one line per active thread....
    Printing one line per active thread....
    Printing one line per active thread....
    Printing one line per active thread....
    Printing one line per active thread....
    -------------------------------------------------------------
    Your clock granularity/precision appears to be 1 microseconds.
    Each test below will take on the order of 1912 microseconds.
       (= 1912 clock ticks)
    Increase the size of the arrays if this shows that
    you are not getting at least 20 clock ticks per test.
    -------------------------------------------------------------
    WARNING -- The above is only a rough guideline.
    For best results, please be sure you know the
    precision of your system timer.
    -------------------------------------------------------------
    Function      Rate (MB/s)   Avg time     Min time     Max time
    Copy:       11453.0018       0.0028       0.0028       0.0028
    Scale:      10896.0649       0.0029       0.0029       0.0030
    Add:        11518.8575       0.0042       0.0042       0.0042
    Triad:      12006.5954       0.0040       0.0040       0.0040
    -------------------------------------------------------------
    Solution Validates
    -------------------------------------------------------------

Swap領域追加

  • http://d.hatena.ne.jp/lake_michigan/20100126/1264492717
  • スワップ元ファイル作成。下記だと350MB
    dd if=/dev/zero of=swapfile1 bs=1024k count=350
    chmod 600 swapfile1
  • スワップファイルに変更
    mkswap swapfile1
  • スワップ領域割り当て
    swapon swapfile1
  • 自動でマウントされるよに/etc/fstabに以下を追記
    /root/swap_file/swapfile1 swap         swap    defaults        0 0

Swap領域縮小

Swap領域解放

  • 一度Swap領域がusedになると解放されないことがある。silver02でたまになる。
  • 下記コマンドでswapを解放可能。ただし、swap used < mem free である必要がある。(mem freeが足りない場合は、drop cacheで、mem cacheを解放するとよい。)
    [root@myserver ~]# swapoff -a && swapon -a

Arun流メモリ使用量確認方法

find /proc/ -maxdepth 1 -type d | xargs -i{} grep VmData {}/status 2>/dev/null | awk 'BEGIN{a=0}{a+=$2}END{print a;}'

Huge Page

Mount

fstabを無効化してもマウントされる

  • https://qiita.com/10yama/items/1ab36a638c6e5c11c136
    Systemd で起動するLinuxで、起動ディスクのパーティーションテーブルが GPT で UEFI ブートする場合、/etc/fstab に書いてないものがマウントされることがあります。
    具体的には、Swapと、/, /home, /srv について、UEFIブートした起動ディスクに存在し、特定パーティーションタイプ(GUID)を持つ形で設定されているパーティーションは、/etc/fstab に書いてなかったりコメントアウトされていても、自動的にマウント・Swapon されます

各パーティションごとにアクセスしているユーザプロセスの確認

  • umountするときとかに役立つ。
    [root@testserver18 media]# fuser -vmedia/disk-1/
    
                         USER        PID ACCESS COMMAND
    /media/disk-1/:      testuser   5476 ..c.. zsh
                         root      32079 ..c.. su

mountしているUSBのdevファイル確認

  • 現在mountされているUSBがどのdeviceファイルになるかは以下でわかる
    [root@testserver18 ~]# cat /etc/mtab
    /dev/mapper/VolGroup00-LogVol00 / ext3 rw 0 0
    proc /proc proc rw 0 0
    sysfs /sys sysfs rw 0 0
    devpts /dev/pts devpts rw,gid=5,mode=620 0 0
    /dev/sda1 /boot ext3 rw 0 0
    tmpfs /dev/shm tmpfs rw 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
    sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0 
    dbserver:/share /share nfs rw,addr=192.168.22.1 0 0
    /dev/sdb1 /media/usb ext3 rw 0 0
    fuse /tmp/.truecrypt_aux_mnt1 fuse rw,nosuid,nodev,allow_other 0 0
    /dev/loop0 /media/usb/UID_CIVILIANS_DATA/RAW_DATA_100K fuseblk rw,allow_other,blksize=4096,default_permissions 0 0
    nfsd /proc/fs/nfsd nfsd rw 0 0
    192.168.22.102:/media/disk-1 /media/disk-1 nfs rw,addr=192.168.22.102 0 0
  • mountがされておらず、USB接続だけされている場合はdmessgコマンドや/var/log/messageから確認する。

automount

  • 下記、マウントオプション指定ファイル。UUID指定での、マウントを記述。
    boot    -fstype=ext4    :UUID="3e84bb2b-1fb2-4bee-89d7-a6dac040ae43"
    • RHEL6.3では、UUIDをの値をダブルクォーテーションで囲むとエラーが発生する。6.5はOKだった。

Disk

Network

NTP

NTP設定

  • NTPサーバの指定
    • /etc/ntp.confを下記のように編集
      # Use public servers from the pool.ntp.org project.
      # Please consider joining the pool (http://www.pool.ntp.org/join.html).
      #server 0.rhel.pool.ntp.org
      #server 1.rhel.pool.ntp.org
      #server 2.rhel.pool.ntp.org
      server 192.168.22.118
  • 起動
    service ntpd restart

NTPサーバと即座に時刻同期する方法

ntpdateを使う方法

  • 1. NTP server停止(server)
    service ntpd stop
  • 2. 時刻同期(client)
    ntpdate testserver18
  • 3. NTPサーバ起動
    service ntpd start

/etc/ntp/step-tickersを使う方法

  • 1. 以下のようにNTPサーバ名を記述する
    [root@testserver09 ~]# vi /etc/ntp/step-tickers
     
    testserver18
  • 2. ntpdの再起動
    [root@testserver09 ~]# service ntpd restart
    Shutting down ntpd:                      [  OK  ]
    ntpd: Synchronizing with time server:    [  OK  ]
    Starting ntpd:                           [  OK  ] 

デーモン

Other

プロセスとファイルディスクリプタ

WindowsファイルをUnixファイルに変換

dos2unix FILE