CentOSからAlmaLinuxへマイグレーション

ずっと後回しにしてきていましたが、公式のスクリプトのおかげで移行自体は驚くほど簡単でした。

準備

– yum ではなく dnfを使えるようにインストール
yumでインストールしようとするとロケールがセットできないとかエラーが出るので個別にダウンロードしてインストールします。(参照:https://qiita.com/piyojiro/items/58f9a89120808e1c1e84)
wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/dnf-conf-0.6.4-2.sdl7.noarch.rpm
wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/dnf-0.6.4-2.sdl7.noarch.rpm
wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/python-dnf-0.6.4-2.sdl7.noarch.rpm
yum install python-dnf-0.6.4-2.sdl7.noarch.rpm dnf-0.6.4-2.sdl7.noarch.rpm dnf-conf-0.6.4-2.sdl7.noarch.rpm

– CentoOS7をCentOS8へアップグレードします。
sudo dnf update -y
sudo dnf install http://vault.centos.org/8.5.2111/BaseOS/x86_64/os/Packages/{centos-linux-repos-8-3.el8.noarch.rpm,centos-linux-release-8.5-1.2111.el8.noarch.rpm,centos-gpg-keys-8-3.el8.noarch.rpm} -y
sudo dnf upgrade https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
sudo dnf clean all

マイグレーション自体は↓

1) スクリプトをダウンロードします
curl -O https://raw.githubusercontent.com/AlmaLinux/almalinux-deploy/master/almalinux-deploy.sh

2)実行
sudo bash almalinux-deploy.sh

3)確認
$ cat /etc/redhat-release
AlmaLinux release 8.10 (Cerulean Leopard)

UTM で “no suitable video mode found. Boot in blind mode”と表示されインストールできない

UTMのバージョンは4.1.5です。
ubuntu14.04をインストールしようとすると

error:no suitable video mode found
Boot in blind mode
と表示され先に勧めません。

原因はUTMのビデオモードの設定のようです。

デフォルトでは virtio-gpu-gi-pciなどになっていますがこれをVGAなどに変更して再度起動するとエラーを回避できました。

CentOS7 に Giitlab Runnerをインストールして登録する

今日はGitLabダウンしてたみたいですね。

まずはダウンロードします
$ sudo curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash

以下、ダウンロード
[sudo] password for contos: [パスワード入力]
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7016 100 7016 0 0 18477 0 --:--:-- --:--:-- --:--:-- 18511
Detected operating system as centos/7.
Checking for curl...
Detected curl...
Downloading repository file: https://packages.gitlab.com/install/repositories/runner/gitlab-runner/config_file.repo?os=centos&dist=7&source=script
done.
Installing pygpgme to verify GPG signatures...
Failed to set locale, defaulting to C
Loaded plugins: copr, fastestmirror, langpacks
Determining fastest mirrors
epel/x86_64/metalink | 8.1 kB 00:00
* base: mirrors.cat.net
* epel: repo.jing.rocks
* extras: mirrors.cat.net
* remi-safe: cdn.centos.no
* updates: mirrors.cat.net
base | 3.6 kB 00:00:00
copr:copr.fedorainfracloud.org:ngompa:snapcore-el7 | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
nodesource | 2.5 kB 00:00:00
remi-safe | 3.0 kB 00:00:00
runner_gitlab-runner-source/signature | 862 B 00:00:00
Retrieving key from https://packages.gitlab.com/runner/gitlab-runner/gpgkey
Importing GPG key 0x51312F3F:
Userid : "GitLab B.V. (package repository signing key) "
Fingerprint: f640 3f65 44a3 8863 daa0 b6e0 3f01 618a 5131 2f3f
From : https://packages.gitlab.com/runner/gitlab-runner/gpgkey
Retrieving key from https://packages.gitlab.com/runner/gitlab-runner/gpgkey/runner-gitlab-runner-4C80FB51394521E9.pub.gpg
Retrieving key from https://packages.gitlab.com/runner/gitlab-runner/gpgkey/runner-gitlab-runner-49F16C5CC3A0F81F.pub.gpg
runner_gitlab-runner-source/signature | 951 B 00:00:01 !!!
updates | 2.9 kB 00:00:00
(1/4): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(2/4): remi-safe/primary_db | 2.5 MB 00:00:00 (3/4): epel/x86_64/primary_db | 7.0 MB 00:00:01
(4/4): updates/7/x86_64/primary_db | 23 MB 00:00:02
runner_gitlab-runner-source/primary | 175 B 00:00:01
Package pygpgme-0.3-9.el7.x86_64 already installed and latest version
Nothing to do
Installing yum-utils...
Failed to set locale, defaulting to C
Loaded plugins: copr, fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cat.net
* epel: repo.jing.rocks
* extras: mirrors.cat.net
* remi-safe: cdn.centos.no
* updates: mirrors.cat.net
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do
Generating yum cache for runner_gitlab-runner...
Failed to set locale, defaulting to C
Importing GPG key 0x51312F3F:
Userid : "GitLab B.V. (package repository signing key) "
Fingerprint: f640 3f65 44a3 8863 daa0 b6e0 3f01 618a 5131 2f3f
From : https://packages.gitlab.com/runner/gitlab-runner/gpgkey
Generating yum cache for runner_gitlab-runner-source...
Failed to set locale, defaulting to C
The repository is setup! You can now install packages.
$

