#0 はじめに
今までCentOSしか使ったことがありませんでした。
はじめてUbuntuをインストールしたときに使った機能や設定変更のまとめです。
#1 環境
VMware Workstation 12 Player上のゲストマシンです。
root@server:~# cat /etc/issue
Ubuntu 16.04 LTS \n \l
root@server:~# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"
root@server:~# uname -a
Linux server 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
#2 使用するISOイメージ
下記サイトより、ubuntu-ja-16.04-desktop-amd64.isoをダウンロードしました。
https://www.ubuntulinux.jp/download/ja-remix
#3 設定変更
##3.1 multi-userターゲットに変更
GUIを使うと、PCの操作が非常に重くなるため、CUIに設定変更しました。
root@server:~# systemctl get-default
graphical.target
root@server:~# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /lib/systemd/system/multi-user.target.
root@server:~# systemctl get-default
multi-user.target
##3.2 NICの名前変更
NICの名前をPNIN(Predictable Network Interface Names)から従来の命名方法(eth0,eth1...)に変更しました。
root@server:~# vi /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="biosdevname=0 net.ifnames=0"
root@server:~# grub-mkconfig -o /boot/grub/grub.cfg
update-grubでもOKです。
root@server:~# update-grub
man update-grubより抜粋
>update-grub is a stub for running grub-mkconfig -o /boot/grub/grub.cfg to generate a grub2 config file.
##3.3 エディタの変更
Ubnutuでは標準エディタとしてnanoが起動するようです。
私はCentOSではviを使っているので、標準エディタをnanoからviに変更しました。
変更方法は以下のとおりです。
私の場合、ホームディレクトリに.bashrcがなかったので、/etc/skelよりコピーしました。
root@server:~# cp /etc/skel/.bashrc ~/
コピーした.bashrcに下記環境変数を追加する。
root@server:~# vi .bashrc
root@server:~# cat .bashrc
-中略-
export EDITOR=vi
##3.4 ユニット定義ファイルの場所
Ubuntuではユニット定義ファイルがインストールされる場所がCentOSとは異なるようです。
OS名 | デフォルト | カスタマイズ |
---|---|---|
CentOS7.3 | /usr/lib/systemd/system | /etc/systemd/system |
Ubuntu16.04 | /lib/systemd/system | /etc/systemd/system |
「デフォルト」とは、yumやaptでパッケージをインストールするとき、
ユニット定義ファイルがインストールされる場所です。
「カスタマイズ」とは、デフォルトにインストールしたユニット定義ファイルを変更して使う場合に
変更したユニット定義ファイルを置く場所です。
カスタマイズはCentOSとUbuntuで違いはないようです。
##3.5 IPアドレスの設定
NetworkManagerのnmtuiコマンドを使ってIPアドレスを設定していましたが、
NetworkManagerを停止した状態でIPアドレスを設定してみました。
NetworkManagerを停止すると、IPアドレスやデフォルトGW等の情報は下記ファイルに設定する必要があります。
ただし、CentOSとUbuntuでは以下のように異なります。
・CentOS:/etc/sysconfig/network-scripts/ifcfg-eth0
・Ubuntu:/etc/network/interfaces
NetworkManagerを停止する。
root@server:~# systemctl stop NetworkManager
"auto eth0"以下を追加しました。
root@server:~# vi /etc/network/interfaces
root@server:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.0.220/24
gateway 192.168.0.1
システムを再起動する。
root@server:~# shutdown -r now
ちなみに、nmtuiコマンドで設定したIPアドレス等の情報は、下記ファイルに保存されます。
root@server:~# cat /etc/NetworkManager/system-connections/eth0
[connection]
id=eth0
-以下、略-
##3.6 ロケールの変更
日本語表示を英語表示に変更する方法を以下に示します。
bashrcに環境変数を設定する。
root@server:~# vi .bashrc
export LANG=en_US.utf8
root@server:~# source .bashrc
#4 Proxy設定
Proxyがある環境(とくに会社)で必要な設定です。
##4.1 apt-getの場合
usernameとpasswordは、proxy認証時に使うものを指定する。
また、proxyのホスト名やポート番号は、実際の環境にあわせて変更してください。
下記の例はポート番号は8080の使用を想定しています。
root@server:~# vi /etc/apt/apt.conf.d/90proxy
root@server:~# cat /etc/apt/apt.conf.d/90proxy
Acquire::http::proxy "http://username:password@proxy.co.jp:8080/";
Acquire::https::proxy "https://username:password@proxy.co.jp:8080/";
##4.2 wgetの場合
##4.3 curlの場合
#5 aptコマンドの使い方
リポジトリからパッケージを取得してインストール/アップデートをするコマンドです。
CentOSのyumコマンドに相当します。
aptコマンドの使い方は下記を参考にしました。
第327回 aptコマンドを使ってみよう
Ubuntu16.04ではapt-getでなくaptコマンド
Ubuntu 16.04 / Debian 8: aptコマンドの使い方
5.1 インストール方法(install)
root@server:~/apt# apt install hping3
-以下、略-
5.2 アンインストール方法(remove)
root@server:~/apt# apt remove hping3
-以下、略-
5.3 アンインストール方法(purge)
removeは、設定ファイルが削除されず残ってしまいます。purgeを使うと、設定ファイルも削除できます。
root@server:~# apt purge apache2
-以下、略-
##5.4 パッケージの検索方法(完全一致:list)
root@server:~/apt# apt list hping3
一覧表示... 完了
hping3/xenial,now 3.a2.ds2-7 amd64 [インストール済み]
##5.5 パッケージの検索方法(部分一致:search)
root@server:~/apt# apt search hping3
ソート中... 完了
全文検索... 完了
hping3/xenial,now 3.a2.ds2-7 amd64 [インストール済み]
Active Network Smashing Tool
hping3-dbgsym/xenial 3.a2.ds2-7 amd64
debug symbols for package hping3
5.6 ソースパッケージのインストール方法
Ubuntu 16.04: apt sourceでソースコードをダウンロードする
独自Debパッケージやaptリポジトリを使ったサーバー管理術
###5.6.1 事前準備
ソースパッケージのリポジトリのコメントアウトを削除する。
root@server:~/test# grep deb-src /etc/apt/sources.list
# deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial main restricted
# deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
# deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial universe
# deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-updates universe
# deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://archive.canonical.com/ubuntu xenial partner
# deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted
# deb-src http://security.ubuntu.com/ubuntu xenial-security universe
# deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse
ソースパッケージのリポジトリを確認する。コメントが削除できたことがわかる。
root@server:~/test# grep deb-src /etc/apt/sources.list
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial universe
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-updates universe
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial multiverse
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://archive.canonical.com/ubuntu xenial partner
deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted
deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse
リポジトリのデータベースを更新する。
root@server:~# apt -y update
###5.6.2 ソースパッケージのダウンロード
ipコマンドのパスを調べる。
root@server:~/test# which ip
/sbin/ip
ipコマンドはiproute2パッケージに含まれていることがわかる。
root@server:~/test# dpkg -S /sbin/ip
iproute2: /sbin/ip
iproute2のソースパッケージをダウンロードする。
root@server:~/test# apt source iproute2
-中略-
ダウンロードしたソースパッケージを確認する。
root@server:~/test# ls
root@server:~/test# ls -F
iproute2-4.3.0/ iproute2_4.3.0-1ubuntu3.16.04.1.debian.tar.xz iproute2_4.3.0-1ubuntu3.16.04.1.dsc iproute2_4.3.0.orig.tar.xz
###5.6.3 ソースパッケージのダウンロード(カーネルソースコード)
カーネルのソースパッケージのダウンロードはここを参考にしました。
root@server:~/test# uname -r
4.4.0-21-generic
root@server:~/test# apt source linux-image-4.4.0-21-generic
パッケージリストを読み込んでいます... 完了
'linux-image-4.4.0-21-generic' の代わりに 'linux' をソースパッケージとして選出しています
注意: 'linux' パッケージは以下の場所の 'Git' バージョン制御システムで保守されています:
git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/xenial
パッケージの最新の (まだリリースされていないかもしれない) 更新を取得するには、
git clone git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/xenial
を使用してください。
146 MB のソースアーカイブを取得する必要があります。
-以下、略-
ダウンロードしたソースを確認する。
root@server:~/test# ls -F
linux-4.4.0/ linux_4.4.0-96.119.diff.gz linux_4.4.0-96.119.dsc linux_4.4.0.orig.tar.gz
##5.7 インストール可能なパッケージを調べる方法(apt-cache policy)
hping3はまだインストールされていない。
root@server:~# hping3
プログラム 'hping3' はまだインストールされていません。 次のように入力することでインストールできます:
apt install hping3
インストール可能なパッケージを調べる。3.a2.ds2-7のhping3がインストールできることがわかる(★)。
root@server:~# apt-cache policy hping3
hping3:
インストールされているバージョン: (なし)
候補: 3.a2.ds2-7
バージョンテーブル:
3.a2.ds2-7 500 ★
500 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
hping3パッケージをインストールする。
root@server:~# apt-get -y install hping3
インストールされたバージョンが3.a2.ds2-7になったことがわかる(★)。
root@server:~# apt-cache policy hping3
hping3:
インストールされているバージョン: 3.a2.ds2-7 ★
候補: 3.a2.ds2-7
バージョンテーブル:
*** 3.a2.ds2-7 500
500 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
100 /var/lib/dpkg/status
##5.8 インストール可能なバージョンの一覧を調べる方法(apt-cache madison)
root@server:~# apt-cache madison hping3
hping3 | 3.a2.ds2-7 | http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
hping3 | 3.a2.ds2-7 | http://jp.archive.ubuntu.com/ubuntu xenial/universe Sources
##5.9 aptコマンドの操作履歴の確認方法
hping3パッケージをインストールする。
root@server:~/apt# apt install hping3
操作履歴を確認する。
root@server:~# less /var/log/apt/history.log
Start-Date: 2017-09-20 11:44:43
Commandline: apt install hping3
Requested-By: hana_shin (1000)
Install: hping3:amd64 (3.a2.ds2-7)
End-Date: 2017-09-20 11:44:45
#6 dpkgコマンドの使い方
##6.1 パッケージ一覧の表示方法(dpkg -l)
CentOSの"rpm -qa"に相当する。
root@server:~# dpkg -l
要望=(U)不明/(I)インストール/(R)削除/(P)完全削除/(H)保持
| 状態=(N)無/(I)インストール済/(C)設定/(U)展開/(F)設定失敗/(H)半インストール/(W)トリガ待ち/(T)トリガ保留
|/ エラー?=(空欄)無/(R)要再インストール (状態,エラーの大文字=異常)
||/ 名前 バージョン アーキテクチ 説明
+++-=====================================-=======================================-============-================================================================================
ii a11y-profile-manager-indicator 0.1.10-0ubuntu3 amd64 Accessibility Profile Manager - Unity desktop indicator
ii account-plugin-facebook 0.12+16.04.20160126-0ubuntu1 all GNOME Control Center account plugin for single signon - facebook
ii account-plugin-flickr 0.12+16.04.20160126-0ubuntu1 all GNOME Control Center account plugin for single signon - flickr
ii account-plugin-google 0.12+16.04.20160126-0ubuntu1 all GNOME Control Center account plugin for single signon
-以下、略-
##6.2 パッケージに含まれているファイルの表示方法(-L)
CentOSの"rpm -ql"に相当する。
root@server:~# dpkg -L bc
/.
/usr
/usr/bin
/usr/bin/bc
/usr/share
/usr/share/doc
/usr/share/doc/bc
/usr/share/doc/bc/README
/usr/share/doc/bc/bc.html
/usr/share/doc/bc/examples
/usr/share/doc/bc/examples/ckbook.b
/usr/share/doc/bc/examples/pi.b
/usr/share/doc/bc/examples/primes.b
/usr/share/doc/bc/examples/twins.b
/usr/share/doc/bc/NEWS.gz
/usr/share/doc/bc/copyright
/usr/share/doc/bc/AUTHORS
/usr/share/doc/bc/changelog.Debian.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/bc.1.gz
/usr/share/doc-base
/usr/share/doc-base/bc
/usr/share/menu
/usr/share/menu/bc
/usr/share/info
/usr/share/info/bc.info.gz
##6.3 コマンドが含まれているパッケージ名を調べる方法(-S)
CentOSの"rpm -qf"に相当する。
コマンドのパス名を調べる。
root@server:~# which bc
/usr/bin/bc
コマンドのパス名をもとに、パッケージ名を調べる。bcコマンドはbcパッケージに含まれていることがわかる。
root@server:~# dpkg -S /usr/bin/bc
bc: /usr/bin/bc
bcパッケージのバージョンは"1.06.95-9build1"だとわかる。
root@server:~# dpkg -l |grep -w bc
||/ 名前 バージョン アーキテクチ 説明
+++-==================-===========================-============-================================================================================
ii bc 1.06.95-9build1 amd64 GNU bc arbitrary precision calculator language
##6.3 パッケージを削除する方法(-r)
root@server:~# dpkg -r tcpdump
(Reading database ... 216276 files and directories currently installed.)
Removing tcpdump (4.9.2-0ubuntu0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
##6.5 パッケージの詳細情報を確認する方法(apt show)
bcコマンドのパスを調べる。
root@server:~# which bc
/usr/bin/bc
bcコマンドが入っているパッケージ名を調べる。bcパッケージであることがわかる。
root@server:~# dpkg -S /usr/bin/bc
bc: /usr/bin/bc
bcパッケージの詳細情報を確認する。
root@server:~# apt show bc
Package: bc
Version: 1.06.95-9build1
Priority: optional
Section: math
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Ryan Kavanagh <rak@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 246 kB
Depends: libc6 (>= 2.14), libreadline6 (>= 6.0)
Homepage: http://ftp.gnu.org/gnu/bc/
Task: ubuntu-desktop, ubuntu-usb, print-server, kubuntu-desktop, edubuntu-desktop, edubuntu-usb, xubuntu-core, xubuntu-desktop, mythbuntu-desktop, lubuntu-core, ubuntustudio-desktop-core, ubuntustudio-desktop, ubuntu-gnome-desktop, ubuntukylin-desktop, ubuntu-mate-core, ubuntu-mate-desktop, ubuntu-mate-cloudtop
Supported: 5y
Download-Size: 82.6 kB
APT-Manual-Installed: yes
APT-Sources: http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
Description: GNU bc: 任意精度の計算言語
GNU bc is an interactive algebraic language with arbitrary precision which
follows the POSIX 1003.2 draft standard, with several extensions including
multi-character variable names, an `else' statement and full Boolean
expressions. GNU bc does not require the separate GNU dc program.
#7 サービスの起動、確認、停止方法(systemctl)
##7.1 サービスの起動方法
root@server:~# systemctl start ufw
root@server:~# systemctl status ufw
● ufw.service - Uncomplicated firewall
Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enabled)
Active: active (exited) since 日 2017-09-17 19:39:27 JST; 33s ago
Process: 1300 ExecStop=/lib/ufw/ufw-init stop (code=exited, status=0/SUCCESS)
Process: 1312 ExecStart=/lib/ufw/ufw-init start quiet (code=exited, status=0/SUCCESS)
Main PID: 1312 (code=exited, status=0/SUCCESS)
9月 17 19:39:27 server systemd[1]: Starting Uncomplicated firewall...
9月 17 19:39:27 server systemd[1]: Started Uncomplicated firewall.
9月 17 19:39:56 server systemd[1]: Started Uncomplicated firewall.
##7.2 サービスの停止方法
root@server:~# systemctl stop ufw
root@server:~# systemctl status ufw
● ufw.service - Uncomplicated firewall
Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enabled)
Active: inactive (dead) since 日 2017-09-17 19:41:01 JST; 1s ago
Process: 1321 ExecStop=/lib/ufw/ufw-init stop (code=exited, status=0/SUCCESS)
Process: 1312 ExecStart=/lib/ufw/ufw-init start quiet (code=exited, status=0/SUCCESS)
Main PID: 1312 (code=exited, status=0/SUCCESS)
9月 17 19:39:27 server systemd[1]: Starting Uncomplicated firewall...
9月 17 19:39:27 server systemd[1]: Started Uncomplicated firewall.
9月 17 19:39:56 server systemd[1]: Started Uncomplicated firewall.
#8 ファイアウォール(ufw)
ufwの使い方はここ(ufwコマンドの使い方)に移動しました。
#9 時刻同期
NTPのインストールはここを参考にしました。
##9.1 NTPパッケージのインストール
root@server:~# apt-get -y install ntp
##9.2 NTPサーバの登録
デフォルトだと非常に多くのNTPサーバと時刻同期をしていました。
自宅環境の時刻精度は重要ではないので、NICTのNTPサーバ(ntp.nict.jp)だけにしました。
root@server:~# vi /etc/ntp.conf
server ntp.nict.jp
##9.3 NTPの再起動
root@server:~# systemctl restart ntp
root@server:~# systemctl status ntp
● ntp.service - LSB: Start NTP daemon
Loaded: loaded (/etc/init.d/ntp; bad; vendor preset: enabled)
Active: active (running) since 日 2017-09-17 19:49:28 JST; 3s ago
Docs: man:systemd-sysv-generator(8)
Process: 4951 ExecStop=/etc/init.d/ntp stop (code=exited, status=0/SUCCESS)
Process: 4964 ExecStart=/etc/init.d/ntp start (code=exited, status=0/SUCCESS)
Tasks: 2 (limit: 512)
CGroup: /system.slice/ntp.service
mq4975 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 122:129
9月 17 19:49:28 server ntpd[4975]: Listen normally on 2 lo 127.0.0.1:123
9月 17 19:49:28 server ntpd[4975]: Listen normally on 3 eth0 192.168.0.220:123
9月 17 19:49:28 server ntpd[4975]: Listen normally on 4 lo [::1]:123
##9.4 NTPサーバの確認
時刻同期しているサーバを確認する。左端に*が付いたサーバが現在同期中のNTPサーバです。
root@server:~# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*golem.canonical 17.253.34.253 2 u 11 64 37 248.200 1.250 3.514
#10 AppArmorの使い方
#11 カーネルメッセージ
CentOSでは/var/log/messagesにカーネルメッセージが保存されていましたが、
Ubuntuでは/var/log/syslogに保存されるようです。
root@server:~# cat /var/log/syslog
Sep 17 18:24:13 server rsyslogd: [origin software="rsyslogd" swVersion="8.16.0" x-pid="672" x-info="http://www.rsyslog.com"] start
Sep 17 18:24:13 server systemd-modules-load[326]: Inserted module 'lp'
Sep 17 18:24:13 server systemd-modules-load[326]: Inserted module 'ppdev'
#12 カーネルのデバッグ方法
##12.1 カーネルシンボル情報のインストール
crashやsystemtapを使うためには、カーネルのシンボル情報が必要です。
まず、カーネルのシンボル情報をインストールします。
インストール方法は、ここを参考にしました。
root@server:~# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C8CAB6595FDFF622
Executing: /tmp/tmp.lpyWq7rDI1/gpg.1.sh --keyserver
keyserver.ubuntu.com
--recv-keys
C8CAB6595FDFF622
gpg: 鍵5FDFF622をhkpからサーバkeyserver.ubuntu.comに要求
gpg: 鍵5FDFF622: 公開鍵"Ubuntu Debug Symbol Archive Automatic Signing Key (2016) <ubuntu-archive@lists.ubuntu.com>"をインポートしました
gpg: 処理数の合計: 1
gpg: インポート: 1 (RSA: 1)
root@server:~#
コード名を調べる。xenialであることがわかる。
root@server:~# lsb_release -c|awk '{print $2}'
xenial
コード名の"xenial"を入れたリポジトリを作成する。
root@server:~# vi /etc/apt/sources.list.d/ddebs.list
root@server:~# cat /etc/apt/sources.list.d/ddebs.list
deb http://ddebs.ubuntu.com/ xenial main restricted universe multiverse
deb http://ddebs.ubuntu.com/ xenial-security main restricted universe multiverse
deb http://ddebs.ubuntu.com/ xenial-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com/ xenial-proposed main restricted universe multiverse
root@server:~# apt-get update
root@server:~# apt-get install linux-image-$(uname -r)-dbgsym
##12.2 crashコマンドのインストールと起動方法
crashコマンドの使い方は「crashコマンドの使い方」を参照ください。
root@server:~# apt-get -y install crash
root@server:~# crash --version
crash 7.1.4
crashコマンドを実行する。
root@server:~# crash /usr/lib/debug/boot/vmlinux-4.4.0-21-generic /boot/System.map-4.4.0-21-generic
システムの状態を確認する。
crash> sys
SYSTEM MAP: /boot/System.map-4.4.0-21-generic
DEBUG KERNEL: /usr/lib/debug/boot/vmlinux-4.4.0-21-generic (4.4.0-21-generic)
DUMPFILE: /proc/kcore
CPUS: 2
DATE: Sun Sep 17 20:25:49 2017
UPTIME: 00:52:42
LOAD AVERAGE: 0.50, 0.54, 0.37
TASKS: 248
NODENAME: server
RELEASE: 4.4.0-21-generic
VERSION: #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016
MACHINE: x86_64 (2394 Mhz)
MEMORY: 2 GB
##12.3 systemtapのインストール
systemtapの使い方は「SystemTapの使い方」を参照ください。
root@server:~# apt-get install -y systemtap gcc
root@server:~# stap -V
Systemtap translator/driver (version 2.9/0.165, Debian version 2.9-2ubuntu2 (xenial))
Copyright (C) 2005-2015 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
enabled features: AVAHI LIBSQLITE3 NLS NSS TR1_UNORDERED_MAP
スクリプトを作成する。
root@server:~# vi tp.stp
root@server:~# cat tp.stp
probe kernel.function("ip_output@net/ipv4/ip_output.c")
{
printf("TIME=%s\n", tz_ctime(gettimeofday_s()))
}
スクリプトを実行する。
root@server:~# stap -vg tp.stp
Pass 1: parsed user script and 110 library script(s) using 117708virt/44180res/6596shr/37696data kb, in 290usr/50sys/340real ms.
Pass 2: analyzed script: 1 probe(s), 6 function(s), 1 embed(s), 0 global(s) using 197928virt/123320res/7480shr/117916data kb, in 1170usr/70sys/1277real ms.
Pass 3: translated to C into "/tmp/stapI6G0gv/stap_f057be4753d03b9f213541f28024aadf_5310_src.c" using 197928virt/123576res/7736shr/117916data kb, in 10usr/0sys/16real ms.
Pass 4: compiled C into "stap_f057be4753d03b9f213541f28024aadf_5310.ko" in 19720usr/3750sys/26960real ms.
Pass 5: starting run.
TIME=Sun Sep 17 20:35:34 2017 JST
TIME=Sun Sep 17 20:35:34 2017 JST
TIME=Sun Sep 17 20:35:34 2017 JST
-以下、略-
#13 アプリケーションのデバッグ方法
##13.1 coreファイルの採取設定
coreファイルサイズを確認する。0バイトになっている。
root@server:~# ulimit -c
0
coreファイルサイズを無限大に設定する。
root@server:~# ulimit -c unlimited
root@server:~# ulimit -c
unlimited
生成するcoreファイル名にプロセス名とPIDを含めるように設定する。
root@server:~# echo 'core.%e.%p' > /proc/sys/kernel/core_pattern
sleepプロセスを生成する。
root@server:~/core# sleep 600&
[1] 15914
sleepプロセスのPIDを確認する。PID=15914であることがわかる。
root@server:~/core# ps -C sleep
PID TTY TIME CMD
15914 pts/1 00:00:00 sleep
sleepプロセス(PID=15914)にSIGSEGVを送信する。
root@server:~/core# kill -SIGSEGV 15914
root@server:~/core#
[1]+ Segmentation fault (コアダンプ) sleep 600
ファイルを確認する。sleepのcoreファイルが生成されたことがわかる。
root@server:~/core# ls
core.sleep.15914
##13.2 シンボル情報のインストール
アプリケーションのシンボル情報のインストールはここを参考にしました。
root@server:~/core# ls
core.sleep.16759
root@server:~/core# which sleep
/bin/sleep
gdbを起動する。sleepにシンボル情報が含まれていない旨のメッセージが表示される。
root@server:~/core# gdb /bin/sleep core.sleep.16759
-中略-
Reading symbols from /bin/sleep...(no debugging symbols found)...done
sleepが含まれているパッケージを調べる。coreutilsパッケージにsleepが含まれていることがわかる。
root@server:~/core# which sleep
/bin/sleep
root@server:~/core# dpkg -S /bin/sleep
coreutils: /bin/sleep
シンボル情報が含まれたcoreutilsパッケージを検索する。coreutils-dbgsym というパッケージであることがわかる。
root@server:~/core# apt-cache search coreutils
coreutils-dbgsym - debug symbols for package coreutils
coreutils-dbgsym パッケージをインストールする。
root@server:~/core# apt-get -y install coreutils-dbgsym
バックトレースを表示する。シンボル名が表示されていることがわかる。
(gdb) bt full
#0 0x00007f193f4512f0 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:84
No locals.
#1 0x00000000004040bf in rpl_nanosleep (requested_delay=requested_delay@entry=0x7fff704ffff0,
remaining_delay=remaining_delay@entry=0x0) at lib/nanosleep.c:85
limit = 2073600
seconds = 600
intermediate = {tv_sec = 600, tv_nsec = 0}
#2 0x0000000000403f18 in xnanosleep (seconds=seconds@entry=600) at lib/xnanosleep.c:51
ts_sleep = {tv_sec = 600, tv_nsec = 0}
#3 0x000000000040169a in main (argc=<optimized out>, argv=<optimized out>) at src/sleep.c:145
i = <optimized out>
seconds = <optimized out>
ok = <optimized out>
#14 カーネルを変更する方法
下記情報を参考にしました。
grubでブートするカーネルを変更する方法
Ubuntu 12.10のGRUB2でデフォルトカーネルを変更するにはどうしたらいいの?
Submenu Designation Examples
現在のカーネル版数を確認する。
root@server:~# uname -r
4.4.0-96-generic
GRUBの設定ファイルに指定できる文字列は''で囲まれた部分のようです。
root@server:~# less /boot/grub/grub.cfg
menuentry 'Ubuntu, with Linux 4.4.0-96-generic' --class ubuntu
menuentry 'Ubuntu, with Linux 4.4.0-96-generic (upstart)' --class ubuntu
menuentry 'Ubuntu, with Linux 4.4.0-96-generic (recovery mode)' --class ubuntu
menuentry 'Ubuntu, with Linux 4.4.0-21-generic' --class ubuntu
menuentry 'Ubuntu, with Linux 4.4.0-21-generic (upstart)' --class ubuntu
menuentry 'Ubuntu, with Linux 4.4.0-21-generic (recovery mode)' --class ubuntu
GRUB_HIDDEN_TIMEOUTを以下のように変更する。
root@server:~# vi /etc/default/grub
#GRUB_HIDDEN_TIMEOUT=0
GRUB_DEFAULT="Ubuntu, with Linux 4.4.0-21-generic"
GRUBの設定ファイルを更新する。しかし、Warningメッセージが表示(★)される。
root@server:~# update-grub
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Linux イメージを見つけました: /boot/vmlinuz-4.4.0-96-generic
Found initrd image: /boot/initrd.img-4.4.0-96-generic
Linux イメージを見つけました: /boot/vmlinuz-4.4.0-21-generic
Found initrd image: /boot/initrd.img-4.4.0-21-generic
★Warning: Please don't use old title `Ubuntu, with Linux 4.4.0-21-generic' for GRUB_DEFAULT, use `Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-21-generic' (for versions before 2.00) or `gnulinux-advanced-0879c06f-f8f7-4639-b623-75033afdddec>gnulinux-4.4.0-21-generic-advanced-0879c06f-f8f7-4639-b623-75033afdddec' (for 2.00 or later)
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
完了
仮想マシンを再起動する。
root@server:~# shutdown -r now
カーネル版数を確認する。版数が変更されていないことがわかる。
root@server:~# uname -r
4.4.0-96-generic
Warningメッセージにしたがって、GRUB_DEFAULTを以下のように変更する。
root@server:~# vi /etc/default/grub
#GRUB_HIDDEN_TIMEOUT=0
#GRUB_DEFAULT="Ubuntu, with Linux 4.4.0-21-generic"
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.4.0-21-generic"
GRUBの設定ファイルを更新する。
root@server:~# update-grub
仮想マシンを再起動する。
root@server:~# shutdown -r now
カーネル版数を確認する。4.4.0-21-genericに変更できたことがわかる。
root@server:~# uname -r
4.4.0-21-generic
#15 conntrackコマンドのインストール方法
root@server:~# apt install conntrack
root@server:~# conntrack --version
conntrack v1.4.3 (conntrack-tools)
#メモ
root@server:~# apt install ulogd
root@server:~# echo "255" > /proc/sys/net/netfilter/nf_conntrack_log_invalid
root@server:~# tail -f /var/log/ulog/syslogemu.log
Sep 20 21:16:05 server nf_ct_tcp: invalid packet ignored in state SYN_RECV IN= OUT= MAC= SRC=192.168.0.220 DST=192.168.0.30 LEN=44 TOS=00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=11111 DPT=1684 SEQ=1379058353 ACK=1891276105 WINDOW=29200 ACK SYN URGP=0 MARK=0
Sep 20 21:16:07 server nf_ct_tcp: invalid packet ignored in state SYN_RECV IN= OUT= MAC= SRC=192.168.0.220 DST=192.168.0.30 LEN=44 TOS=00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=11111 DPT=1684 SEQ=1379058353 ACK=1891276105 WINDOW=29200 ACK SYN URGP=0 MARK=0
-以下、略-
#X 参考情報
debian パッケージの作成方法
debianパッケージのつくり方