CentOS 7 不要サービスの停止

さてさて、サーバにCentOS 7入れたので、まずは不要なサービスを止めましょう。CentOS 7からはsystemdがデフォルトなので、CentOS 6とはいろいろ操作が異なりますね。

サービス一覧

$ systemctl list-units --type=service
UNIT                                  LOAD   ACTIVE SUB     DESCRIPTION
auditd.service                        loaded active running Security Auditing Service
avahi-daemon.service                  loaded active running Avahi mDNS/DNS-SD Stack
chronyd.service                       loaded active running NTP client/server
crond.service                         loaded active running Command Scheduler
dbus.service                          loaded active running D-Bus System Message Bus
getty@tty1.service                    loaded active running Getty on tty1
irqbalance.service                    loaded active running irqbalance daemon
iscsi-shutdown.service                loaded active exited  Logout off all iSCSI sessions on shutdown
kdump.service                         loaded active exited  Crash recovery kernel arming
kmod-static-nodes.service             loaded active exited  Create list of required static device nodes for the current kernel
lvm2-lvmetad.service                  loaded active running LVM2 metadata daemon
lvm2-monitor.service                  loaded active exited  Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
lvm2-pvscan@8:2.service               loaded active exited  LVM2 PV scan on device 8:2
network.service                       loaded active exited  LSB: Bring up/down networking
NetworkManager.service                loaded active running Network Manager
polkit.service                        loaded active running Authorization Manager
postfix.service                       loaded active running Postfix Mail Transport Agent
rhel-dmesg.service                    loaded active exited  Dump dmesg to /var/log/dmesg
rhel-import-state.service             loaded active exited  Import network configuration from initramfs
rhel-readonly.service                 loaded active exited  Configure read-only root support
rsyslog.service                       loaded active running System Logging Service
sshd.service                          loaded active running OpenSSH server daemon
systemd-backlight@acpi_video0.service loaded active exited  Load/Save Screen Backlight Brightness of acpi_video0
systemd-journald.service              loaded active running Journal Service
systemd-logind.service                loaded active running Login Service
systemd-random-seed.service           loaded active exited  Load/Save Random Seed
systemd-readahead-collect.service     loaded active exited  Collect Read-Ahead Data
systemd-readahead-replay.service      loaded active exited  Replay Read-Ahead Data
systemd-remount-fs.service            loaded active exited  Remount Root and Kernel File Systems
systemd-sysctl.service                loaded active exited  Apply Kernel Variables
systemd-tmpfiles-setup-dev.service    loaded active exited  Create static device nodes in /dev
systemd-tmpfiles-setup.service        loaded active exited  Create Volatile Files and Directories
systemd-udev-trigger.service          loaded active exited  udev Coldplug all Devices
systemd-udevd.service                 loaded active running udev Kernel Device Manager
systemd-update-utmp.service           loaded active exited  Update UTMP about System Reboot/Shutdown
systemd-user-sessions.service         loaded active exited  Permit User Sessions
systemd-vconsole-setup.service        loaded active exited  Setup Virtual Console
tuned.service                         loaded active running Dynamic System Tuning Daemon

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

38 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

サービスの内容と残すか無効化するか。