インストールできるよと言われているのでインストールします


$ sudo yum install -y gitlab-runner

↓こんな感じでインストール始まりました


Failed to set locale, defaulting to C
Loaded plugins: copr, fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cat.net
* epel: repo.jing.rocks
* extras: mirrors.cat.net
* remi-safe: cdn.centos.no
* updates: mirrors.cat.net
Resolving Dependencies
--> Running transaction check
---> Package gitlab-runner.x86_64 0:16.4.1-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
gitlab-runner x86_64 16.4.1-1 runner_gitlab-runner 461 M

Transaction Summary
===============================================================================================================================================
Install 1 Package

Total download size: 461 M
Installed size: 502 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/runner_gitlab-runner/packages/gitlab-runner-16.4.1-1.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 6ba75a4e: NOKEY==================-] 11 MB/s | 460 MB 00:00:00 ETA
Public key for gitlab-runner-16.4.1-1.x86_64.rpm is not installed
gitlab-runner-16.4.1-1.x86_64.rpm | 461 MB 00:00:44
Retrieving key from https://packages.gitlab.com/runner/gitlab-runner/gpgkey
Importing GPG key 0x51312F3F:
Userid : "GitLab B.V. (package repository signing key) "
Fingerprint: f640 3f65 44a3 8863 daa0 b6e0 3f01 618a 5131 2f3f
From : https://packages.gitlab.com/runner/gitlab-runner/gpgkey
Retrieving key from https://packages.gitlab.com/runner/gitlab-runner/gpgkey/runner-gitlab-runner-4C80FB51394521E9.pub.gpg
Importing GPG key 0x35DFA027:
Userid : "GitLab, Inc. "
Fingerprint: 09e5 7083 f34c ca94 d541 bc58 a674 bf81 35df a027
From : https://packages.gitlab.com/runner/gitlab-runner/gpgkey/runner-gitlab-runner-4C80FB51394521E9.pub.gpg
Retrieving key from https://packages.gitlab.com/runner/gitlab-runner/gpgkey/runner-gitlab-runner-49F16C5CC3A0F81F.pub.gpg
Importing GPG key 0x6BA75A4E:
Userid : "GitLab, Inc. "
Fingerprint: 931d a69c fa3a febb c97d aa8c 6c57 c29c 6ba7 5a4e
From : https://packages.gitlab.com/runner/gitlab-runner/gpgkey/runner-gitlab-runner-49F16C5CC3A0F81F.pub.gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : gitlab-runner-16.4.1-1.x86_64 [####################################################################################################################### Installing : gitlab-runner-16.4.1-1.x86_64 [######################################################################################################################## Installing : gitlab-runner-16.4.1-1.x86_64 [########################################################################################################################## Installing : gitlab-runner-16.4.1-1.x86_64 1/1
GitLab Runner: creating gitlab-runner...
Home directory skeleton not used
Runtime platform arch=amd64 os=linux pid=17698 revision=d89a789a version=16.4.1
gitlab-runner: the service is not installed
Runtime platform arch=amd64 os=linux pid=17703 revision=d89a789a version=16.4.1
gitlab-ci-multi-runner: the service is not installed
Runtime platform arch=amd64 os=linux pid=17715 revision=d89a789a version=16.4.1
Runtime platform arch=amd64 os=linux pid=17763 revision=d89a789a version=16.4.1
INFO: Docker installation not found, skipping clear-docker-cache
Verifying : gitlab-runner-16.4.1-1.x86_64 1/1

