Linux Tips

Revision as of 10:22, 14 June 2022 by Nxhack (talk | contribs)
  • tcp_wrappers IPv6

IPv6 については CIDR 表記ができる

ALL : [3ffe:505:2:1::]/64
  • ccache 4.1 が遅い

compression がデフォで有効になっていた。非力な環境なので無効にした。

compression = false

すでに圧縮されちゃったキャッシュはこのコマンドで戻る。

ccache --recompress uncompressed

さらに、これはやりすぎかもしれないが...

sloppiness = include_file_mtime, include_file_ctime, time_macros, pch_defines, file_stat_matches, locale

やはりやりすぎだった。ある状況で間違ってビルドされた。いまは time_macros, pch_defines のみで検証中。

  • varnish 起動ミス

超ワークアラウンドだが、/etc/rc.local に書いておく

/usr/bin/install -o varnishlog -g varnish -d /run/varnish
/usr/bin/install -o varnishlog -g varnish -d /run/varnishlog
/usr/bin/install -o varnishlog -g varnish -d /run/varnishncsa
  • 壊れた symlink 一覧
find . -xtype l
  • icu めも
ICU Data Library Customizer
icupkg icudt57l.dat icudt62l.dat -w
  • めもめも
cat /sys/devices/system/cpu/vulnerabilities/l1tf
  • HTTP/2 化

hitch + varnish5 で簡単

curl -L https://packagecloud.io/varnishcache/varnish5/gpgkey | sudo apt-key add -
echo "deb https://packagecloud.io/varnishcache/varnish5/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/varnishcache_varnish5.list
sudo apt-get update
varnish6 はまだ安定しないので 5.x を使う

varnish の起動オプションに追加

-p feature=+http2 -p thread_pools=2 -p thread_pool_min=450 -p thread_pool_max=5000 -p syslog_cli_traffic=off -t 120

hitch.confに追加

alpn-protos = "h2, http/1.1"
  • https 化

そろそろヤバイので https 化した。現在の構成が apache2 + varnish なので、いろいろ調査した結果 hitch を使うことにした。

http://hitch-tls.org/

Ubuntu のパッケージは古かったので PPA で導入。

Ubuntu PPA aiming for latest hitch on latest ubuntu.
sudo add-apt-repository ppa:lasse-karstensen/hitch
sudo apt-get update
sudo apt-get -y install hitch

hitch + varnish + apache2 + Let's Encrypt の統合の参考はこれが良かった。

Let's Encrypt with Hitch and Varnish (CentOS7) Tutorial

Ubuntu のパッケージに letsencrypt というのがあるが、これは古くて hitch 対応してないらしいので PPA 導入。

https://launchpad.net/~certbot/+archive/ubuntu/certbot
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get -y install certbot

基本的には CentOS7 のドキュメントをなぞるのでよいが、 hitch.conf を作っておく。(手順にしたがって pem-file を追加する)

frontend = {
  host = "*"
  port = "443"
}
backend = "[127.0.0.1]:6086"    # 6086 is the default Varnish PROXY port.
workers = 2                     # number of CPU cores

backlog = 1024
keepalive = 3600
syslog = on

ciphers = "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"

daemon = off
user = "_hitch"
group = "_hitch"

# Enable to let clients negotiate HTTP/2 with ALPN. (default off)
# alpn-protos = "h2, http/1.1"

# run Varnish as backend over PROXY; varnishd -a :80 -a localhost:6086,PROXY ..
write-proxy-v2 = on             # Write PROXY header
certbot-renew
certbot-renew.timer
が無いので renew は自分で crontab に書く
00 04 25 * * /usr/bin/certbot renew && systemctl restart hitch

certbot の --post-hook は、

--post-hook="systemctl restart hitch"

varnish で強制的に https に redirect する。

https://github.com/varnish/hitch/wiki/FAQ
https://varnish-cache.org/trac/wiki/VCLExampleRedirectInVCL

コンテンツ側の対処

https://www.mediawiki.org/wiki/Manual:$wgServer
https://ja.wordpress.org/plugins/really-simple-ssl/

HSTS

https://github.com/varnish/hitch/wiki/FAQ#hsts-with-hitch-and-varnish
A+にしたいのでやってみた

varnish h2 が安定したら HTTP/2 にする

https://packagecloud.io/varnishcache
varnish5 いれたら簡単にでけたw
  • varnish が 404 のまま
sub vcl_backend_response {
    # Don't cache 404 responses
    if ( beresp.status == 404 ) {
        set beresp.ttl = 3s;
    }
}
  • ubuntu 16.04 systemd 環境の varnish と logrotate
mkdir /run/varnish
chown varnishlog:varnish /run/varnish
Type=forking
ExecStartPre=/usr/bin/install -o varnishlog -g varnish -d /run/varnish
ExecStart=/usr/bin/varnishlog -D -a -w /var/log/varnish/varnish.log -P /run/varnish/varnishlog.pid
PIDFile=/run/varnish/varnishlog.pid
Type=forking
ExecStartPre=/usr/bin/install -o varnishlog -g varnish -d /run/varnish
ExecStart=/usr/bin/varnishncsa -D -a -w /var/log/varnish/varnishncsa.log -P /run/varnish/varnishncsa.pid
PIDFile=/run/varnish/varnishncsa.pid
  postrotate
    /bin/kill -HUP `cat /run/varnish/varnishlog.pid 2>/dev/null` 2> /dev/null || true
  endscript
  postrotate
    /bin/kill -HUP `cat /run/varnish/varnishncsa.pid 2>/dev/null` 2> /dev/null || true
  endscript


  • ccache