Service Description To be disable?
auditd Linux Security Modulesによるシステムコール許可・不許可のログを出力させるサービス 残しておく
avahi-daemon mDNS/DNS-SDによるローカルネットワーク内の名前解決サービス MacBonjourもあるし残す(環境によっては不要)
chronyd NTPによる時刻同期 必要
crond いつものcron 必要
dbus publish/subscribe型のシステム内プロセス間メッセージ配信サービス 必要
irqbalance ハードウェア割込み処理をCPUの各コアに分散させるサービス 2 coreなので必要
iscsi-shutdown shutdown時にiscsiセッションをログオフしてくれるサービス iscsi使わないけどoneshotなので放置
kdump カーネルクラッシュ時にカーネルの状態をダンプするサービス 使う日が来ないことを祈りつつ残す
kmod-static-nodes 起動時に/dev配下のデバイスファイルの設定をしている? 必要
lvm2-lvmetad LVM用(3.6. メタデータデーモン (lvmetad) LVMを利用しているので残す
lvm2-monitor LVMボリュームの監視 残す
network ネットワークインターフェース起動用 必要
NetworkManager ネットワーク設定の自動管理 今回は有線しか使わないけど使い方は覚えたいので残しておく。勝手にネットワーク設定が切り替わったりするケースもあるので手動管理したい人は停止しておいたほうが無難。
polkit セキュリティ・権限ポリシー管理 細かい権限管理は不要なので停止したいが、systemdなどとも連携してるため残す
postfix メールサーバ 不要なので無効化
rhel-dmesg dmesgを/var/log/dmesgに吐く 残す
rhel-import-state initramfsの設定ファイルを起動時にコピーするみたいだがよくわからん 残す
rhel-readonly /etc/sysconfig/readonly-rootの設定に基づいて起動時に/ をreadonlyにする たぶん使わないけど残す
rsyslog ログ管理サービス 必要
sshd sshサービス 必要
tuned Linux Performance Tuning サービス(2.5. Tuned および ktune 残す

あれ、停止するのpostfixぐらいかw。

あと、SELinuxも無効にしてために/etc/sysconfig/selinuxを開いて、

SELINUX=disabled

と設定しておく。

Haskell道 その2

すごいHaskellたのしく学ぼう!

すごいHaskellたのしく学ぼう!

Amazonで注文してたのが届いたので早速読んでます。

リスト操作

結合
[1, 2, 3] ++ [4, 5, 6]
 -> [1, 2, 3, 4, 5, 6]

リスト結合時は左側のリストの末端まで走査することになるため、左側に大きなリストを置かない方がいいと書いてるけど、実際は遅延評価なので気にならないっぽい。

*Main> let n = [1..99999999] ++ [1]  -- 一瞬
*Main> let t = tail n                -- 一瞬
*Main> length t                      -- 時間がかかる
99999999

先頭に要素を追加する。

let str = "ello, world"
'h':str
 -> "hello, world"
"h":str
 -> error  -- "h"は要素ではないため
アクセス

!! のあとに添え字を置く。

[1, 2, 3, 4, 5, 6] !! 2
 -> 3
操作
head [1, 2, 3, 4, 5, 6]
 -> 1
tail [1, 2, 3, 4, 5, 6]
 -> [2, 3, 4, 5, 6]
last [1, 2, 3, 4, 5, 6]
 -> 6
init [1, 2, 3, 4, 5, 6]
 -> [1, 2, 3, 4, 5]
take 3 [1, 2, 3, 4, 5, 6]
 -> [1, 2, 3]
drop 3 [1, 2, 3, 4, 5, 6]
 -> [4, 5, 6]
長さ
lenght [1, 2, 3, 4, 5, 6]
 -> 6
空リストチェック
null [1, 2, 3, 4, 5, 6]
 -> False
null []
 -> True
逆リスト
reverse [1, 2, 3]
 -> [3, 2, 1]
包含

ruby的には include?

elem 2 [1, 2, 3]
 -> True
elem 4 [1, 2, 3]
 -> False

サーバ リプレイス

サーバに使ってたAtom N330のPCですが、あまり使ってない&ファン音がうるさいので、一年以上電源すら入れてませんでした。GWで休みなのでリプレイスすることにしましょう。

今回購入したのはShuttle DS57U。
f:id:jetBeaver:20150503101352j:plain
www.shuttle-japan.jp

一緒に、Samsung SSD 850 EVO mSATA 120GBとCFD Elixir DDR3L 1600MHz 8GBも購入。(型番だと、MZ-M5E120 と D3N1600Q-L8G)

組み立ては超簡単なので解説するまでもないですね。Dockerの実験とかしたく、OSどうしようか迷ったけどとりあえずCentOS 7を入れておいた。

稼働中にHDMI抜き差しすると、

[drm:drm_edid_block_valid] *ERROR* EDID checksum is invalid, remainder is 130

とか出てくるけど、気にしない。

ファンレスなので稼働中は完全無音。いいですね。今まで手ごろなファンレスPCだとAtom系プロセッサが多かったですが、DS57Uは’Broadwell-U’Intel Celeron 3205U搭載なので性能もだいぶマシになってるかと。(Atom N330はさすがにとろかった)

UNIX BENCHの結果も貼っときます。

========================================================================
   BYTE UNIX Benchmarks (Version 5.1.3)

   System: noop: GNU/Linux
   OS: GNU/Linux -- 3.10.0-229.1.2.el7.x86_64 -- #1 SMP Fri Mar 27 03:04:26 UTC 2015
   Machine: x86_64 (x86_64)
   Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
   CPU 0: Intel(R) Celeron(R) 3205U @ 1.50GHz (2993.1 bogomips)
          Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET, Intel virtualization
   CPU 1: Intel(R) Celeron(R) 3205U @ 1.50GHz (2993.1 bogomips)
          Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET, Intel virtualization
   09:45:08 up 19 min,  1 user,  load average: 0.10, 0.05, 0.03; runlevel 3

------------------------------------------------------------------------
Benchmark Run: 日  5月 03 2015 09:45:08 - 10:13:22
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       17444542.6 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     2720.9 MWIPS (9.9 s, 7 samples)
Execl Throughput                               2626.3 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        583978.7 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          167450.0 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       1538414.4 KBps  (30.0 s, 2 samples)
Pipe Throughput                              941660.4 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 122952.4 lps   (10.0 s, 7 samples)
Process Creation                               8663.9 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   4462.0 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    893.4 lpm   (60.0 s, 2 samples)
System Call Overhead                        1422643.3 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   17444542.6   1494.8
Double-Precision Whetstone                       55.0       2720.9    494.7
Execl Throughput                                 43.0       2626.3    610.8
File Copy 1024 bufsize 2000 maxblocks          3960.0     583978.7   1474.7
File Copy 256 bufsize 500 maxblocks            1655.0     167450.0   1011.8
File Copy 4096 bufsize 8000 maxblocks          5800.0    1538414.4   2652.4
Pipe Throughput                               12440.0     941660.4    757.0
Pipe-based Context Switching                   4000.0     122952.4    307.4
Process Creation                                126.0       8663.9    687.6
Shell Scripts (1 concurrent)                     42.4       4462.0   1052.4
Shell Scripts (8 concurrent)                      6.0        893.4   1489.1
System Call Overhead                          15000.0    1422643.3    948.4
                                                                   ========
System Benchmarks Index Score                                         931.2

------------------------------------------------------------------------
Benchmark Run: 日  5月 03 2015 10:13:22 - 10:41:37
2 CPUs in system; running 2 parallel copies of tests

Dhrystone 2 using register variables       34825486.9 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     5441.2 MWIPS (9.9 s, 7 samples)
Execl Throughput                               5794.2 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        998230.2 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          289651.2 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2468148.8 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1879296.2 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 411993.8 lps   (10.0 s, 7 samples)
Process Creation                              18371.9 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   6687.3 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    913.8 lpm   (60.1 s, 2 samples)
System Call Overhead                        2411994.1 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   34825486.9   2984.2
Double-Precision Whetstone                       55.0       5441.2    989.3
Execl Throughput                                 43.0       5794.2   1347.5
File Copy 1024 bufsize 2000 maxblocks          3960.0     998230.2   2520.8
File Copy 256 bufsize 500 maxblocks            1655.0     289651.2   1750.2
File Copy 4096 bufsize 8000 maxblocks          5800.0    2468148.8   4255.4
Pipe Throughput                               12440.0    1879296.2   1510.7
Pipe-based Context Switching                   4000.0     411993.8   1030.0
Process Creation                                126.0      18371.9   1458.1
Shell Scripts (1 concurrent)                     42.4       6687.3   1577.2
Shell Scripts (8 concurrent)                      6.0        913.8   1522.9
System Call Overhead                          15000.0    2411994.1   1608.0
                                                                   ========
System Benchmarks Index Score                                        1716.6

負数の剰余

最近、これ見て、負数の余剰にこういう使い方があるんだーって思いました。
エクセルの角度の算出についての質問です.x,yにある値を代入して,... - Yahoo!知恵袋

処理系によって違うみたいなので、気になって試してみた。

C (Apple LLVM version 6.1.0 (clang-602.0.49))

$ cat mod.c
#include <stdio.h>

int main(void)
{
    printf("%d\n", -150 % 360);
    return 0;
}
$ gcc mod.c && ./a.out
-150

Haskell

Prelude> (-150) `mod` 360
210

Ruby

irb(main):001:0> -150 % 360
=> 210

Scala

scala> -150 % 360
res0: Int = -150

Swift
f:id:jetBeaver:20150421210028p:plain


確かに違いますね。使うときは気をつけましょう。

Haskell道 その1

Haskellはforやwhileのような繰り返し構文がないんですね。なかなか戸惑いますが慣れでしょうか。

早速、コンビネーションを得る関数を作ってみた。

module Main (main) where

combination :: Integer -> [Integer] -> [[Integer]]
combination n elems | n <= 0 || length elems == 0 = []
combination 1 elems     = map (\e -> [e]) elems
combination n (e:elems) = current ++ others
    where current = map (e:) (combination (n-1) elems)
          others  = combination n elems

main :: IO ()
main = do
    print (combination 3 [1,2,3,4,5])

出力

*Main> main
[[1,2,3],[1,2,4],[1,2,5],[1,3,4],[1,3,5],[1,4,5],[2,3,4],[2,3,5],[2,4,5],[3,4,5]]

Haskellインストール

さてさて、今年はHaskellを覚えようと思ってます。
まずはインストールしましょう。

なお、インストール環境はこちら;
Mac OSX Yosemite(10.10.3), Xcode 6.3

インストールはとっても簡単で、Haskell Platform for Mac OS Xからpkgをダウンロードしてきて入れるだけ。
そしたら、/usr/bin 配下に、ghcとかghciとかcabalとかのリンクファイルが置かれます。本体は/Library/Frameworks/GHC.frameworkとか/Library/Haskellにインストールされてるみたい。

早速、ghciでインタラクティブに実行してみましょう。

$ ghci
GHCi, version 7.8.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> putStrLn "hello, world"
hello, world
Prelude> 

よーし、やるぞ!

Ether frameヘッダの欠如したpcapをwiresharkでみる方法

LinuxEthernet ネットワークインターフェイスからtcpdumpで取得したpcapがなんかおかしい。バイナリで見るとEther frameヘッダが欠如してるし。。

そんなときは、pcapヘッダのdata link typeを'RAW'に設定することでペイロードを直接IPとして見てくれる。

以下のコマンドで21byte目を書き換えて、wiresharkで開けばいいわけです。
echo -en '\x65' | dd bs=1 seek=20 conv=notrunc of=./tcpdump.pcap