Installed:
gitlab-runner.x86_64 0:16.4.1-1
Complete!
$

確認してみます
$ sudo gitlab-runner --version
[sudo] password for centos: [パスワード]
Version: 16.4.1
Git revision: d89a789a
Git branch: 16-4-stable
GO version: go1.20.5
Built: 2023-10-06T01:26:25+0000
OS/Arch: linux/amd64
$

$ sudo gitlab-runner status
[sudo] password for centos: [パスワード]
Runtime platform arch=amd64 os=linux pid=18832 revision=d89a789a version=16.4.1
gitlab-runner: Service is running
$

インストールはされたっぽい

次は登録します

gitlabの「設定」→「CI/CD]を開いて「Runner」を展開します。

「新規プロジェクトRunner」をクリックします
新規作成画面になりますので
タグに何か入れて「作成」をクリックします

するとrunnerが作成されます

このトークンをクリップボードにコピーしておきます
$ sudo gitlab-runner register
[sudo] password for centos:[パスワード入力]
Runtime platform arch=amd64 os=linux pid=19417 revision=d89a789a version=16.4.1
Running in system-mode.

gitlabのインスタンスのURLを求められます。
言われている通りhttps://gitlab.com/ と入力します。
Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.com/

するとトークンを求められるので、先ほど作成したトークンをペーストします。
Enter the registration token:
tokenTOKENtokenTOKENtokenTOKEN
Verifying runner... is valid runner=RunnerIDppoi

こんどはRunnerに名前をつけてくださいと言われます。
my-runnerとか入れておきます。
Enter a name for the runner. This is stored only in the local config.toml file:
: my-runner

実行環境を決めてくださいと言われます。
shellにしときます。
Enter an executor: virtualbox, docker-autoscaler, docker+machine, custom, docker, docker-windows, parallels, ssh, kubernetes, shell, instance:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"

先ほどの「設定」→「CI/CD」 Runnerを展開すると登録したRunnerを見ることができます。

ubuntu で ssh接続できるポートとユーザーを設定する

/etc/ssh/sshd_configの最初の方にある

Port 22

の次あたりに

Port [使いたいポート番号]

追記する

あと最後に

AllowUsers [ユーザー名] [ユーザー名]

sshdを再起動する

あとファイアウォールの設定をする

新しいポート番号でログインできることを確認してから
sshd_configの
Port 22
をコメントアウトする

指定したユーザー以外でssh接続しようとするとパスワード聞かれた後で(パスワード合ってても) Permission denied と言われます。

インストールした仮想サーバーにSSH接続できないとき

仮想サーバーをインストールし直してローカルマシンから接続しようとするとHost Key Verification Failedと表示されてssh接続できない

“IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!” (誰かが何か厄介なことをしている可能性があります!)😅

解決方法は
ssh-keygen -R 127.0.0.1

~/.ssh/known_hosts の何かが変更されて接続できるようになります。

稼働中のwpサイトの開発環境構築

ubuntu14で運用してるWPサイトのためにM2-Macで開発環境を作りましたので覚え書き

UTMでmacの中に仮想環境ubuntu14を作る

sshd と ファイアウォールを設定してsshで作業できるようにする

前準備)LAMP環境のインストール
apt install apache2
apt install mysql-server-## mysql-client-##
apt install php##

ポートは22と80を開けておく

1)現行サイトからとってくるもの
-WPのファイル
-DB

2) データベースファイルを開発環境(UTM)へ

運用中のものと同じ空のデータベースを作成しておく
CREATE DATABASE [データベース名];
ファイル共有してsqlファイルのある場所で
mysql -u [ユーザー名] -p [上で作成した読み込み先データベース] < [読み込むファイル.spl]

パスワードを聞かれた後読み込みが始まります。
内容によると思いますが、けっこう時間がかかりました。