.bashrc に

USE_CCACHE=1
export USE_CCACHE
PATH="/usr/lib/ccache:$PATH"
export PATH
  • Fail2Ban

今更ながらですが、Fail2ban実験中。

いままで、つつかれるのは仕方がないと放置してたのですが...
  • たんなるメモ

OpenWrt / LEDE とかクロスコンパイル環境では、やたらと PATH が深くなりがち。このためにいろいろトラブルがでる。

execvp: printf: Argument list too long.
これはパス名がながくて、引数のサイズ制限をこえたということ。対処は PATH を短くするか、xargs つかってうまく逐次処理する。
getconf ARG_MAX
bad interpreter: No such file or directory
shellbang でもインタープリターのフルパス名でハマることもある。逃げ方は exec hoge 等のラッパかます等。
80桁


  • たんなるメモ
Use 'apt-get autoremove' to remove them.
  • VirtualBox + Ubuntu システム時刻

Windows のシステム時刻がローカルタイム(JST)なので、Ubuntu の /etc/default/rcS で

# assume that the BIOS clock is set to UTC time (recommended)
#UTC=yes
UTC=no
  • Ubuntu unattended-upgrades サードパーティ レポジトリの扱い

Origin と Suite を指定してくれてないものをどうすればよいのか...

Unattended-Upgrade::Allowed-Origins {
    "*:*";
};

大胆に *:* してテスト中。

    "Sensu:sensu";
    "LP-PPA-ondrej-php:${distro_codename}";
    "elastic:stable";


  • たんなるメモ
dpkg-reconfigure keyboard-configuration
  • Hey! MAN!!!

漢なら run as root B)

漢なら Disable Ubuntu command-not-found

.bashrc に

unset command_not_found_handle
  • メモリー系いろいろ
echo -17 > /proc/<PID>/oom_adj

sshd とかは起動スクリプトで -17 に設定されている

vm.overcommit_memory=2
vm.overcommit_ratio=90

overcommit_ratio は環境による。メモリー逼迫してる場合はこれやると危険かも。

  • service - run a System V init script

ふむ

man 8 service
service SCRIPT COMMAND

# service mysql restart

  • cron-apt
apt-get install cron-apt
/etc/cron-apt/config

APTCOMMAND=/usr/bin/aptitude
MAILTO="someone@somewhere"
/etc/cron-atp/action.d/5-upgrade

safe-upgrade -y -o APT::Get::Show-Upgraded=true
/etc/cron.d/cron-apt

実行時間適当に変えてくれてる
  • つかえるかな?
cpulimit
  • Cluster SSH

おもろい

Cluster SSH - Cluster Admin Via SSH
  • たんなるメモ
vm.swappiness=0
kernel.panic_on_oops=1
kernel.panic=1
mount -o barrier=0
調査中...
  • OOM Killer を避ける
# echo -17 > /proc/<pid of sshd>/oom_adj
Linux performance tuning & stabilization tips (mysqlconf2010)
デフォでなってるな
  • 127.0.1.1 の話と、localdomain の話
いろいろ厳密化してるなぁ
localhost. と hostname 名前解決の分離
Debian Reference - Network configuration
UbuntuNote - Ubuntuのメモ
めも - 127.0.1.1
Net::SMTPでSMTPのHELO/EHLOにデフォルトで不正なホスト名を使用
たぶん、この議論を引き起こした遠因はこれかな
SecuriTeam - Common DNS Misconfiguration can Lead to "same Site" Scripting
yebo blog: Same-Site Scripting
  • mount bind
ふむ リハビリ中
mount --bindが便利 - komamitsu.log
Linux/ディレクトリにディレクトリをマウントする - discypus
  • relatime
ほー知らんかった3...(かなりリハビリ必要やな)
relatimeがどこで実装されているのか調べてみた
最新のFedoraとUbuntuではrelatimeもnoatimeもいらない?
relatimeが標準に
  • ディスクI/Oとniceレベル
ほー知らんかった2...
ドライバに変数を渡すのにうってつけの方法
ほえほえ ionice
mediate disk access with ionice(1).
  • Linuxにおけるメモリの開放
ほー知らんかった...
第10回:メモリ管理で安定稼動
DB2 V9.1以降でSTMMを使用する場合のOSのメモリー関連設定の注意事項 (DM-08-009)
続 @ITのmeminfoの見方の説明が完全に間違っている件について
sysctl -w vm.drop_caches=1
  • Linux TCP Tuning
TCP Tuning Guide - Linux TCP Tuning
  • Jetty TCP Tuning
Jetty - Addressing High TCP Slot Usage
  • たんなるメモ15
わすれもの
/usr/bin/setterm -blank 0 -store > /dev/tty1
  • よけいなお世話:)
tune2fs -c -1 -i 0 デバイス

過去ログ

昔のものは、雑多なメモ