1. サービス管理 サービスの管理ファイル 実体は「/lib/systemd/system/mssql-server.service」である
「systemctl enable mssql-server.service」を実行することで、
「/etc/systemd/system/multi-user.target.wants/mssql-server.service」にシンボリックリンクが作成される
設定変更
Configure SQL Server on Linux with the mssql-conf tool
https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-mssql-conf
•
一部の設定は「mssql-conf」を使用して設定を変更
ファイアウォール Ubuntu
ufwの基本操作
https://qiita.com/RyoMa_0923/items/681f86196997bea236f0
•
ufw
RHEL
4.5. ファイアウォールの使用
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/security_guide/sec-using_firewalls
•
firewalld
リモート接続 リモート管理
インフラエンジニアじゃなくても押さえておきたいSSHの基礎知識
https://qiita.com/tag1216/items/5d06bad7468f731f590e
•
ssh
ファイルコピー
SCP (1)
http://euske.github.io/openssh-jman/scp.html
•
scp
ソフトウェア更新 Ubuntu パッケージ情報 (リポジトリ情報) の更
新
apt-get update
インストールされているパッケージの更
新
apt-get upgrade
リポジトリ上のファイルを使用しパッ
ケージの更新
upgrade とことなり、新規のパッケー
ジの追加/不要なパッケージの削除も実
施
Linux のディストリビューションバー
ジョンも更新される
apt-get dist-upgrade
自動更新 「/etc/apt/apt.conf.d/20auto-upgrades」で設定されている
「/var/log/unattended-upgrades」にログが出力される
• Ubuntu 16.04: 自動アップデート / アップグレードの設定をする
https://www.hiroom2.com/2016/05/12/ubuntu-16-04%E3%81%A7%E8%87%AA%E5%8B%95%E3%82%A2%E3%83%83%E3%83%97%E3%83%87%E3%83%
BC%E3%83%88-%E3%82%A2%E3%83%83%E3%83%97%E3%82%B0%E3%83%AC%E3%83%BC%E3%83%89%E3%81%AE%E8%A8%AD%E5%AE%9A%E3%
82%92%E3%81%99%E3%82%8B/
「apt-xxxx」のsystemd ユニットで制御が行われている
(例 : 実行スクリプトについては、「apt-daily.service」実行タイミングの制御については「apt-daily.timer」で制御されている)
ベストプラクティス SQL
Server
on
Linux
Performance best practices and configuration guidelines for SQL Server 2017 on Linux•
https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-performance-best-practices
SQL Server の設定
PROCESS AFFINITY の指定 ALTER SERVER CONFIGURATION
SET PROCESS AFFINITY NUMANODE = 0 TO <Max NUMA Node ID>
tempdb のデータファイルの分割 SQL Server on Linux は、インストール時の tempdb 分割が行われないため、インストール後に分割する
mssql-conf ツールを使用したメモリ設定 デフォルトでは SQL Server が使用するメモリは 80% に制限されているため、大容量のメモリを搭載している場合、
残りの 20% のサイズによっては、上限緩和を検討する (本設定は SQL Server の max server memroy とは別の設定)
Linux の設定
CPU CPU の電力制御のユーティリティ apt install -y cpufrequtils
cpufreq-info
CPU クロックのガバナー sudo cpupower frequency-info
sudo cpupower frequency-set -g performance
パフォーマンスと電源消費効率のバランス x86_energy_perf_policy -v 'performance'
CPU クロックの下限 tuned を使用して設定を実施
2.5. TUNED および KTUNE
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/6/html/power_management_guide/tuned
•
min_perf_pct=100
C-State C1 のみにする
How to set intel_idle.max_cstate=1
https://askubuntu.com/questions/749349/how-to-set-intel-idle-max-cstate-1
•
sudo vi /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="intel_idle.max_cstate=1"
sudo update-grub
reboot
ディスク Read-Ahead のブロックサイズ blockdev --report
blockdev -v --setra 4096 /dev/sda
sysctl によるカーネルパラメーターの変更 設定の確認 cat /proc/sys/kernel/sched_min_granularity_ns
sudo sysctl -a
設定の変更 sudo sysctl -w kernel.sched_min_granularity_ns=10000000
sudo sysctl -w kernel.sched_wakeup_granularity_ns=15000000
sudo sysctl -w vm.dirty_ratio=40
sudo sysctl -w vm.dirty_background_ratio=10
sudo sysctl -w vm.swappiness=10
sudo sysctl -p
NUMA 複数 NUMA ノード環境での自動 NUMA バラン
シングの無効化
sudo sysctl -w kernel.numa_balancing=0
sudo sysctl -p
仮想アドレス空間 メモリマップ数の上限の変更
(65536 (64KB) -> 262144 (256KB))
sudo sysctl -w vm.max_map_count=262144
sudo sysctl -p
マウントオプション SQL Server のデータ/ログファイルのファイル
システムのマウントオプションの設定
(relatime -> noatime )
設定の確認 mount
または、
cat /proc/mounts
設定の変更 vi /etc/fstab
該当のボリュームに「noatime」オプションを追加する
3.9. RELATIME ドライブアクセス最適化
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/6/html/power_management_guide/relatime
•
※国内のブログの検証結果では、realtime / noattime の変更による明確な性能差は確認できないという情報が多い
Huge Page 透過的な Huge Page の有効化 ほとんどの Linux 環境では有効になっている。
How to disable Transparent Huge Pages (THP) in Ubuntu 16.04LTS
https://stackoverflow.com/questions/44800633/how-to-disable-transparent-huge-pages-thp-in-ubuntu-16-04lts
•
Red Hat Enterprise Linux 7 で transparent hugepages (THP) を無効にする
https://access.redhat.com/ja/node/1565043
•
Huge Page まとめ
https://gist.github.com/shino/5d9aac68e7ebf03d4962a4c07c503f7d
•
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /proc/meminfo
Swap ファイル swap ファイルの適切な設定
Windows エンジニア向け SQL Server on Linux のためのスキルアップデート
2017年11月20日 8:05
SQL Server on Linux - 1 ページ
2. Swap ファイル swap ファイルの適切な設定
Ubuntu 16.10 その79 - スワップ領域をパーティションからファイルに移行させるには
https://kledgeb.blogspot.jp/2016/12/ubuntu-1610-79.html
•
swap ファイルの確認 swapon
仮想マシンでの実行時 動的メモリ割り当て (Dynamic Memory) を使
用しない
仮想マシンのメモリ割り当てとして、動的メモリ割り当てによる可変的なメモリ割り当てを実行しない
OOM Killer OOM Killer という動作が存在していることの認
識
メモリ/スワップの枯渇の可能性が出た場合に、メモリを消費しているプロセスを停止させる動作
Linux OOM Killerについて
https://qiita.com/konpyu/items/20d1989d1251d805cf3b
•
LinuxにおけるOOM発生時の挙動
https://qiita.com/satoru_takeuchi/items/792cb21b5d1b96300f99
•
メモリ不足時に大事なプロセスが OOM Killer に殺されないようにする
http://s.webry.info/sp/vogel.at.webry.info/201605/article_1.html
•
エラーログに対応する~OOM Killer編
https://thinkit.co.jp/article/736/1?page=0%2C1
•
OOM Killer – How To Create OOM Exclusions in Linux•
https://backdrift.org/oom-killer-how-to-create-oom-exclusions-in-linux
Linux - OOM Killer の発動を抑制!•
https://www.mk-mode.com/octopress/2016/03/15/linux-control-oomkiller/
inux/mm/oom_kill.c•
http://elixir.free-electrons.com/linux/v4.14.3/source/mm/oom_kill.c
9.6. システムのユニットファイルの作成および変更
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/system_administrators_guide/sect -managing_services_with_systemd-unit_files
•
OOM Killer に対しての考慮
swap ファイルのサイズを適切に設定•
mssql-conf で memory.memorylimitmb を適切に設定
OOM Killer の対象となりえる
プロセスの確認
apt install -y dstat
dstat --top-oom
スコアの確認 grep "" /proc/*/oom_score
ps -e | grep "sqlservr" | awk '{system("cat /proc/"$1"/oom_score")}'
OOM Killer の対象外にする echo "-17" > /proc/[pid]/oom_adj
ps -e | grep "sqlservr" | awk '{system("echo -17 > /proc/"$1"/oom_adj")}'
sudo echo '*/1 * * * * root ps -e | grep "sqlservr" | awk '''{system("echo -1000 > /proc/"$1"/oom_score_adj")}''' > /dev/null 2>&1' > /etc/cron.d/sqlservr_oom
または、
sudo echo '*/1 * * * * root ps -e | grep "sqlservr" | awk '''{system("echo -17 > /proc/"$1"/oom_adj")}''' > /dev/null 2>&1' > /etc/cron.d/sqlservr_oom
OOM Killer の設定の確認 sudo sysctl -r | grep "oom"
PASS Summit 2017 - SQL Server on Linux: DBA focused lessons learned from early deployments•
Inside SQL Server 2017 on Linux
https://onedrive.live.com/?authkey=%21ABg4T%5Fv1nZbdDbE&id=233BB03122CBD248%21249941&cid=233BB03122CBD248
•
SQL Server 2017 on Linux - Administration
SQL Server 2017 on Linux - Administration
•
How to safeguard SQL Server on Linux from OOM-Killer
https://blogs.msdn.microsoft.com/psssql/2017/10/17/how-to-safeguard-sql-server-on-linux-from-oom-killer/
•
Docker ローカルまたはリモートストレージ / コンテナーボリュームのマウントを検討•
Docker ボリュームストレージプラグインの活用•
Docker run の実行時に --cap-add sys_ptrace の活用•
事前の
IO 検証
FIO / dd / Iometer 等による事前のディスク性能の検証•
SQL Server on Linux では、ファイルの瞬時初期化はデフォルトで有効となっている•
マウントしたドライブを使用している場合「/etc/fstab」の「noattime」の設定の有効化•
SQL アカウント / グループ アカウント / グループともに mssql が使用されているため、バックアップや BULK INSERT をするファイルに対してこれらのアクセス権が必要となる
id mssql
uid=999(mssql) gid=999(mssql) groups=999(mssql)
コマンドラインから SQL Server を実行する場合、「sudo -u mssql /opt/mssql/bin/sqlservr」により起動する。
パフォーマンスツール PSSDiag https://blogs.msdn.microsoft.com/sqlcat/2017/08/11/collecting -performance-data-with-pssdiag-for-sql-server-on-linux/
https://github.com/Microsoft/DiagManager/tree/master/LinuxPSSDiag
sysstat https://github.com/sysstat/sysstat
プロセス構成
メインの PID で、SQL PAL Monitor が動作し、子プロセスで、SQL PAL / sqlservr.exe が動作している•
SQL Server のプロセス構成•
SQL Server Agent / Full Text Search をインストールした場合、sqlservr のプロセス内で動作することになるため、個別にサービスを停止することはできない•
ディレクトリ /opt/mssql バイナリ
/var/opt/mssql データ/ログ
Windows のディレクトリとの対応
Filesystem Hierarchy Standard
https://ja.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
•
Windows Linux
/
C:Users<ユーザー名> /home/<ユーザー名>
C:Windows /bin
/sbin
%WINDOWSTEMP% /tmp
C:Program Files /opt
/usr/bin
/usr/local
ライブラリ / ソースコード / バイナリ /usr
システムログ /var
コマンド Windows Linux
dir ls
cd cd
md mkdir
rd rmdir
del rm
echo echo
type cat
more more
copy cp
move mv
ren mv
find / findstr grep
tail
net start / net stop systemctl
イベントログ journalctl
/var/log/messages
attrib chmod / chown
ログ RHEL /var/log/messages
Ubuntu /var/log/syslog
SQL Server ログ /var/opt/mssql/log
SQL Server on Linux - 2 ページ
3. SQL Server ログ /var/opt/mssql/log
セットアップログ Debian Pakcage : /var/log/dpkg.log
RPM:/var/log/yum.log
オフラインインストール RHEL yumdownloader --downloadonly --resolve --destdir=/home/user/offlineistall mssql-server
Ubuntu apt-get download mssql-server
apt-cache depends mssql-server
GitHubサンプル https://github.com/denzilribeiro/sqlunattended
データディスクのマウント The systemd unit file for the SQL server should be locally extended by a dependency on the /datadir this will make sure the s tart is done after the mount and the unmount waits for the stop. The most generic option to do this would be
RequiresMountsFor=/datadir
I think it automatically depend on the installation path of the scripts already.
Note that you do not need to modify the systemd unit files in the library directory but you can amend them in the /etc/system d/system/<sqlserver>.service
systemdでmount完了を待ってサービスを起動する
https://qiita.com/ko-zu/items/3759144c53904afe6b76
•
systemctl show --no-pager mssql-server | grep "RequiresMountsFor"
mkdir /lib/systemd/system/mssql-server.service.d
vi /lib/systemd/system/mssql-server.service.d/mssql-server.conf
[Unit]
RequiresMountsFor=/mnt/backup
systemctl daemon-reload
systemctl show --no-pager mssql-server | grep "RequiresMountsFor"
システムデータベースの再構築 /opt/mssql/bin/sqlservr -c --setup --force-setup
システムデータベースの移動 tempdb / msdb / model : ALTER DATABASE で移動•
master : 移動することはできない•
パフォーマンスモニタリング コマンドライン
https://www.cyberciti.biz/tips/top-linux-monitoring-tools.html
http://www.brendangregg.com/linuxperf.html
モニタリング top [Linux] ある一定期間のtopコマンドの結果をファイルに出力する(備忘録)•
https://qiita.com/dkwnm/items/a147d30397676c9340ff
topコマンドの使い方•
貼り付け元 <https://qiita.com/k0kubun/items/7368c323d90f24a00c2f>
htop htopコマンドで覚えておきたい使い方11個•
https://orebibou.com/2016/05/htop%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%A7%E8%A6%9A%E3%81%88%E3%81%A6%E3%81%8A%E3%81%8D%E3%81%9F%E3%81%84%
E4%BD%BF%E3%81%84%E6%96%B911%E5%80%8B/
sar sar(sysstat)によるボトルネック特定
https://qiita.com/kidach1/items/07637a5baa0da7d52e6a
•
vmstat Vmstat の出力結果はどのように解釈すれば良いですか?•
https://access.redhat.com/ja/node/3054501
ディスク iostat iostat -x sda -c 2 -t > stats.log iostat how do I set up a logging•
https://serverfault.com/questions/227357/iostat-how-do-i-set-up-a-logging
iostat の await, svctm の 見かた、考え方(※10/30スライド修正)•
https://qiita.com/ora_gonsuke777/items/66212505bf9950b056a2
iostat コマンドの読み方•
https://blogs.oracle.com/yappri/iostat
df dfコマンドについてまとめました【Linuxコマンド集】•
https://eng-entrance.com/linux-command-df
lsblk
メモリ memstat Linux のメモリー管理(メモリ-が足りない?,メモリーリークの検出/防止)•
http://www.math.kobe-u.ac.jp/HOME/kodama/tips-free-memory.html
linuxにおけるメモリと関連コマンド(free, vmstat, top, sar)•
http://sisidovski.hatenablog.com/entry/2015/07/07/072150
Linux負荷監視コマンドまとめ•
https://qiita.com/aosho235/items/c4d6995743dd1dac16e1
sar sar(sysstat)によるボトルネック特定•
https://qiita.com/kidach1/items/07637a5baa0da7d52e6a
ネットワーク ifconfig / ip
netstat Linuxでプロセスが何のポート使っているかを調べる•
https://qiita.com/sonoshou/items/cc2b740147ba1b8da1f3
プロセス ps psコマンドについて詳しくまとめました 【Linuxコマンド集】
https://eng-entrance.com/linux-command-ps
•
モニタリングユーティリティ
Nagios
Collectd
Telegraf
Monitoring SQL on Linux https://blogs.msdn.microsoft.com/sqlcat/2017/07/03/how-the-sqlcat-customer-lab-is-monitoring-sql-on-linux/
https://github.com/Microsoft/mssql-monitoring
可用性 Pacemaker High Availability Add-On リファレンス•
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/high_availability_add-on_reference/
第1章 Pacemaker を使用した Red Hat High Availability クラスターの作成•
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/high_availability_add-on_administration/ch-startup-haaa>
第3章 pcs コマンドラインインターフェース
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/high_availability_add-on_reference/ch-pcscommand-haar
•
付録B pcs コマンドの使用例
https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html/Configuring_the_Red_Hat_High_Availability_Add -On_with_Pacemaker/ap-configfile-HAAR.html
•
SQL Server on Linux - 3 ページ