3)WPのファイルをコピーして設定をする
共有フォルダからDocument Root ディレクトリへ
ちなみにwp内の全てのファイルをすでに存在するディレクトリへコピーするときは
cp -pR /media/share/wp/* /var/www
ディレクトリ自体をコピーするときは
cp -r /media/share/wp/directory /var/www/directory
のようにします。

wp-configのDB名、ユーザー名、パスワード、ホストを設定します。
ホストは127.0.0.1

ルートディレクトリの設定をします。設定するのは
/etc/apache2/
の apache2.conf
/etc/apache2/sites-available
の 000-default.conとdefault-ssl.conf
3箇所です

4)mac のhostsを編集して稼働中のサイトのドメインで開発環境が表示されるようにする
macの/private/etc/hostsへ
127.0.0.1 sitename.com
を追記します。

今回新規にインストールしたApacheでSSLを有効化してなかったので最初
sudo a2enmod ssl
sudo a2ensite default-ssl
でapacheを再起動したら表示されました。

あとphpにmysql拡張モジュールがインストールされてない状態で
WPのインストールをしようとすると500エラーとなってしまいます。
なので
sudo apt install php-mysql

M2 macから仮想環境(UTM)のubuntuへファイル共有する

VirtFSというホスト/ゲスト間でのファイルのやり取りをするプロトコルを使います。
公式によるとLinuxの仮想マシンではSPICEよりもVirtFSが推奨だそうです。

仮想マシンの”共有”タブでVirtFSを選択、ホスト側の共有フォルダを指定して仮想マシンを起動します。
UTMの設定

次に起動したゲスト側で共有フォルダを作成して、フォルダをマウントします。
今回は/media/share を作って使います。
$ sudo mkdir /media/share
$ sudo mount -t 9p -o trans=virtio share /media/share -oversion=9p2000.L

これでホストで共有フォルダに入れたファイルをゲストから見ることができます。



$ls /media/share
test.txt

ただこのままだと、再起動するたびにマウントする必要があります。
だもんで /etc/fstab へ起動時にマウントするディレクトリとして指定します。

share	/media/share	9p	trans=virtio,version=9p2000.L,rw,_netdev,nofail	0	0

これで起動時に毎回自動的にマウントされます。

XLDを使ってCentOS7.xでUbuntu14.04を使う 1)

CentOSのアップデート

$ sudo yum update
$ sudo yum install epel-release
$ sudo yum update

snapdをインストール
snapdとはディストリビューションに依存せずにパッケージ管理を行うためのツールだそうです

最初にCopr(Cool Other Package Repo)をインストールする
$ sudo yum install yum-plugin-copr
正規のディストリビューションには含まれてませんので自己責任で!とか言われます。

Coprにあるsnapdをインストールする
$ sudo yum copr enable ngompa/snapcore-el7
$ sudo systemctl enable --now snapd.socket
Created symlink from /etc/systemd/system/sockets.target.wants/snapd.socket to /usr/lib/systemd/system/snapd.socket.

snapを使ってLXDのインストール

$ sudo snap search lxd
Name Version Publisher Notes Summary
lxd 5.10-b392610 canonical** - LXD - container and VM manager
lxd-bgp 0+git.a30c4fe stgraber - BGP server that exposes LXD routes
lxd-demo-server 0+git.6d54658 stgraber - Online software demo sessions using LXD
lxdmosaic 0+git.c6f53f3f turtle0x1 - A web interface to manage multiple instances of LXD
lxd-gitlab-runner 0.1 alexclewontin - GitLab CI/CD runner with built in LXD executor
microcloud 0+git.d78a41a canonical** - Automated small-scale cloud deployment
fabrica 1.1.0 ogra - Build snaps by simply pointing a web form to a git tree
nova ocata james-page - OpenStack Compute Service (nova)
nova-hypervisor ocata james-page - OpenStack Compute Service - KVM Hypervisor (nova)
distrobuilder 2.1 stgraber classic Image builder for LXC and LXD
satellite 0.1.2 alanzanattadev - Advanced scalable Open source intelligence platform

$ snap install lxd
2023-01-29T06:18:58+09:00 INFO Waiting for automatic snapd restart...
lxd 5.10-b392610 from Canonical** installed

インストールの確認をします

$ sudo ln -s /var/lib/snapd/snap /snap
$ snap list
Name Version Rev Tracking Publisher Notes
core20 20221212 1778 latest/stable canonical** base
lxd 5.10-b392610 24323 latest/stable canonical** -
snapd 2.58 17950 latest/stable canonical** snapd

$ snap services
Service Startup Current Notes
lxd.activate enabled inactive -
lxd.daemon enabled inactive socket-activated
lxd.user-daemon enabled inactive socket-activated

最初、lxdコマンドを入力しても command not found となっていましたが、ログインし直すと反応してくれるようになりました。CentOSでsnapを使う時のご作法のようでした。

$ lxd --version
5.10

きょうはここまで。。。