kuroの覚え書き

96の個人的覚え書き

SRAToolkit

公開されているSRAファイルをダウンロードして再解析がしたいとき、データのダウンロードが結構面倒なので(サイトの構造が複雑すぎてなかなかファイル本体にたどり着けない)専用のツールを利用したい。
とおもってインストールをbrewからやってみた。

$ brew install sratoolkit

ところがだ。

$ fastq-dump --gzip --split-files SRRxxxxxxxx

localeがおかしいとかのwarningはまあいいとして、どうもperlのライブラリがぶつかって動かないらしい。


というわけで、バイナリを手動でインストールしてみた。

$ wget https://ftp-trace.ncbi.nlm.nih.gov/sra/sdk/current/sratoolkit.current-centos_linux64.tar.gz
$ tar xvzf sratoolkit.current-centos_linux64.tar.gz
$ mv sratoolkit.2.10.7-centos_linux64 ~/src/
$ ln -s ~/src/sratoolkit.2.10.7-centos_linux64/bin/* ~/bin

homebrewでpython3.6(前のバージョン)をインストールする

$ cd /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
$ git log python.rb
commit b02eee23d9ac8e1027a212f269da6edd4c1f0f5f
Author: BrewTestBot <homebrew-test-bot@lists.sfconservancy.org>
Date:   Mon Apr 20 06:02:17 2020 +0000

    python: update 3.7.7_1 bottle.

commit 8bcd19011df9b5d42f5286bd5f3ec65e2aafc8c7
Author: Michka Popoff <michkapopoff@gmail.com>
Date:   Mon Apr 20 08:01:09 2020 +0200

    python: bump revision for libffi (#20152)

commit 4f455d5f8c2d45682448416d53d0c47355445177
Author: Michka Popoff <michkapopoff@gmail.com>
Date:   Sat Apr 18 18:17:50 2020 +0200

    python: fix style for Linuxbrew

・・・・・

こんな感じにgit logを開く
とにかく3.7を入れちゃうとモジュール関係も最新を入れてしまうのでGLIBC_2.18が必要となってしまうので、3.6に戻ってもらう。

commit ac64d11bca23f0d221967fef3b89e1d30053e067
Author: LinuxbrewTestBot <testbot@linuxbrew.sh>
Date:   Sun Jun 17 15:53:29 2018 +0000

    python: update 3.6.5_1 bottle for Linuxbrew.

commit 3ec730ba2ea8fcbd8fb853778b07236c3edb02c1
Merge: d07628b798 597da37dcc
Date:   Sun Jun 17 17:23:04 2018 +0200

    Merge branch homebrew/master into linuxbrew/master
    
     Conflicts:
            Formula/gdbm.rb
            Formula/pipenv.rb
            Formula/pre-commit.rb
            Formula/python.rb
            Formula/python@2.rb
            Formula/sip.rb
            Formula/vim@7.4.rb

commit f2a764ef944b1080be64bd88dca9a1d80130c558
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Sun Jun 17 13:24:46 2018 +0000

    python: update 3.6.5_1 bottle.

commit b60c0325575ed4c3c90ba061880a79bc0c208cf0
Author: commitay <commitay@users.noreply.github.com>
Date:   Sun Jun 17 18:01:44 2018 +1000

    python: revision for gdbm
    
    Also, update `setuptools` and `wheel` resources

commit 5f5331172328b5d21592518fece5c332c42bc770
Merge: dbc1429eab c1f561a772
Author: Michka Popoff <michkapopoff@gmail.com>
Date:   Wed Jun 13 23:07:55 2018 +0200

    Merge branch homebrew/master into linuxbrew/master

commit c1f561a772a747d711657afa2644287aa0cc9a40
Author: commitay <commitay@users.noreply.github.com>
Date:   Wed Jun 13 19:26:30 2018 +1000

    python 3.7.0rc1 (devel) (#28975)

ここでやっと3.6登場

commit 0036460b7cf3f16e5e02880d893717ee86404ef3
Author: Chuancong Gao <chuanconggao@users.noreply.github.com>
Date:   Thu Mar 29 19:40:41 2018 -0700

    python 3.6.5

このへんで行くか。

$ git checkout 0036460b7cf3f16e5e02880d893717ee86404ef3 python.rb
$ HOMEBREW_NO_AUTO_UPDATE=1 brew install python
Warning: Calling 'devel' blocks in formulae is deprecated! Use 'head' blocks or @-versioned formulae instead.
Please report this issue to the homebrew/core tap (not Homebrew/brew or Homebrew/core), or even better, submit a PR to fix it:
  /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rb:15

==> Downloading https://files.pythonhosted.org/packages/72/c2/c09362ab29338413ab
######################################################################## 100.0%
==> Downloading https://files.pythonhosted.org/packages/c4/44/e6b8056b6c8f2bfd14
######################################################################## 100.0%
==> Downloading https://files.pythonhosted.org/packages/fa/b4/f9886517624a4dcb81
######################################################################## 100.0%
==> Downloading https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
##############################                                   [  938.835230] serial8250: too much work for irq4
######################################################################## 100.0%
Warning: Calling 'devel' blocks in formulae is deprecated! Use 'head' blocks or @-versioned formulae instead.
Please report this issue to the homebrew/core tap (not Homebrew/brew or Homebrew/core), or even better, submit a PR to fix it:
  /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rb:15

Error: An exception occurred within a child process:
  NoMethodError: undefined method `installed?' for OS::Mac::CLT:Module
Did you mean?  instance_of?

うーん、やっぱりだめか?

次はanacondaでトライ

Python3.7.7/CentOS7でエラー

Traceback (most recent call last):
  File "manage.py", line 2, in <module>
    from app import app, manager
  File "/home/kuro/database/app/__init__.py", line 23, in <module>
    from app.views import samples, genes, anno, fasta, blast, blast_nb, crispr, clustalw, seeds, plasmid, stat
  File "/home/kuro/database/app/views/crispr.py", line 8, in <module>
    import matplotlib
  File "/home/linuxbrew/.linuxbrew/Cellar/python/3.7.7_1/lib/python3.7/site-packages/matplotlib/__init__.py", line 205, in <module>
    _check_versions()
  File "/home/linuxbrew/.linuxbrew/Cellar/python/3.7.7_1/lib/python3.7/site-packages/matplotlib/__init__.py", line 190, in _check_versions
    from . import ft2font
ImportError: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /home/linuxbrew/.linuxbrew/lib/libstdc++.so.6)

matplotlibをインポートしようとするとGLIBC_2.18が無いと言って落ちる。
CentOS7ではGLIBC_2.18はサポートしないらしいので、そろそろCentOS7も8に上げるべき時期が来たのかもしれない。

KVM仮想環境でテストを開始するか。
それともbrewで入れずanacondaにしてみるか?

brewで新規にインストールすると3.7.7がインストールされてしまうので、brewの環境を一旦アンインストールし、yumで標準リポジトリから3.6系を入れてみることにした。そうすると問題はなくなることは確認できたが、yumで入れるといちいちsudoでパッケージを追加したりと若干使い勝手が悪い。

次はbrewで明示的に3.6系をインストールする方法を試してみる。
参照
macOS Mojave に Python 3.6 環境を構築する - Satoshi Oikawa - Medium

Fujitsu PRIMERGY TX1310M3にCentOSをインストールする

昨年度末にディスコン間近と思われるTX1310M3を購入したっきり、全然時間がなくて放置してあったのだが、ちょっと触ってみる。

まず、これまでのRX200や300とはBIOSUEFIになっている点でかなり勝手が違う。同じUEFIのRX1330M3ともなにやら違っていてこのTX1310M3は特に曲者らしい・・・

色々やってみたがembedded MegaRAID (software RAID)がCentOSでもUbuntuでもうまく使えない。

暇を見つけてやってみたことを並べていくことにする。

買ったままの状態では何もOSが入ってないのでF2を押さなくても勝手にUEFIの画面に入る。
f:id:k-kuro:20200521191421j:plain

AdvancedからLSI Software RAID Configuration Utilityに進む。
f:id:k-kuro:20200521191838j:plain

ここからのRAID設定はややこしいので、
富士通 PRIMERGY TX1310 M3 ソフトウェアRAID設定手順 | PGDブログ
こちら参照で。

ちなみにAdvanced>SATA ConfigurationでAHCIが選択されているとEmbedded RAIDがスキップされ、BIOS上にもメニューが表示されない。
RAIDに変更してリセットするとこのメニューが現れる。

【PRIMERGY】uEFI時のEmbedded SATA RAIDの設定 | OTTOSERVER "TECH" Blog
こちらの説明によると旧BIOSモードに切り替えてからのRAID設定ができないと言っているがそんなことはなく
AdvancedでCSM Configurationをenableにして再起動してやると、起動シークエンスの途中でRAID設定に入ることができるはずだ。

LSIの昔ながらのインターフェースで設定できるので、なれた人ならこちらのほうがやりやすかろう。

さて、RAIDが設定できたら早速インストール。
CentOS8.1なら標準でドライバを持っているらしいという情報を得たので、試しに入れてみようと8.1を探してみると、どうやら8以降はインストーラが片面2層DVD出ないと入り切らないサイズになっているらしい。そんなディスクもない、ということでUSBメモリにネットワークインストーラを入れてやってUSBからのインストールを試してみる。
f:id:k-kuro:20200521193443j:plain
いけそうでいけない。anacondaが起動してインストーラが立ち上がった時点でこのようなエラーが出て止まってしまう。

ネットワークインストールの問題かもしれないので、とりあえず何も考えずにCentOS7のインストーラディスクを装着して起動してみる。
ちなみに今度は色々枯れたちょっと古めのバージョン7.5のディスクでやってみる。

まあ、当然というかインストーラRAIDディスクにアクセスできず、行き詰まる。

次、MEGASR2ドライバを読ませる。
【PRIMERGY】PRIMERGY M3世代へのCentOSインストールについて【CentOS】 | OTTOSERVER "TECH" Blog
ドライバは7.5のものをSDカードに仕込んでおく。

http://azby.fmworld.net/app/customer/driversearch/ia/drviadownload?driverNumber=F1027982

お約束の
インストール項目選択で「e」を押す。
quietを消して

modprobe.blacklist=ahci inst.dd

を追加しctrl + x
でドライバを読ませる。

あれ?ちゃんとインストール出来たよ。
前やったときはどうしてもドライバが動かなかったのに。ドライバのバージョンが上がったか?

最近のサーバ構成

サーバ   CPU               メモリ            理論性能
RX1330M3 E3-1230v6(4C/8T, 3.50GHz)   DDR4-2400 (PC4-19200E) UDIMM 64GB  224.0GFLOPS
RX300S7  E5-2667(6C/12T, 2.90GHz)x2  DDR3-1600 (PC3L-12800R) LV-RDIMM 32GB 278.4GFLOPS
RX300S7  E5-2643(4C/8T, 3.30GHz)x2  DDR3-1600 (PC3L-12800E) LV-UDIMM 24GB    211.2GFLOPS
RX200S7  E5-2630(6C/12T, 2.30GHz)x2  DDR3-1333 (PC3-10600R) RDIMM 44GB  220.8GFLOPS
RX300S7  E5-2620(6C/12T, 2.00GHz)x2  DDR3-1600 (PC3L-12800R) LV-RDIMM 24GB   192.0GFLOPS

NEC Express5800R110e-1e Pentium G2020 (2C/2T, 2.9GHz)  DDR3-1333 (PC3-10600E) UDIMM 4GB   #ファイルサーバ

E5600(Westmere-EP)は退役し、台数は減ったものの、十分な計算能力は確保していると思う。
各機メモリがもうちょっと欲しいところ。
1CPUあたり64GBくらいないとCufflinksがコケる。

この他TX1310M3も入手してあるが未整備。

ちなみに自宅用には
NEC Express5800T110f-e E3-1220v3(4C/4T, 3.30GHz) DDR3-1600 (PC3L-12800E) LV-UDIMM 8GB

THIRDWAVE R121-340 (CPU/Mem未実装)
がある。

教師なし機械学習

deep learningの本を読めば読むほどに自分のやりたいことが教師あり深層学習ではできないんじゃないかと思い始めた。結局正解、不正解が明確に判定できる例が多数ないと、その特徴を抽出する学習が機能しないわけだが、世の中そんなに白黒はっきりした例が揃っていることなんてなかなかない。よくわからない集団の中から特徴を見分けて分類できるか、ということのほうが多いはずだ。

ということですっかり深層学習一辺倒になりつつある時代に逆行して、教師なし機械学習に戻ってくるという感じ。

早速書籍を購入し、ハンズオンを試していこうと思う。

さて心機一転Macに環境構築していく。

Pythonはすでに3.6がインストールされているので、tensorflowとkerasをpipでインストールする。
次にxgboostをインストールしようとしてちょっと詰まる。
書籍ではgitでダウンロードしてきたファイルからインストールしているがwin環境用のインストーラなのでインストールできない。

$ cd handson-unsupervised-learning/
$ cd xgboost/
$ pip3 install xgboost-0.81-cp36-cp36m-win_amd64.whl 
ERROR: xgboost-0.81-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.

よく見ると書籍の欄外に注釈として
pip install xgbootでインストールできると書いてあったので

$ pip3 install xgboost
Collecting xgboost
  Downloading xgboost-1.0.2.tar.gz (821 kB)
     |████████████████████████████████| 821 kB 5.0 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /usr/local/opt/python/bin/python3.6 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-install-4x26emtu/xgboost/setup.py'"'"'; __file__='"'"'/private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-install-4x26emtu/xgboost/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-pip-egg-info-s7yrttks
         cwd: /private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-install-4x26emtu/xgboost/
    Complete output (27 lines):
    ++ pwd
    + oldpath=/private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-install-4x26emtu/xgboost
    + cd ./xgboost/
    + mkdir -p build
    + cd build
    + cmake ..
    ./xgboost/build-python.sh: line 21: cmake: command not found
    + echo -----------------------------
    -----------------------------
    + echo 'Building multi-thread xgboost failed'
    Building multi-thread xgboost failed
    + echo 'Start to build single-thread xgboost'
    Start to build single-thread xgboost
    + cmake .. -DUSE_OPENMP=0
    ./xgboost/build-python.sh: line 27: cmake: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-install-4x26emtu/xgboost/setup.py", line 42, in <module>
        LIB_PATH = libpath['find_lib_path']()
      File "/private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-install-4x26emtu/xgboost/xgboost/libpath.py", line 50, in find_lib_path
        'List of candidates:\n' + ('\n'.join(dll_path)))
    XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
    List of candidates:
    /private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-install-4x26emtu/xgboost/xgboost/libxgboost.dylib
    /private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-install-4x26emtu/xgboost/xgboost/../../lib/libxgboost.dylib
    /private/var/folders/bh/ggq7fvb9581379cgprt5p9r40000gn/T/pip-install-4x26emtu/xgboost/xgboost/./lib/libxgboost.dylib
    /usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/xgboost/libxgboost.dylib
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

これはコンパイラがまずいのか?

$ gcc -dumpversion
4.2.1

gccの最新バージョンは8らしいのだが、4と5で互換性がないとかで、とりあえず6入れてみようかなと思い、

$ brew install gcc6
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring portable-ruby-2.6.3.mavericks.bottle.tar.gz
==> Auto-updated Homebrew!
Updated 3 taps (brewsci/science, homebrew/cask and homebrew/core).

.........

Warning: You are using macOS 10.12.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this old version.

..........

ん?6は古いから保証しない?やはり素直に8を入れるべきなのか。
いや、OSXのバージョンが古いのか?

長い時間がかかってようやくgcc6が入った。
しかし、まだエラーは消えず。
cmakeが入ってないせいかもしれない。
というわけで

$ brew install make
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/cask and homebrew/core).
==> Updated Formulae
re2
==> Updated Casks
keka                                     mactracker

Warning: You are using macOS 10.12.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this old version.

..........

これまた長い時間がかかる。
しかしまだエラーが出てインストールできない。

$ pip3 install xgboost
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/xgboost/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/xgboost/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/xgboost/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/xgboost/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/xgboost/
Could not fetch URL https://pypi.org/simple/xgboost/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/xgboost/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
ERROR: Could not find a version that satisfies the requirement xgboost (from versions: none)
ERROR: No matching distribution found for xgboost

次に試したのは
Installation Guide — xgboost 1.1.0-SNAPSHOT documentation
ここを参照して(というか最初にここ見ろよという話)

$ brew install libomp
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
balena-cli          emscripten          gatsby-cli          neomutt
cfn-lint            faudio              git-annex           proj
conserver           fluent-bit          git-quick-stats
dxpy                fwup                gopass

Warning: You are using macOS 10.12.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this old version.

==> Downloading https://github.com/llvm/llvm-project/releases/download/llvmorg-1
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws
######################################################################## 100.0%
==> cmake . -DLIBOMP_INSTALL_ALIASES=OFF
==> make install
==> cmake . -DLIBOMP_ENABLE_SHARED=OFF -DLIBOMP_INSTALL_ALIASES=OFF
==> make install
🍺  /usr/local/Cellar/libomp/10.0.0: 9 files, 1.4MB, built in 45 seconds

やっとインストールできそう。

$ cd ../python-package/
Mac-mini-2014:python-package kkuro$ python3 setup.py install
/usr/local/lib/python3.6/site-packages/setuptools/dist.py:472: UserWarning: The version specified ('1.1.0-SNAPSHOT') is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.
  "details." % version
running install
running build

..........

今度はエラーなく完了したようだけど果たしてこれでいいのか?

Clusteringしたデータを折れ線グラフとして一気に作成

%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib as mpl
color_codes = {1:'#E60012', 2:'#F39800', 3:'#FFF100', 4:'#8FC31F', 5:'#009944', 6:'#009E96', 7:'#00A0E9', 8:'#0068B7', 9:'#1D2088', 10:'#920783', 11:'#E4007F', 0:'#E5004F'}
fig_x=10
fig_y=10
l_wide=0.15
numclusters = [0,1,2]
for num_cluster in numclusters:
    gcolor=color_codes[num_cluster]
    df = pd.read_csv('iris_k.csv', index_col=0)
    df = df[df['kmeans'].isin([num_cluster])]
    df = df.loc[:,['0','1','2','3']]
    df = df.T
    print(num_cluster)
    df.plot(color=gcolor, legend=False, figsize=(fig_x, fig_y), linewidth=l_wide )
    plt.savefig('g'+str(num_cluster)+'.png')

csvから該当箇所をちまちま切り出していては面倒臭すぎるのでpythonで一気にやってもらう。

f:id:k-kuro:20200221093256p:plain
こんな感じにk-meansで3クラスターに分けたirisデータの一部を使用すると
f:id:k-kuro:20200221094022p:plainf:id:k-kuro:20200221094024p:plainf:id:k-kuro:20200221094028p:plain
こんな感じにそれぞれのクラスターの折れ線が描ける。

firewall-cmdのお作法

これまたしょっちゅう・・・

activeなゾーンの表示

# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

似ているけど

# firewall-cmd --list-all-zones
block
  target: %%REJECT%%
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
	

dmz
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

・・・・・・

work
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

こんな感じにずらずらと一覧。

get系

# firewall-cmd --get-active-zones
public
  interfaces: eth0

# firewall-cmd --get-default-zone
public

# firewall-cmd --get-services
RH-Satellite-6 amanda-client amanda-k5-client amqp amqps apcupsd audit bacula bacula-client bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns docker-registry docker-swarm dropbox-lansync elasticsearch etcd-client etcd-server finger freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls lightning-network llmnr managesieve matrix mdns minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nfs nfs3 nmea-0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius redis rpc-bind rsh rsyncd rtsp salt-master samba samba-client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server

serviceは
/usr/lib/firewalld/services/
xmlファイルとして定義されているもの

# firewall-cmd --add-service=https --zone=public --permanent
# firewall-cmd --reload
success

というふうに開通したいサービスをゾーンに登録できる
permanentオプションをつけると起動時に自動で開き、つけないとその時限りとなる。permanentオプションを付けるときはreloadオプションも必要。

# firewall-cmd --add-port=8080/tcp --zone=public

ポートを直接指定して開く場合はこのようにする。通常のサービスとは異なるポートを使いたいときなど。

nmcliのお作法

すぐに忘れてしょっちゅう調べている気がするので、覚書。

基本のネットワーク設定

# nmcli c m eth0 ipv4.method manual ipv4.addresses 192.168.1.101/24 ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8 connection.autoconnect yes

この例ではDHCPをやめて手動設定にする、ipアドレスゲートウェイアドレス、DNSサーバ、そして起動時に自動でネットワークデバイスを有効にする設定を一気に行っているが、必要な部分だけを書いてもいい。
設定変更したあとは再起動するか、

# nmcli c down eth0; nmcli c up eth0

でネットワークをリセットする。

現在の状況を表示

# nmcli d
DEVICE  TYPE      STATE      CONNECTION 
eth0    ethernet  connected  eth0       
lo      loopback  unmanaged  --         

firewalldで使うゾーンの設定も行える。

# nmcli c m eth0 connection.zone internal

なお、nmcli c のcはconnectionの省略でcと書く代わりにconnectionと書いてもいい。

  g[eneral]       NetworkManager's general status and operations
  n[etworking]    overall networking control
  r[adio]         NetworkManager radio switches
  c[onnection]    NetworkManager's connections
  d[evice]        devices managed by NetworkManager
  a[gent]         NetworkManager secret agent or polkit agent
  m[onitor]       monitor NetworkManager changes

またnmcli c mのmはmodifyの省略形でmodやmodifyでもいいようだ。

CentOS7に仮想環境(続き)

f:id:k-kuro:20200620122334p:plain
こうなっているNAT接続を
f:id:k-kuro:20200620122434p:plain
こういうBridge接続に変える方法。

もともとKVMホストeno0にあてがっていた192.168.0.40をブリッジにあてがう。

# nmcli d
DEVICE      TYPE      STATE     CONNECTION 
eno0        ethernet  接続済み  有線接続 1 
virbr0      bridge    接続済み  virbr0     
eno1        ethernet  利用不可  --         
lo          loopback  管理無し  --         
virbr0-nic  tun       管理無し  --    

初期状態ではこうなっているはず。

# nmcli c a type bridge ifname br0
# nmcli c m bridge-br0 bridge.stp no
# nmcli c m bridge-br0 ipv4.method manual ipv4.address "192.168.0.40/24" ipv4.gateway "192.168.0.1" ipv4.dns 8.8.8.8
# nmcli c a type bridge-slave ifname eno0 master bridge-br0

ここまでやると

$ nmcli d
DEVICE      TYPE      STATE     CONNECTION 
eno0        ethernet  接続済み  有線接続 1 
br0         bridge    接続済み  bridge-br0 
virbr0      bridge    接続済み  virbr0     
eno1        ethernet  利用不可  --         
lo          loopback  管理無し  --         
virbr0-nic  tun       管理無し  --         
kkuro@kkuro-E5800-T110f-E:~$ nmcli c show
NAME               UUID                                  TYPE      DEVICE 
bridge-br0         46996087-e60a-4480-97bb-68eed1c0c354  bridge    br0    
virbr0             70df80ad-997e-4e47-9997-1ad9508861f8  bridge    virbr0 
有線接続 1         f32a9ca5-f080-307d-bc96-d24dd34c6432  ethernet  eno0   
bridge-slave-eno1  783fc200-6155-496b-8c39-09f1b03c8aec  ethernet  --     
有線接続 2         159a4b96-7520-3f02-8584-8d92dc89e7f7  ethernet  --   

この様になっているはず。
最後に不要となった物理NICのアドレス(有線接続 1)を削除する。

# nmcli c delete 有線接続\ 1
$ nmcli d
DEVICE      TYPE      STATE     CONNECTION        
br0         bridge    接続済み  bridge-br0        
virbr0      bridge    接続済み  virbr0            
eno0        ethernet  接続済み  bridge-slave-eno0 
eno1        ethernet  利用不可  --                
lo          loopback  管理無し  --                
virbr0-nic  tun       管理無し  -- 

$ nmcli c show
NAME               UUID                                  TYPE      DEVICE 
bridge-br0         46996087-e60a-4480-97bb-68eed1c0c354  bridge    br0    
bridge-slave-eno0  783fc200-6155-496b-8c39-09f1b03c8aec  ethernet  eno0   
virbr0             70df80ad-997e-4e47-9997-1ad9508861f8  bridge    virbr0 
有線接続 2         159a4b96-7520-3f02-8584-8d92dc89e7f7  ethernet  --


ここまではいいはず。
この状態でsshで192.168.0.40にアクセスするとKVMホストにログインできる。

仮想マシン

# virt-install --name kvm2 --memory 1024 --disk size=20 --vcpu 4 --location /tmp/CentOS-7-x86_64-DVD-1908.iso --network bridge=br0 --graphics none --extra-args='console=tty0 console=ttyS0'

で作成する。(sshで接続してインストールしているのでgraphics noneとしているが、実機でやっていたり、vnc環境なら--graphics以降はいらない)
インストールが始まったらNATを使う場合に空欄にしておいたnetworkの設定項目も入力する。
DHCPも使えるが、わざわざブリッジにするならやはりここはstaticアドレスを入れておきたい。
ネット空間はホストと同じ192.168.0.xxでOKだ。

これにて無事、仮想マシンに直接sshでログインできるようになった。
さて、ちゃんとできるになったことだしメインのサーバにも仮想マシンを立てて、通常の作業はそちらで行うのが良いだろうな。

# virt-clone --original kvm1 --name centos7template --file /home/kvm/images/centos7template.img

インストールした仮想環境をコピーしてテンプレートにしておけば環境をいくらでも増やしていける。disk imgはバックアップとしてすげ替えることも可能。

ここからは既存の仮想環境のネットワーク設定を変える試み。しかしうまくいっていない。普通に仮想環境を作り直したほうが早そうだ。

# nano host-bridge.xml
# cat host-bridge.xml
<network>
  <name>host-bridge</name>
  <forward mode="bridge" />
  <bridge name="br0"/>
</network>

# virsh net-define --file host-bridge.xml
# virsh net-autostart host-bridge

# virsh edit kvm1
<source network='default'/>

<source network='host-bridge'/>

に書き換える。