- 投稿日:2022-02-14T15:30:27+09:00
【Azure】Linux系VMのログイン用パスワードが忘れてしまった時
シリアルコンソール Azureでは、シリアルコンソール方法で、VMに接続できる仕組みがあります。 シリアルコンソールについて: VMのパスワードが忘れてしまった時 もしVMのパスワードが忘れてしまった場合は、下記の方法で、VM内のローカルカウントユーザーのパスワードをリセットすることができます。 前提はAzure Cliが利用できることです。 az vm user update \ --resource-group myResourceGroup \ --name myVM \ --username azureuser \ --password myNewPassword VM諸設定によりSSHで入れない時 例えはsshdのconfigファイル編集により、失敗してしまい、sshできない場合は、シリアルコンソール経由して、シリアルコンソールでまずsudo権限を持つユーザーを作成し、その後シリアルコンソール上で色々編集できます。 管理者権限を持つユーザーの作成 az vm user update \ --resource-group myResourceGroup \ --name myVM \ --username myNewUser \ --ssh-key-value ~/.ssh/id_rsa.pub その後、上記で作成したユーザーからシリアルコンソールでいろいろ操作できればと思います。 操作後に、一時的に作成したユーザーの削除を忘れずに az vm user delete \ --resource-group myResourceGroup \ --name myVM \ --username myNewUser 参考URL:
- 投稿日:2022-02-14T08:19:26+09:00
LPIC 101 「Linuxのインストールとパッケージ管理」についてのコマンドを実際に確認してみる
LPIC 101で扱うコマンドを眺めててもなかなか頭に入らないので実際に触りながら学んだ記録です。 実行環境 誰でもweb上で確認できるようにkatacodaのUbuntu playgroundを使いました。以下のコマンド一覧は基本コピペで確認可能なはず。 $ bash --version GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. LPIC 101 出題範囲を確認 公式:https://www.lpi.org/our-certifications/exam-101-objectives 抜粋すると、 102.1 Design hard disk layout Weight: 2 102.2 Install a boot manager Weight: 2 102.3 Manage shared libraries Weight: 1 102.4 Use Debian package management Weight: 3 102.5 Use RPM and YUM package management Weight: 3 102.6 Linux as a virtualization guest Weight: 1 これに沿ってコマンドを確認していきたいと思います。 102.1 Design hard disk layout この節は、パーティションの設計について理解すればよく、特にコマンドで確認することはありませんでした。 102.2 Install a boot manager ブートローダーのインストールについて確認します。ブートローダーとは、HDDからOSを読み込んで起動するプログラムのことです。 grubをインストールする grubとは、Linuxの多くのディストリビューションで標準的に使われているブートローダーのことです。 $ grub-install /dev/sda grubの設定をする /etc/default/grubで設定を行ってから以下のコマンドを実行。 $ grub-mkconfig Generating grub configuration file ... # # DO NOT EDIT THIS FILE # # It is automatically generated by grub-mkconfig using templates # from /etc/grub.d and settings from /etc/default/grub # ### BEGIN /etc/grub.d/00_header ### (以下略) 102.3 Manage shared libraries 共有ライブラリを管理するためのコマンドを確認します。 実行ファイルが必要としている共有ライブラリを確認する $ ldd /bin/cat linux-vdso.so.1 => (0x00007ffd73fc6000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2e327be000) /lib64/ld-linux-x86-64.so.2 (0x00007f2e32b88000) catコマンドに必要なライブラリを確認しているという感じだと思います。 共有ライブラリを更新した際に、キャッシュを更新する ファイルが実行されるたびに共有ライブラリがあるパス一覧から全てを検索するのは非効率なので、Linuxではそれらを/etc/ld.so.cacheにキャッシュする仕様となっています。そのため、共有ライブラリを更新する場合はキャッシュも更新してあげる必要があります。 $ ldconfig 102.4 Use Debian package management Debian パッケージの管理についてコマンドを確認します。 dpkg インストール apache2をインストールする例。 $ dpkg -i apache2_2.4.29-1ubuntu4.5_amd64.deb 設定ファイルを含めてアンインストール $ dpkg --purge apache2 残す場合は-r, --removeオプションを使う。 システムにインストール済のパッケージ一覧を確認する $ dpkg -l | head -10 Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-=====================================-===============================================-============-=============================================================================== ii accountsservice 0.6.40-2ubuntu11.6 amd64 query and manipulate user account information ii adduser 3.113+nmu3ubuntu4 all add and remove users and groups ii amd64-microcode 3.20191021.1+really3.20180524.1~ubuntu0.16.04.2 amd64 Processor microcode firmware for AMD CPUs ii ansible 2.0.0.2-2ubuntu1.3 all Configuration management, deployment, and task execution system ii ant 1.9.6-1ubuntu1.1 all Java based build tool like make パッケージに含まれるファイルを表示する $ dpkg -L bash | head -10 /. /etc /etc/skel /etc/skel/.profile /etc/skel/.bash_logout /etc/skel/.bashrc /etc/bash.bashrc /bin /bin/bash /usr インストール済のパッケージを確認する $ dpkg -s bash | head -10 Package: bash Essential: yes Status: install ok installed Priority: required Section: shells Installed-Size: 1500 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Architecture: amd64 Multi-Arch: foreign Version: 4.3-14ubuntu1.4 apt-get 最新のパッケージ情報を取得する $ apt-get update Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial InRelease [18.1 kB] Hit:2 http://gb.archive.ubuntu.com/ubuntu xenial InRelease Get:3 http://gb.archive.ubuntu.com/ubuntu xenial-updates InRelease [99.8 kB] Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [99.8 kB] Get:5 http://gb.archive.ubuntu.com/ubuntu xenial-backports InRelease [97.4 kB] Get:6 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB] Get:7 https://deb.nodesource.com/node_14.x xenial InRelease [4,584 B] Get:8 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB] (以下略) /etc/apt/sources.listにapt-getでパッケージを管理しているサイトの一覧が載っているので、そのリストに一括で更新をかけるイメージです。 パッケージをインストールする $ apt-get install apache2 パッケージをアンインストールする $ apt-get remove apache2 パッケージを一括で最新の状態にアップデートする $ apt-get dist-upgrade これは便利ですね! $ apt-get upgrade でも同じことは可能です。 パッケージの検索 $ apt-cache search apache2 apache2 - Apache HTTP Server apache2-data - Apache HTTP Server (common files) apache2-dbg - Apache debugging symbols apache2-dev - Apache HTTP Server (development headers) apache2-doc - Apache HTTP Server (on-site documentation) apache2-utils - Apache HTTP Server (utility programs for web servers) (以下略) apache2という単語が入ったパッケージが全て羅列されるイメージ。 パッケージに関する情報を表示 $ apt-cache show apache2 Package: apache2 Architecture: amd64 Version: 2.4.18-2ubuntu3.17 Priority: optional Section: web Origin: Ubuntu (以下略) apt パッケージリストを更新する $ apt update Hit:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial InRelease Hit:2 http://gb.archive.ubuntu.com/ubuntu xenial InRelease Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease Hit:4 http://gb.archive.ubuntu.com/ubuntu xenial-updates InRelease Hit:5 http://gb.archive.ubuntu.com/ubuntu xenial-backports InRelease Hit:7 https://download.docker.com/linux/ubuntu bionic InRelease Hit:8 https://deb.nodesource.com/node_14.x xenial InRelease (以下略) さっきのapt-get updateとほぼ同じ。 システムをアップグレードする $ apt -y upgrade パッケージのインストールをする $ apt install apache2 パッケージのアンインストールをする $ apt remove apache2 パッケージの検索をする $ apt search "apache2*" パッケージの依存関係を満たすためにインストールしたものの、今は必要ないパッケージを削除する $ apt autoremove …apt-get, apt-cache使わずにaptだけで良くない? 102.5 Use RPM and YUM package management RPM パッケージの管理についてコマンドを確認します。有名どころだとCentOS(AWSのEC2とか)で使う。 katacodaはCentOS playgroundを使って進めていきます。 とりあえずサーバー上にrpmパッケージを置いてやらないとインストールとかできないので以下は実行しておきましょう。 [root@5faaaca9ceee ~]# wget https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/zsh-5.0.2-34.el7_8.2.x86_64.rpm rpm パッケージのインストール [root@5faaaca9ceee ~]# rpm -ivh zsh-5.0.2-34.el7_8.2.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:zsh-5.0.2-34.el7_8.2 ################################# [100%] -iはinstallのi、-vは詳細な情報表示、-hはhash(進行状況をhashで表示する)ということなので、インストールするだけなら-iで構わない。 パッケージのアップグレード [root@5faaaca9ceee ~]# rpm -F zsh-5.0.2-34.el7_8.2.x86_64.rpm -Uでも同じことできます。-Uだとなければインストール、-Fだとインストールされていればアップグレード。ややこしい。 パッケージのアンインストール [root@5faaaca9ceee ~]# rpm -e zsh パッケージ情報の照会 [root@5faaaca9ceee ~]# rpm -qa | grep zsh zsh-5.0.2-34.el7_8.2.x86_64 -qで指定されたパッケージがインストールされているか照会する、-aはall。全ての入力の中からzshをgrepしてるって感じです。 各パッケージの照会 [root@5faaaca9ceee ~]# rpm -qi zsh Name : zsh Version : 5.0.2 Release : 34.el7_8.2 Architecture: x86_64 Install Date: Sun 13 Feb 2022 10:49:19 PM UTC Group : System Environment/Shells Size : 5860430 License : MIT Signature : RSA/SHA256, Wed 08 Apr 2020 02:41:00 PM UTC, Key ID 24c6a8a7f4a80eb5 Source RPM : zsh-5.0.2-34.el7_8.2.src.rpm Build Date : Tue 07 Apr 2020 02:38:13 PM UTC Build Host : x86-02.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : http://zsh.sourceforge.net/ Summary : Powerful interactive shell Description : The zsh shell is a command interpreter usable as an interactive login shell and as a shell script command processor. Zsh resembles the ksh shell (the Korn shell), but includes many enhancements. Zsh supports command line editing, built-in spelling correction, programmable command completion, shell functions (with autoloading), a history mechanism, and more. -iはinfo。-qipでインストール前のパッケージ情報も見れる。 パッケージの依存関係を調べる [root@5faaaca9ceee ~]# rpm -qR zsh /bin/sh /bin/sh /bin/sh /bin/sh /bin/zsh /sbin/install-info /sbin/install-info config(zsh) = 5.0.2-34.el7_8.2 coreutils (以下略) パッケージの署名確認 [root@5faaaca9ceee ~]# rpm -checksig zsh-5.0.2-34.el7_8.2.x86_64.rpm zsh-5.0.2-34.el7_8.2.x86_64.rpm: rsa sha1 (md5) pgp md5 OK 何に使うかはよくわかってない。 パッケージの展開 [root@5faaaca9ceee ~]# rpm2cpio zsh-5.0.2-34.el7_8.2.x86_64.rpm | cpio -id 11745 blocks rpmはオプション暗記が必須でなかなか不便ですね… yum 基本APTツールの互換っぽい感じなのでコマンドもaptっぽい感じです。 アップデート [root@5faaaca9ceee ~]# yum check-update Loaded plugins: fastestmirror, langpacks Determining fastest mirrors epel/x86_64/metalink | 30 kB 00:00:00 * base: mirror.softaculous.com * epel: ftp.uni-stuttgart.de * extras: mirror.softaculous.com * updates: ftp.fau.de (以下略) 上記はチェックのみ。以下を実行すればアップデートが実行される。 [root@5faaaca9ceee ~]# yum update Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.softaculous.com * epel: ftp.uni-stuttgart.de * extras: mirror.softaculous.com * updates: ftp.fau.de (以下略) 個別にやるならこんな感じで。 [root@5faaaca9ceee ~]# yum update openssl インストール [root@5faaaca9ceee ~]# yum install ruby アンインストール [root@5faaaca9ceee ~]# yum remove ruby パッケージ情報を確認 [root@5faaaca9ceee ~]# yum info ruby Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.softaculous.com * epel: ftp.uni-stuttgart.de * extras: mirror.softaculous.com * updates: ftp.fau.de Installed Packages Name : ruby Arch : x86_64 Version : 2.0.0.648 Release : 36.el7 Size : 63 k Repo : installed From repo : base Summary : An interpreter of object-oriented scripting language URL : http://ruby-lang.org/ License : (Ruby or BSD) and Public Domain Description : Ruby is the interpreted scripting language for quick and easy : object-oriented programming. It has many features to process text : files and to do system management tasks (as in Perl). It is simple, : straight-forward, and extensible. パッケージを検索 [root@5faaaca9ceee ~]# yum search ruby | head -20 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.softaculous.com * epel: ftp.uni-stuttgart.de * extras: mirror.softaculous.com * updates: ftp.fau.de ============================== N/S matched: ruby =============================== graphviz-ruby.x86_64 : Ruby extension for graphviz kross-ruby.x86_64 : Kross plugin for ruby libselinux-ruby.x86_64 : SELinux ruby bindings for libselinux marisa-ruby.x86_64 : Ruby language binding for marisa mlt-ruby.x86_64 : Ruby package to work with MLT munin-plugins-ruby.noarch : Ruby plugins for Munin resource monitoring nbdkit-plugin-ruby.x86_64 : Ruby plugin for nbdkit openwsman-ruby.x86_64 : Ruby bindings for openwsman client API plasma-scriptengine-ruby.x86_64 : Plasma scriptengine for ruby postgresql-plruby.x86_64 : PostgreSQL Ruby Procedural Language postgresql-plruby-doc.x86_64 : Documentation for plruby remctl-ruby.x86_64 : Ruby interface to remctl rrdtool-ruby.x86_64 : Ruby RRDtool bindings パッケージグループ単位でのインストール [root@5faaaca9ceee ~]# yum group list Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.softaculous.com * epel: ftp.uni-stuttgart.de * extras: mirror.softaculous.com * updates: ftp.fau.de Installed Environment Groups: GNOME Desktop Available Environment Groups: Minimal Install Compute Node Infrastructure Server File and Print Server Cinnamon Desktop MATE Desktop Basic Web Server Virtualization Host Server with GUI KDE Plasma Workspaces Development and Creative Workstation Available Groups: Cinnamon Compatibility Libraries Console Internet Tools Development Tools Educational Software Electronic Lab Fedora Packager General Purpose Desktop Graphical Administration Tools Haskell LXQt Desktop Legacy UNIX Compatibility MATE Milkymist Scientific Support Security Tools Smart Card Support System Administration Tools System Management TurboGears application framework Xfce Done [root@5faaaca9ceee ~]# yum groups install "Cinnamon" これはなかなかユニークで面白い。便利ですね。 dnf 最近はyumの代わりにdnfを使う流派もあるらしい。使い方はyumとほぼ同じ感じ(雑) Zypper OpenSUSEのパッケージ管理にはzypperコマンドを使うらしいです。使い方はaptとほぼ同じ感じ(雑) $ zypper install git 一例。 102.6 Linux as a virtualization guest この説はクラウドサービスやIaaS, PaaS, SaaSの違いを理解していれば良く、特に確認するコマンドはありませんでした。
- 投稿日:2022-02-14T02:37:13+09:00
LinuxとPython3でsubprocess.Popenを使って"OSError: [Errno 12] Cannot allocate memory"が出たとき
原因 単純にメモリーが足りない subprocess.Popenを実行するプロセスのメモリが元々多い メモリが元々多い??とは? subprocess.Popenを実行するプロセスのメモリが元々多いとは? subprocess.Popenはシステムコールのsys_cloneが使われていて、メモリがコピーされて使用量もコピーされるようです・・・ そんなの知らないよ・・・ tensorflowで大き目のモデルを読み込んだプロセスとかだと大き目になりがち。 その状態でsubprocess.Popenを使って非同期実行するとメモリがコピーされるのか?メモリ空間がコピーされるのかよくわからないがsubprocess.Popenコール時点の容量が消費されるみたいです。 単純にメモリーが足りないパターンの場合はどうしようもない。 対策 キュー化するとか??大げさになっちゃうなぁ~~。今回は、REST APIを作って小さいプロセスからsubprocess.Popenで非同期実行してみた。
- 投稿日:2022-02-14T01:15:34+09:00
net-toolsを捨ててiproute2へ
経緯 頑なにnet-toolsのifconfigに慣れ親しんでいたのだが、OSバージョンアップして後から入れるのは面倒なのでそろそろ覚えたい 参考 iproute2:wikipedia ipコマンドチートシート 覚えておきたいもの iproute2コマンド net-toolsコマンド 役割 ip addr ifconfig IPアドレス確認 ss netstat ネットワーク状態確認 ip addrで覚えたいもの インタフェースアップダウン ip addr set eth0 up インタフェースアップさせる ip addr set eth0 down インタフェースダウンさせる IPアドレス全部表示 ip addr show インタフェースとIPアドレスが表示される インタフェース名は1: lo:から始まる部分のlo部分 IPアドレスはinet部分 特定インタフェースのIPアドレスを表示 ip addr show eth0 ssで覚えたいもの 使用中ポート全表示 ss -atn オプション 解説 a LISTEN, no-LISTENの全ソケット t TCPソケット n 数字表示