shari-sushi / 0025Linux

0 stars 0 forks source link

GCE VM で V-Karaoke を立てる #3

Open shari-sushi opened 6 months ago

shari-sushi commented 6 months ago

(Linux repositoryにissue立てるのどうかと思うけど)

https://github.com/shari-sushi/V-Kara-Lists を立てる。


LinuC向けに GCE でインスタンス立てたときのメモ e2 コアとメモリの非? E2, N1, N2 か業務ならC3?

名前 : 立てたいインスタンス名 リージョン、ゾーン ; アイオワ、use-central マシンの構成 : E2、プリセット : e2-micro, 可用性ポリシー : スポット (真面目にサービスするなら標準)

マシン側とgcp側の両方 gcloud っていうCLI?があって、ssh接続できる。鍵使わなくてもいける? (Cloud Shellのことと思われる)

cloud shell はユーザーごとに1つ割り当てられるマシンで動く、完全。

gcloud compute ssh [インスタンス名] --zone us-central1-c compute = サービス名(GC compute) であり、アクセス先を示している。 gcloud サービス名(アクセス先) 実行内容 us-centralが一番安そう。jpに比べて多少ラグはあるけど。

[自分のアカウント情報]:~ ([会社の情報的な])$ gcloud compute ssh [インスタンス名] --zone us-central1-c
Warning: Permanently added 'compute.xxxx' (xxxxxxx) to the list of known hosts.
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-1058-gcp x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

  System information as of Tue Apr 30 05:36:21 UTC 2024

  System load:  0.0               Processes:             102
  Usage of /:   19.4% of 9.51GB   Users logged in:       0
  Memory usage: 22%               IPv4 address for ens4: 10.128.0.3
  Swap usage:   0%

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status

New release '22.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Tue Apr 30 05:24:01 2024 from 35.235.241.18
shari-sushi commented 6 months ago

GCのサービスを軽く把握

分かりやすい!自社に合った Google Cloud コンピューティングの選択方法とは?

GCP : AWS


Google Cloude : AWS, Azureと比較

Google Cloud : サーバーレスとフルマネージド: その違いとは?

似ているが違う

shari-sushi commented 6 months ago

公式 : GCP(Google Cloud Platform)でCompute Engineを立ててみる

VM作って

ボツ

## SSH接続 ### ssh鍵発行 https://qiita.com/bo_yakitarako/items/08e2d205ca7634cd7d57 > The key's randomart image is: の結果は無事表示された。 鍵ができた事確認 ```sh > ls ~/.ssh ディレクトリ: C:\Users\user name\.ssh Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2024/05/02 18:55 2610 id_rsa -a---- 2024/05/02 18:55 578 id_rsa.pub -a---- 2024/04/22 2:47 1497 known_hosts ``` 安全にssh key作るなら{こっち](https://qiita.com/suthio/items/2760e4cff0e185fe2db9) このssh公開鍵をGCに登録する。

せっかくなのでvim使いたい→諦めた

(指定のフォルダをeditorで開きに行くより、今開いてるVScodeなりのターミナルでさくっと vim ~/.sshしたい) vim公式って誘導されたgithubが200弱のいいねしかなかったりで怖かったので断念。他の紹介サイトもzipファイルを直接ダウンロードとかで怖い。 この辺り役立つかなぁ https://qiita.com/hikaruright/items/b415d569b5bbeaf967bd#homebrewの代替を探す 以上。

### 既存鍵の使用 GC上にSSH鍵が書いてあるところが2か所ある。(組織所属だから?) - VMインスタンスのSSH 認証鍵の欄に`ecdsa-sha2-nistp256`, `ssh-rsa`の2種類 (`-----BEGIN OPENSSH PRIVATE KEY-----`みたいな書き方はしてない。) `ssh-rsa`の方を試してみたけど ```sh > ssh 34.172.125.65 -i ~/.ssh/hoge.pub [user]@"[インスタンスの公開IP]": Permission denied (publickey). ``` となった。(.pubの拡張子を消したりもした) - CEの[メタデータ](https://console.cloud.google.com/compute/metadata?resourceTab=sshkeys&project=portal-key-390113)の`SSH 認証鍵の欄`から自分の`ユーザー名`のキーをコピー、手元でファイルにして↑と同じようにやるも同じ結果。 じゃあ手元で作成したsshキーをGCに登録しようかと思ったところ、 Google Cloud : [VM に SSH 認証鍵を追加する](https://cloud.google.com/compute/docs/connect/add-ssh-keys?hl=ja#rest) > 注意: メタデータで SSH 認証鍵を管理すると、プロジェクト メンバーが VM に接続できなくなる場合があります。また、プロジェクト外のユーザーを含むユーザーに VM への意図しないアクセス権を付与するリスクがあります。プロジェクト メタデータを変更できるユーザーとサービス アカウントは、プロジェクト レベルの SSH 認証鍵をブロックする VM を除く、プロジェクト内のすべての VM の SSH 認証鍵を追加できます。詳しくは、[手動での鍵管理のリスク](https://cloud.google.com/compute/docs/instances/access-overview?hl=ja#risks)をご覧ください。 一旦ssh諦めます。 また、AWSのssh接続では`-----BEGIN OPENSSH PRIVATE KEY-----`で始まる.pemを使ってたのでちょっと不思議。どっちでもいいのか。AWSの方が珍しいのかな。 (もしかしてファイアウォールで穴開けてないから?) --- ↑諦めたので ブラウザで接続する。 VMインスタンスにて、下画像のブラウザでウィンドウを開く、でブラウザでかってにSSH接続してくれるみたい。 難なくできた。 ### ファイアウォール設定 https://console.cloud.google.com/net-security/firewall-manager/firewall-policies/list?project=portal-key-390113 にて 名前 : shari-v-kara 説明 : 何かあれば確認せず消してください(要約) ログ : オフ ネットワーク : デフォルト 優先度 : `60000` トラフィック : 上り 一致したときのアクション : 許可 ソースフィルタ : IPv4 範囲 送信元 : `[自分のpc?]/32` /32にすることでサブドメインまで許されるらしい。 (自分のPCのサブドメインってなんだ) 一致したときのアクション : 許可 プロトコルとポート : TCP : ポート ; `22, 80, 443, 3306` …ファイアウォールってVMインスタンス毎じゃなくてプロジェクト毎の設定?ならやる意味なかったかも。 でもdefaultが残ってたしそんな訳ないと思うんだけど…。 誰かのブログ : [Compute Engine にデプロイ](https://cloud.google.com/build/docs/deploying-builds/deploy-compute-engine?hl=ja)

インスタンス作成時にHTTP, HTTPSのファイアウォールオンにしておけばひもづけられたんじゃね? 立てた後でオン/オフ変更できるのだろうか。

色々やり直そう

shari-sushi commented 6 months ago

VM編集、SSH鍵作成からやり直し

VScode ターミナルで

> ssh-keygen -t rsa -b 4096 -f gc_v_kara
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in gc_v_kara.
Your public key has been saved in gc_v_kara.pub.
The key fingerprint is:
SHA256: ***
The key's randomart image is:
+---[RSA 4096]----+
|       ~略~      |
+----[SHA256]-----+

ここで生成された gc_v_kara.pubファイルの全文(SSH公開鍵)をコピー

前のコメントで作成していたVMを編集

どういうことか分からなかったので、 公式 : ネットワーク タグを追加する

タグは、Compute Engine 仮想マシン(VM)インスタンスやインスタンス テンプレートなどのリソースのタグフィールドに追加される文字からなる文字列です。タグは個別のリソースではないため、個別に作成することはできません。

えぇ…状況から予想はしてたけどまじか。 今まで読んできた記事はどういうことだ。最近変わったのか?

ファイアウォール ルールとルート

ネットワーク タグを使用すると、特定のインスタンスまたは一連のインスタンスにファイアウォール ルールとルートを適用できます。 ターゲットタグとソースタグを使用して、特定のインスタンスに適用されるファイアウォール ルールを作成します。 タグを使用して、特定のインスタンスに適用されるルートを作成します。

どっちのタグをどっちに付ける? まあいいや

これでインスタンスの編集終了。 したら、インスタンスのSSG認証鍵に、入力したSSH鍵は表示されたけどユーザー名が-になってる。大丈夫だろうか。

外部IPアドレスを確認したが、↓の通りSSH接続できず。

> ssh ***  -i ~/.ssh/gc_v_kara        
The authenticity of host ***(***)' can't be established.
ECDSA key fingerprint is SHA256: ***.  
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '***' (ECDSA) to the list of known hosts.
***@***: Permission denied (publickey).

> ssh ***  -i ~/.ssh/gc_v_kara.pub
***@***: Permission denied (publickey).

後日、

ssh user名@*** -i ~/.ssh/gc_v_kara.pub 的なこともしたけどだめだった

※新規IPは確認表示があり、yesする度にknown_hostsに溜まっていくので、何となく都度削除している。 インスタンスは機動から12時間で自動で停止するようにしてるから。(再起動の度にpublic IP変わるから)

でも下画像からブラウザならアクセスできるんだよな。 image

流石にダメだった

ブラウザSSH接続で実験 ```sh > mkdir v-kara > cd v-kara > git clone https://github.com/shari-sushi/V-Kara-Lists.git -bash: git: command not found > git install -bash: git: command not found ``` 調べたらできるのかもしれないけど、それは後日。 (正しくはgit initだったけどそもそもgit command使えないっちゅう)

shari-sushi commented 6 months ago
ブラウザからSSH接続できなくなった気がしたけど気の精だった?

![image](https://github.com/shari-sushi/0025Linux/assets/127638412/73d30422-27d7-4ebf-8ac0-376931eb4844) https://stackoverflow.com/questions/69265736/how-to-solve-error-4003-on-ssh-google-cloud-platform GCEのSSH接続の解説記事 https://blog.g-gen.co.jp/entry/ssh-to-compute-engine-vm > 基本的には 0.0.0.0/0 から該当インスタンスへの 22/TCP を VPC ファイアウォールルールで許可する必要があります。Google のパブリック IP は不定のためです。 サーバー再起動してIP変わったからかー 都度設定するの面倒だな - 選択肢 - サーバー自動停止をやめる - ファイアウォール側で自動追尾できるようにする - 面倒だけど毎回設定する - 1と3の折衷案…自動停止の期間を延ばす

ファイアウォールに新しい公開IPを…これ自分のPCのIPアドレス/32入れた気がするわ。 てかいつの間にかインスタンス止まってて、再開したら接続できた。

shari-sushi commented 6 months ago

サーバーを立てる

GCP (Google Cloud Platform) の Compute Engine で爆速で Web アプリ環境を用意する全手順

  • GCP でユーザ登録 ~略~
  • インスタンス作成 ~略~
  • Web サーバ導入 次に、Nginx をインストールする。今回は ContOS7 に入れてるので「こちら」の記事を参考にインストールする。 これで、http://外部IPアドレス にアクセスして、Web サイトが公開できた。 以上で Web アプリの環境が完成した。あとは、各自のソースコードを適所にデプロイしてあげるだけ

LinuC用、v-kara用の両インスタンスにてOSの確認が取れなかった (初見の何かを選んだ気がするんだけども→多分debianだ) image あった? image

【第30回】DebianとUbuntu、CentOSとRHELから学ぶ、Upstreamとの関係

Ubuntuに対してDebianは「選択の自由」も重要視している。たとえばDebianはインストール時にデスクトップ環境を選択できるし、Ubuntuに比べるとサポートしているCPUアーキテクチャも多い。使用するソフトウェアを決め打ちすることで、Live環境とインストーラーを同一化させ初心者が悩まないようにしているUbuntuとは対照的だろう。

とりあえず先に進んで、ダメそうならOSが無いor不適合かもという判断をする。

CentOS7 に Nginx をインストールする

$ sudo ls /etc/yum.repos.d/nginx.repo
ls: cannot access '/etc/yum.repos.d/nginx.repo': No such file or directory
sudo vi /etc/yum.repos.d/nginx.repo

で作成、書き込みを同時にしたのに権限エラーってまじか。てか空にしても同じエラー。

E212: Can't open file for writing

↓でできた

$ mkdir  ./etc/yum.repos.d/
$ touch  ./etc/yum.repos.d/nginx.repo
$ ls  ./etc/yum.repos.d/nginx.repo
$ ls -l ./etc/yum.repos.d/
total 0
-rw-r--r-- 1 [myname] [myname] 0 May  4 06:12 nginx.repo
$ sudo vi /etc/yum.repos.d/nginx.repo

書き込んだ内容

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1

このあとの操作。 せっかくならシェルスクリプトやりたかったけど、出力を読みってwhileで回してinputを求めるor全てのinputを求めるのに自動でyesの解答するみたいなの書き方調べるのちょっと横道にそれすぎなのでやめた(言い訳)

# nginxをインストール (質問は全て「Y」で肯定)
sudo yum install nginx

# バージョンの確認
nginx -v

# 自動起動設定 (初回の場合はシンボリックリンクが作成される)
sudo systemctl enable nginx

# 起動
sudo systemctl start nginx
sudo yum install nginx
sudo: yum: command not found

https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q13207829133

yumは、linuxの中でも、Fedora , RedHat , CentOSなどのディストリビューションで標準として使用されるパッケージ管理ソフトです。

ですが、あなたのlinuxは恐らくDebian , Ubuntuなどのディストリビューションです。これらのlinuxでのパッケージ管理ソフトではyumではなくaptと言うパッケージ管理ソフトを使用します

なるほど?

$ sudo apt install yum
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package yum is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'yum' has no installation candidate

だめなんかい。

$ sudo apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  nginx-common
Suggested packages:
  fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
  nginx nginx-common
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 640 kB of archives.
After this operation, 1696 kB of additional disk space will be used.

Do you want to continue? [Y/n] Y
Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B]
Get:2 https://deb.debian.org/debian bookworm/main amd64 nginx-common all 1.22.1-9 [112 kB]
Get:3 https://deb.debian.org/debian bookworm/main amd64 nginx amd64 1.22.1-9 [527 kB]
Fetched 640 kB in 0s (1438 kB/s)
Preconfiguring packages ...
Selecting previously unselected package nginx-common.
(Reading database ... 67169 files and directories currently installed.)
Preparing to unpack .../nginx-common_1.22.1-9_all.deb ...
Unpacking nginx-common (1.22.1-9) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.22.1-9_amd64.deb ...
Unpacking nginx (1.22.1-9) ...
Setting up nginx-common (1.22.1-9) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.
Setting up nginx (1.22.1-9) ...
Upgrading binary: nginx.
Processing triggers for man-db (2.11.2-2) ...

lsで確認したところ、 /libにインストールされた気がするけど大丈夫だろうか。

$ sudo apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
nginx is already the newest version (1.22.1-9).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
$ nginx -v
-bash: nginx: command not found

どういうこっちゃ

$ echo $nginx

コマンドのpathが設定されてないのか?(うろ覚えだけどそんなことを前に教わったような)

debianにnginxをインストールする方法見つけた…

で、うまくいかなかった

Nginex 公式?: https://nginx.org/en/linux_packages.html#Debian ```sh $ cat /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck=0 enabled=1 $ nginx -v -bash: nginx: command not found $ sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring Reading package lists... Done Building dependency tree... Done Reading state information... Done curl is already the newest version (7.88.1-10+deb12u5). ca-certificates is already the newest version (20230311). lsb-release is already the newest version (12.0-1). lsb-release set to manually installed. debian-archive-keyring is already the newest version (2023.3+deb12u1). The following NEW packages will be installed: gnupg2 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 445 kB of archives. After this operation, 464 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B] Get:2 https://deb.debian.org/debian bookworm/main amd64 gnupg2 all 2.2.40-1.1 [445 kB] Fetched 445 kB in 0s (1382 kB/s) Selecting previously unselected package gnupg2. (Reading database ... 67221 files and directories currently installed.) Preparing to unpack .../gnupg2_2.2.40-1.1_all.deb ... Unpacking gnupg2 (2.2.40-1.1) ... Setting up gnupg2 (2.2.40-1.1) ... Processing triggers for man-db (2.11.2-2) ... $ ls /usr/share/keyrings/nginx-archive-keyring.gpg ls: cannot access '/usr/share/keyrings/nginx-archive-keyring.gpg': No such file or directory $ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1561 100 1561 0 0 2500 0 --:--:-- --:--:-- --:--:-- 2501 $ gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14] 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 uid nginx signing key $ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ http://nginx.org/packages/debian `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian bookworm nginx $ ls /etc/apt/preferences.d/99nginx ls: cannot access '/etc/apt/preferences.d/99nginx': No such file or directory $ echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \ | sudo tee /etc/apt/preferences.d/99nginx Package: * Pin: origin nginx.org Pin: release o=nginx Pin-Priority: 900 $ ^C $ sudo apt update Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B] Get:5 file:/etc/apt/mirrors/debian-security.list Mirrorlist [39 B] Get:7 https://packages.cloud.google.com/apt google-compute-engine-bookworm-stable InRelease [1321 B] Get:8 https://packages.cloud.google.com/apt cloud-sdk-bookworm InRelease [6406 B] Get:2 https://deb.debian.org/debian bookworm InRelease [151 kB] Get:9 http://nginx.org/packages/debian bookworm InRelease [2860 B] Get:10 https://packages.cloud.google.com/apt google-compute-engine-bookworm-stable/main all Packages [2830 B] Get:11 https://packages.cloud.google.com/apt google-compute-engine-bookworm-stable/main amd64 Packages [3128 B] Get:3 https://deb.debian.org/debian bookworm-updates InRelease [55.4 kB] Get:4 https://deb.debian.org/debian bookworm-backports InRelease [56.5 kB] Get:12 https://packages.cloud.google.com/apt cloud-sdk-bookworm/main amd64 Packages [482 kB] Get:6 https://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB] Get:13 http://nginx.org/packages/debian bookworm/nginx amd64 Packages [7975 B] Get:14 https://deb.debian.org/debian bookworm-updates/main Sources.diff/Index [10.6 kB] Get:15 https://deb.debian.org/debian bookworm-updates/main amd64 Packages.diff/Index [10.6 kB] Get:16 https://deb.debian.org/debian bookworm-updates/main Translation-en.diff/Index [10.6 kB] Get:17 https://deb.debian.org/debian bookworm-updates/main Sources T-2024-04-23-2036.10-F-2024-04-23-2036.10.pdiff [831 B] Get:18 https://deb.debian.org/debian bookworm-updates/main amd64 Packages T-2024-04-23-2036.10-F-2024-04-23-2036.10.pdiff [1595 B] Get:17 https://deb.debian.org/debian bookworm-updates/main Sources T-2024-04-23-2036.10-F-2024-04-23-2036.10.pdiff [831 B] Get:18 https://deb.debian.org/debian bookworm-updates/main amd64 Packages T-2024-04-23-2036.10-F-2024-04-23-2036.10.pdiff [1595 B] Get:22 https://deb.debian.org/debian bookworm-updates/main Translation-en T-2024-04-23-2036.10-F-2024-04-23-2036.10.pdiff [2563 B] Get:22 https://deb.debian.org/debian bookworm-updates/main Translation-en T-2024-04-23-2036.10-F-2024-04-23-2036.10.pdiff [2563 B] Get:19 https://deb.debian.org/debian bookworm-backports/main Sources.diff/Index [63.3 kB] Get:20 https://deb.debian.org/debian bookworm-backports/main amd64 Packages.diff/Index [63.3 kB] Get:21 https://deb.debian.org/debian bookworm-backports/main Translation-en.diff/Index [63.3 kB] Get:26 https://deb.debian.org/debian bookworm-backports/main Sources T-2024-05-04-2020.06-F-2024-04-15-2018.42.pdiff [19.4 kB] Get:26 https://deb.debian.org/debian bookworm-backports/main Sources T-2024-05-04-2020.06-F-2024-04-15-2018.42.pdiff [19.4 kB] Get:27 https://deb.debian.org/debian bookworm-backports/main amd64 Packages T-2024-05-04-0204.48-F-2024-04-15-2018.42.pdiff [17.5 kB] Get:27 https://deb.debian.org/debian bookworm-backports/main amd64 Packages T-2024-05-04-0204.48-F-2024-04-15-2018.42.pdiff [17.5 kB] Get:28 https://deb.debian.org/debian bookworm-backports/main Translation-en T-2024-05-01-1413.56-F-2024-04-19-2009.49.pdiff [7671 B] Get:28 https://deb.debian.org/debian bookworm-backports/main Translation-en T-2024-05-01-1413.56-F-2024-04-19-2009.49.pdiff [7671 B] Get:23 https://deb.debian.org/debian-security bookworm-security/main Sources [92.2 kB] Get:24 https://deb.debian.org/debian-security bookworm-security/main amd64 Packages [156 kB] Get:25 https://deb.debian.org/debian-security bookworm-security/main Translation-en [94.9 kB] Fetched 1431 kB in 1s (986 kB/s) Reading package lists... Done Building dependency tree... Done Reading state information... Done 6 packages can be upgraded. Run 'apt list --upgradable' to see them. $ sudo apt install nginx Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages will be REMOVED: nginx-common The following packages will be upgraded: nginx 1 upgraded, 0 newly installed, 1 to remove and 5 not upgraded. Need to get 1015 kB of archives. After this operation, 1818 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://nginx.org/packages/debian bookworm/nginx amd64 nginx amd64 1.26.0-1~bookworm [1015 kB] Fetched 1015 kB in 1s (1124 kB/s) Reading changelogs... Done dpkg: nginx-common: dependency problems, but removing anyway as you requested: nginx depends on nginx-common (<< 1.22.1-9.1~). nginx depends on nginx-common (>= 1.22.1-9). nginx depends on nginx-common (<< 1.22.1-9.1~). nginx depends on nginx-common (>= 1.22.1-9). (Reading database ... 67228 files and directories currently installed.) Removing nginx-common (1.22.1-9) ... (Reading database ... 67205 files and directories currently installed.) Preparing to unpack .../nginx_1.26.0-1~bookworm_amd64.deb ... Unpacking nginx (1.26.0-1~bookworm) over (1.22.1-9) ... Setting up nginx (1.26.0-1~bookworm) ... Installing new version of config file /etc/default/nginx ... Installing new version of config file /etc/init.d/nginx ... Installing new version of config file /etc/logrotate.d/nginx ... Installing new version of config file /etc/nginx/fastcgi_params ... Installing new version of config file /etc/nginx/mime.types ... Installing new version of config file /etc/nginx/nginx.conf ... Processing triggers for man-db (2.11.2-2) ... $ nginx -v -bash: nginx: command not found ---



https://qiita.com/lookung4/items/82c82ba8f152408e6f77
立ち上げる前にurl設定が必要?htmlサーバだから?

https://zenn.dev/wataru1982/articles/5bcc3cb44a6804

---

sentOSでインスタンス作ったらyumコマンドは使えた。

---
今回はGCEにデプロイすることが目的なのでサーバー比較してないけど、時間余れば比較したい
[NginxとApacheの違い─2つの定番ウェブサーバーを詳しく比較](https://kinsta.com/jp/blog/nginx-vs-apache/)
[ApacheとNginxについて比較](https://qiita.com/kamihork/items/49e2a363da7d840a4149)
[NginxとApacheを比較解説!メリット・デメリットも紹介](https://www.geekly.co.jp/column/cat-technology/1903_096/)
shari-sushi commented 6 months ago

nginx コマンドが認識されない

https://kyoruni.hatenablog.com/entry/nginx-install どの記事見ても、install直後にそのままnginx -vしてる

ちなみにいまこんな状態

```sh $ sudo apt update Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B] Get:3 file:/etc/apt/mirrors/debian-security.list Mirrorlist [39 B] Hit:7 https://packages.cloud.google.com/apt google-compute-engine-bookworm-stable InRelease Hit:8 https://packages.cloud.google.com/apt cloud-sdk-bookworm InRelease Hit:2 https://deb.debian.org/debian bookworm InRelease Get:4 https://deb.debian.org/debian bookworm-updates InRelease [55.4 kB] Hit:9 http://nginx.org/packages/debian bookworm InRelease Get:5 https://deb.debian.org/debian bookworm-backports InRelease [56.5 kB] Get:6 https://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB] Get:10 https://deb.debian.org/debian bookworm-backports/main Sources.diff/Index [63.3 kB] Get:11 https://deb.debian.org/debian bookworm-backports/main amd64 Packages.diff/Index [63.3 kB] Get:14 https://deb.debian.org/debian bookworm-backports/main Sources T-2024-05-06-0204.56-F-2024-05-05-0209.30.pdiff [2418 B] Get:14 https://deb.debian.org/debian bookworm-backports/main Sources T-2024-05-06-0204.56-F-2024-05-05-0209.30.pdiff [2418 B] Get:15 https://deb.debian.org/debian bookworm-backports/main amd64 Packages T-2024-05-05-2005.45-F-2024-05-05-0807.24.pdiff [3261 B] Get:15 https://deb.debian.org/debian bookworm-backports/main amd64 Packages T-2024-05-05-2005.45-F-2024-05-05-0807.24.pdiff [3261 B] Get:12 https://deb.debian.org/debian-security bookworm-security/main Sources [91.9 kB] Get:13 https://deb.debian.org/debian-security bookworm-security/main amd64 Packages [156 kB] Fetched 540 kB in 1s (387 kB/s) Reading package lists... Done Building dependency tree... Done Reading state information... Done 2 packages can be upgraded. Run 'apt list --upgradable' to see them. $ sudo apt install nginx Reading package lists... Done Building dependency tree... Done Reading state information... Done nginx is already the newest version (1.26.0-1~bookworm). 0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded. $ nginx -v -bash: nginx: command not found ```

pathが通っていないのか他に理由があるのか https://atmarkit.itmedia.co.jp/flinux/rensai/linuxtips/035addnewpath.html

path通し方 https://qiita.com/ryouya3948/items/8edbd5d744c83dd41141

問題はどこに通すかなんだよな

これで親の親から探してみるかね https://www.sejuku.net/blog/54248

$ which ls
/usr/bin/ls

$ wichi nginx
-bash: wichi: command not found

etc/yum.repos.d/nginx.repoこれも怪しいよね

ls ../../usr/bin の結果、そこにnginxっぽいフォルダ、ファイルは無かった。

treeコマンド入れてみた。

$ sudo apt-get install tree
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  tree
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 52.5 kB of archives.
After this operation, 116 kB of additional disk space will be used.
Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B]
Get:2 https://deb.debian.org/debian bookworm/main amd64 tree amd64 2.1.0-1 [52.5 kB]
Fetched 52.5 kB in 0s (139 kB/s)
Selecting previously unselected package tree.
(Reading database ... 67223 files and directories currently installed.)
Preparing to unpack .../tree_2.1.0-1_amd64.deb ...
Unpacking tree (2.1.0-1) ...
Setting up tree (2.1.0-1) ...
Processing triggers for man-db (2.11.2-2) ...

$ tree .
.
├── etc
│   └── yum.repos.d
│       └── nginx.repo
├── shellscript
│   └── mk-nginx.sh
├── v-kara
│   ├── test1
│   └── test2
└── v-kara-front

./shellscript/mk-nginx.shは自作の全く機能しないファイル

AIに聞いてみたらnginx入ってるのは分かった。

$ /usr/sbin/nginx -v
nginx version: nginx/1.26.0

$ export PATH=$PATH:/usr/sbin/nginx
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin/nginx

$ nginx -v
-bash: nginx: command not found
susi_imo_niku@kawai-v-kara:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin/nginx
$ $nginx -v
nginx version: nginx/1.26.0
$ nginx -v
-bash: nginx: command not found
shari-sushi commented 6 months ago

【Debian】Debianでnginxをインストールして、htmlの編集をした。(公式の微解説)

について何してるか調べる。

# 下準備
①sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring

# keyの取得(※\は改行のこと)
②curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

# キーの確認
③gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

# 上のコマンドを打ったときの出力例
④pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
      573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid                      nginx signing key <signing-key@nginx.com>

# stable nginxのセットアップ(後述のmainline版のどちらかでセットアップする)
⑤echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian `lsb_release -cs` nginx" \
   | sudo tee /etc/apt/sources.list.d/nginx.list

# mainline nginxのセットアップ(stableかmainlineか)
⑥echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

# リポジトリのセットアップ
⑦echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx

# ようやくインストール
⑧sudo apt update
⑨sudo apt install nginx

※丸番号は私の加筆

shari-sushi commented 6 months ago

ubuntuでした……なんで ubuntuならgitコマンド最初から打てた。 (treeはダメだった)

https://qiita.com/keitean/items/9b2284a053bc13bcdf7b

ってか、これの通り従っちゃだめか?

/v-kara/V-Kara-Lists/t0016Go/cmd$ go run .

Command 'go' not found, but can be installed with:

snap install go         # version 1.22.2, or
apt  install golang-go  # version 2:1.13~1ubuntu2
apt  install gccgo-go   # version 2:1.13~1ubuntu2

See 'snap info go' for additional versions.

https://subro.mokuren.ne.jp/0400.html を参考に、

:~/v-kara/V-Kara-Lists/t0016Go/cmd$ sudo snap install go --classic
go 1.22.2 from Canonical✓ installed
:~/v-kara/V-Kara-Lists/t0016Go/cmd$ go run .
start to godotenc.Load
sart to initAesEnv
failed to convert to bcryptCost. err:strconv.Atoi: parsing "": invalid syntax
guestId:0
クラウド環境で起動
goEnv ==  && isDocker ==  
GUEST_USER_NAME= 
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /health                   --> main.main.func1 (4 handlers)
path=:@tcp(:3306)/?charset=utf8mb4&parseTime=true 

2024/05/06 15:39:35 ~***~/v-kara/V-Kara-Lists/t0016Go/infra/db.go:87
[error] failed to initialize database, got error dial tcp :3306: connect: connection refused
panic: failed to connect database

goroutine 1 [running]:
github.com/shari-sushi/0016go_next_relation/infra.dbInit()
        ~***~/v-kara/V-Kara-Lists/t0016Go/infra/db.go:94 +0x4dd
github.com/shari-sushi/0016go_next_relation/infra.Routing(0xc0000da820)
       ~***~/v-kara/V-Kara-Lists/t0016Go/infra/routing.go:12 +0x2a
main.main()
       ~***~/v-kara/V-Kara-Lists/t0016Go/cmd/main.go:42 +0x37f
exit status 2

MySQL用意して、環境変数を渡してやればそのまま起動しそう。

$ npx

Command 'npx' not found, but can be installed with:

apt install npm
Please ask your administrator.

$ npm

Command 'npm' not found, but can be installed with:

apt install npm
Please ask your administrator.

npx,npmもインストール必要っぽい


メモ

cd  v-kara/V-Kara-Lists/t0016Go/cmd
go run .
shari-sushi commented 6 months ago

ToDo

※環境変数ってVMインスタンス単位?それとも個別?

shari-sushi commented 6 months ago

MySQLインストール

https://cloud.google.com/compute/docs/instances/sql-server/setup-mysql?hl=ja#ubuntu

install MySQL

```sh $ sudo apt-get -y install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0 Suggested packages: libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca The following NEW packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0 0 upgraded, 26 newly installed, 0 to remove and 0 not upgraded. Need to get 36.8 MB of archives. After this operation, 318 MB of additional disk space will be used. Get:1 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mysql-common all 5.8+1.0.5ubuntu2 [7496 B] Get:2 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client-core-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [5084 kB] Get:3 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [22.0 kB] Get:4 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libevent-core-2.1-7 amd64 2.1.11-stable-1 [89.1 kB] Get:5 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libevent-pthreads-2.1-7 amd64 2.1.11-stable-1 [7372 B] Get:6 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libmecab2 amd64 0.996-10build1 [233 kB] Get:7 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libnuma1 amd64 2.0.12-1 [20.8 kB] Get:8 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server-core-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [22.7 MB] Get:9 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server-8.0 amd64 8.0.36-0ubuntu0.20.04.1 [1326 kB] Get:10 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhtml-tagset-perl all 3.20-4 [12.5 kB] Get:11 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 liburi-perl all 1.76-2 [77.5 kB] Get:12 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhtml-parser-perl amd64 3.72-5 [86.3 kB] Get:13 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libcgi-pm-perl all 4.46-1 [186 kB] Get:14 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libfcgi-perl amd64 0.79-1 [33.1 kB] Get:15 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libcgi-fast-perl all 1:2.15-1 [10.5 kB] Get:16 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libencode-locale-perl all 1.05-1 [12.3 kB] Get:17 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhtml-template-perl all 2.97-1 [59.0 kB] Get:18 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libtimedate-perl all 2.3200-1 [34.0 kB] Get:19 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhttp-date-perl all 6.05-1 [9920 B] Get:20 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libio-html-perl all 1.001-1 [14.9 kB] Get:21 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 liblwp-mediatypes-perl all 6.04-1 [19.5 kB] Get:22 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 libhttp-message-perl all 6.22-1 [76.1 kB] Get:23 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mecab-utils amd64 0.996-10build1 [4912 B] Get:24 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic all 2.7.0-20070801+main-2.1 [6714 kB] Get:25 http://us-central1.gce.archive.ubuntu.com/ubuntu focal/main amd64 mecab-ipadic-utf8 all 2.7.0-20070801+main-2.1 [4380 B] Get:26 http://us-central1.gce.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server all 8.0.36-0ubuntu0.20.04.1 [9484 B] Fetched 36.8 MB in 1s (37.4 MB/s) Preconfiguring packages ... Selecting previously unselected package mysql-common. (Reading database ... 62124 files and directories currently installed.) Preparing to unpack .../0-mysql-common_5.8+1.0.5ubuntu2_all.deb ... Unpacking mysql-common (5.8+1.0.5ubuntu2) ... Selecting previously unselected package mysql-client-core-8.0. Preparing to unpack .../1-mysql-client-core-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package mysql-client-8.0. Preparing to unpack .../2-mysql-client-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package libevent-core-2.1-7:amd64. Preparing to unpack .../3-libevent-core-2.1-7_2.1.11-stable-1_amd64.deb ... Unpacking libevent-core-2.1-7:amd64 (2.1.11-stable-1) ... Selecting previously unselected package libevent-pthreads-2.1-7:amd64. Preparing to unpack .../4-libevent-pthreads-2.1-7_2.1.11-stable-1_amd64.deb ... Unpacking libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ... Selecting previously unselected package libmecab2:amd64. Preparing to unpack .../5-libmecab2_0.996-10build1_amd64.deb ... Unpacking libmecab2:amd64 (0.996-10build1) ... Selecting previously unselected package libnuma1:amd64. Preparing to unpack .../6-libnuma1_2.0.12-1_amd64.deb ... Unpacking libnuma1:amd64 (2.0.12-1) ... Selecting previously unselected package mysql-server-core-8.0. Preparing to unpack .../7-mysql-server-core-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-common (5.8+1.0.5ubuntu2) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Selecting previously unselected package mysql-server-8.0. (Reading database ... 62345 files and directories currently installed.) Preparing to unpack .../00-mysql-server-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package libhtml-tagset-perl. Preparing to unpack .../01-libhtml-tagset-perl_3.20-4_all.deb ... Unpacking libhtml-tagset-perl (3.20-4) ... Selecting previously unselected package liburi-perl. Preparing to unpack .../02-liburi-perl_1.76-2_all.deb ... Unpacking liburi-perl (1.76-2) ... Selecting previously unselected package libhtml-parser-perl. Preparing to unpack .../03-libhtml-parser-perl_3.72-5_amd64.deb ... Unpacking libhtml-parser-perl (3.72-5) ... Selecting previously unselected package libcgi-pm-perl. Preparing to unpack .../04-libcgi-pm-perl_4.46-1_all.deb ... Unpacking libcgi-pm-perl (4.46-1) ... Selecting previously unselected package libfcgi-perl. Preparing to unpack .../05-libfcgi-perl_0.79-1_amd64.deb ... Unpacking libfcgi-perl (0.79-1) ... Selecting previously unselected package libcgi-fast-perl. Preparing to unpack .../06-libcgi-fast-perl_1%3a2.15-1_all.deb ... Unpacking libcgi-fast-perl (1:2.15-1) ... Selecting previously unselected package libencode-locale-perl. Preparing to unpack .../07-libencode-locale-perl_1.05-1_all.deb ... Unpacking libencode-locale-perl (1.05-1) ... Selecting previously unselected package libhtml-template-perl. Preparing to unpack .../08-libhtml-template-perl_2.97-1_all.deb ... Unpacking libhtml-template-perl (2.97-1) ... Selecting previously unselected package libtimedate-perl. Preparing to unpack .../09-libtimedate-perl_2.3200-1_all.deb ... Unpacking libtimedate-perl (2.3200-1) ... Selecting previously unselected package libhttp-date-perl. Preparing to unpack .../10-libhttp-date-perl_6.05-1_all.deb ... Unpacking libhttp-date-perl (6.05-1) ... Selecting previously unselected package libio-html-perl. Preparing to unpack .../11-libio-html-perl_1.001-1_all.deb ... Unpacking libio-html-perl (1.001-1) ... Selecting previously unselected package liblwp-mediatypes-perl. Preparing to unpack .../12-liblwp-mediatypes-perl_6.04-1_all.deb ... Unpacking liblwp-mediatypes-perl (6.04-1) ... Selecting previously unselected package libhttp-message-perl. Preparing to unpack .../13-libhttp-message-perl_6.22-1_all.deb ... Unpacking libhttp-message-perl (6.22-1) ... Selecting previously unselected package mecab-utils. Preparing to unpack .../14-mecab-utils_0.996-10build1_amd64.deb ... Unpacking mecab-utils (0.996-10build1) ... Selecting previously unselected package mecab-ipadic. Preparing to unpack .../15-mecab-ipadic_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mecab-ipadic-utf8. Preparing to unpack .../16-mecab-ipadic-utf8_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mysql-server. Preparing to unpack .../17-mysql-server_8.0.36-0ubuntu0.20.04.1_all.deb ... Unpacking mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up libmecab2:amd64 (0.996-10build1) ... Setting up mysql-client-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up libhtml-tagset-perl (3.20-4) ... Setting up liblwp-mediatypes-perl (6.04-1) ... Setting up libencode-locale-perl (1.05-1) ... Setting up mecab-utils (0.996-10build1) ... Setting up libevent-core-2.1-7:amd64 (2.1.11-stable-1) ... Setting up libio-html-perl (1.001-1) ... Setting up libtimedate-perl (2.3200-1) ... Setting up libnuma1:amd64 (2.0.12-1) ... Setting up mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up libfcgi-perl (0.79-1) ... Setting up liburi-perl (1.76-2) ... Setting up libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ... Setting up libhttp-date-perl (6.05-1) ... Setting up mecab-ipadic (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up mysql-server-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up libhtml-parser-perl (3.72-5) ... Setting up libhttp-message-perl (6.22-1) ... Setting up mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode Renaming removed key_buffer and myisam-recover options (if present) mysqld will log errors to /var/log/mysql/error.log mysqld is running as pid 4386 Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service. Setting up libcgi-pm-perl (4.46-1) ... Setting up libhtml-template-perl (2.97-1) ... Setting up mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up libcgi-fast-perl (1:2.15-1) ... Processing triggers for systemd (245.4-4ubuntu3.23) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9.15) ... ```

$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

MySQLをインストールしたときのログで気になってるのは、 mysqld is running as pid 4386 え、インストールした時点でmysqlは立ち上がってる?(プロセス扱いになってるってこと?)

プロセスの復習: https://github.com/shari-sushi/0025Linux/issues/1#issuecomment-2084858518

4.5.1.1 mysql クライアントオプション

--table, -t

出力を表形式で表示します。 インタラクティブに使用する場合はこれがデフォルトですが、バッチモードで表形式の出力を生成するのにも使用できます。


https://dev.mysql.com/doc/refman/8.0/ja/problems-connecting.html

新規インストールの後、パスワードを使用せずに root としてサーバーにログオンしようとすると、次のエラーメッセージが表示されることがあります。

shell> mysql -u root 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
これは、インストール時に root パスワードがすでに割り当てられており、指定する必要があることを意味します。

つまり、今回自分のにはパスワードが必要と。でも8.0では自動生成されないみたいなことが同じ公式に書いてあったのに…。

shari-sushi commented 6 months ago

MySQL接続

↑のコメントで

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

ってなったのはやっぱlocalhost扱いになってる?

それはさておき、まずはパスワード探し https://qiita.com/RyosukeSomeya/items/c695487588f5ac28d9f4

/var/log/mysqld.log このファイルをviコマンドやlessコマンドで確認すると以下の様なログがあるはずです。 [Note] A temporary password is generated for root@localhost: Ea

親の親ディレクトリにvar/log/mysqlはあったけどmysqld.logは無かった。 それ開いたけどログじゃなかった。正規表現とコマンド?オプション?が書いてあった。

わかんないからGCEのルートでgrep

grep temporary password

10分以上待っても終わらなかった…

mysql.logなさそう(色々あった)

$ ls ../../etc/my*

↓この状態で、viで開くと、以下の画像のように新規ファイルとなり、中身は空。なぜ。

:/etc$ ls my*
conf.d  debian-start  debian.cnf  my.cnf  my.cnf.fallback  mysql.cnf  mysql.conf.d
:/etc$ vi my.cnf
:/etc$ vi mysql.cnf

image

shari-sushi commented 6 months ago

メモ

https://www.web-dev-qa-db-ja.com/ja/command-line/lsの色の違いは何を意味しますか?/957164827/

青:ディレクトリ 緑:実行可能または認識されたデータファイル スカイブルー:シンボリックリンクファイル 背景が黒の黄色:デバイス ピンク:グラフィック画像ファイル 赤:アーカイブファイル 背景が黒の赤:リンク切れ

わわわ: シンボリックリンク

UNIX系のOS(Linuxとか)における、ファイルやフォルダの代理人ファイルのこと。

Windowsにおける「ショートカット」のUNIX系OSにおける呼び名

shari-sushi commented 6 months ago

MySQL入れ直し

logファイルもない、my.cnfもない(…多分)でよくわからなかったので、入れ直し。

sudo apt purge mysql*

→質問されるので Y と回答

アンインストール ログ

``` $ sudo apt purge mysql* Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting 'mysql-source-8.0' for glob 'mysql*' Note, selecting 'mysqltcl' for glob 'mysql*' Note, selecting 'mysql-client-5.5' for glob 'mysql*' Note, selecting 'mysql-client-5.6' for glob 'mysql*' Note, selecting 'mysql-client-5.7' for glob 'mysql*' Note, selecting 'mysql-common-5.6' for glob 'mysql*' Note, selecting 'mysql-server-5.5' for glob 'mysql*' Note, selecting 'mysql-server-5.6' for glob 'mysql*' Note, selecting 'mysql-server-5.7' for glob 'mysql*' Note, selecting 'mysql-client-8.0' for glob 'mysql*' Note, selecting 'mysql-testsuite' for glob 'mysql*' Note, selecting 'mysql-server' for glob 'mysql*' Note, selecting 'mysql-router' for glob 'mysql*' Note, selecting 'mysql-server-8.0' for glob 'mysql*' Note, selecting 'mysql-client' for glob 'mysql*' Note, selecting 'mysql-sandbox' for glob 'mysql*' Note, selecting 'mysql-client-core-5.5' for glob 'mysql*' Note, selecting 'mysql-client-core-5.6' for glob 'mysql*' Note, selecting 'mysql-client-core-5.7' for glob 'mysql*' Note, selecting 'mysql-client-core-8.0' for glob 'mysql*' Note, selecting 'mysql-testsuite-5.5' for glob 'mysql*' Note, selecting 'mysql-testsuite-5.6' for glob 'mysql*' Note, selecting 'mysql-testsuite-5.7' for glob 'mysql*' Note, selecting 'mysql-common' for glob 'mysql*' Note, selecting 'mysql-testsuite-8.0' for glob 'mysql*' Note, selecting 'mysqltuner' for glob 'mysql*' Note, selecting 'mysql-server-core-5.5' for glob 'mysql*' Note, selecting 'mysql-server-core-5.6' for glob 'mysql*' Note, selecting 'mysql-server-core-5.7' for glob 'mysql*' Note, selecting 'mysql-server-core-8.0' for glob 'mysql*' Package 'mysql-client-5.7' is not installed, so not removed Package 'mysql-client-core-5.7' is not installed, so not removed Note, selecting 'mysql-common' instead of 'mysql-common-5.6' Package 'mysql-server-5.5' is not installed, so not removed Package 'mysql-server-5.7' is not installed, so not removed Package 'mysql-server-core-5.7' is not installed, so not removed Package 'mysql-client-core-5.5' is not installed, so not removed Package 'mysql-client-core-5.6' is not installed, so not removed Package 'mysql-client-5.5' is not installed, so not removed Package 'mysql-client-5.6' is not installed, so not removed Package 'mysql-server-core-5.5' is not installed, so not removed Package 'mysql-server-core-5.6' is not installed, so not removed Package 'mysql-server-5.6' is not installed, so not removed Package 'mysql-testsuite-5.5' is not installed, so not removed Package 'mysql-testsuite-5.6' is not installed, so not removed Package 'mysql-testsuite-5.7' is not installed, so not removed Package 'mysql-sandbox' is not installed, so not removed Package 'mysqltcl' is not installed, so not removed Package 'mysqltuner' is not installed, so not removed Package 'mysql-client' is not installed, so not removed Package 'mysql-router' is not installed, so not removed Package 'mysql-source-8.0' is not installed, so not removed Package 'mysql-testsuite' is not installed, so not removed Package 'mysql-testsuite-8.0' is not installed, so not removed The following packages were automatically installed and are no longer required: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: mysql-client-8.0* mysql-client-core-8.0* mysql-common* mysql-server* mysql-server-8.0* mysql-server-core-8.0* 0 upgraded, 0 newly installed, 6 to remove and 3 not upgraded. After this operation, 259 MB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 62718 files and directories currently installed.) Removing mysql-server (8.0.36-0ubuntu0.20.04.1) ... Removing mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Removing mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Removing mysql-client-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Removing mysql-common (5.8+1.0.5ubuntu2) ... Removing mysql-server-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9.15) ... (Reading database ... 62502 files and directories currently installed.) Purging configuration files for mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... Purging configuration files for mysql-common (5.8+1.0.5ubuntu2) ... dpkg: warning: while removing mysql-common, directory '/etc/mysql' not empty so not removed Processing triggers for systemd (245.4-4ubuntu3.23) ... $ sudo apt autoremove Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils 0 upgraded, 0 newly installed, 20 to remove and 3 not upgraded. After this operation, 58.5 MB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 62482 files and directories currently installed.) Removing libcgi-fast-perl (1:2.15-1) ... Removing libhtml-template-perl (2.97-1) ... Removing libcgi-pm-perl (4.46-1) ... Removing libhttp-message-perl (6.22-1) ... Removing libencode-locale-perl (1.05-1) ... Removing libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ... Removing libevent-core-2.1-7:amd64 (2.1.11-stable-1) ... Removing libfcgi-perl (0.79-1) ... Removing libhtml-parser-perl (3.72-5) ... Removing libhtml-tagset-perl (3.20-4) ... Removing libhttp-date-perl (6.05-1) ... Removing libio-html-perl (1.001-1) ... Removing liblwp-mediatypes-perl (6.04-1) ... Removing mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Removing mecab-ipadic (2.7.0-20070801+main-2.1) ... Removing mecab-utils (0.996-10build1) ... Removing libmecab2:amd64 (0.996-10build1) ... Removing libnuma1:amd64 (2.0.12-1) ... Removing libtimedate-perl (2.3200-1) ... Removing liburi-perl (1.76-2) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9.15) ... :/$ sudo apt autoclean Reading package lists... Done Building dependency tree ```

インストール ログ

```sh :/$ sudo apt install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0 Suggested packages: libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca The following NEW packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0 0 upgraded, 26 newly installed, 0 to remove and 3 not upgraded. Need to get 0 B/36.8 MB of archives. After this operation, 318 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Preconfiguring packages ... Selecting previously unselected package mysql-common. (Reading database ... 62132 files and directories currently installed.) Preparing to unpack .../0-mysql-common_5.8+1.0.5ubuntu2_all.deb ... Unpacking mysql-common (5.8+1.0.5ubuntu2) ... Selecting previously unselected package mysql-client-core-8.0. Preparing to unpack .../1-mysql-client-core-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package mysql-client-8.0. Preparing to unpack .../2-mysql-client-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package libevent-core-2.1-7:amd64. Preparing to unpack .../3-libevent-core-2.1-7_2.1.11-stable-1_amd64.deb ... Unpacking libevent-core-2.1-7:amd64 (2.1.11-stable-1) ... Selecting previously unselected package libevent-pthreads-2.1-7:amd64. Preparing to unpack .../4-libevent-pthreads-2.1-7_2.1.11-stable-1_amd64.deb ... Unpacking libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ... Selecting previously unselected package libmecab2:amd64. Preparing to unpack .../5-libmecab2_0.996-10build1_amd64.deb ... Unpacking libmecab2:amd64 (0.996-10build1) ... Selecting previously unselected package libnuma1:amd64. Preparing to unpack .../6-libnuma1_2.0.12-1_amd64.deb ... Unpacking libnuma1:amd64 (2.0.12-1) ... Selecting previously unselected package mysql-server-core-8.0. Preparing to unpack .../7-mysql-server-core-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-common (5.8+1.0.5ubuntu2) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Selecting previously unselected package mysql-server-8.0. (Reading database ... 62352 files and directories currently installed.) Preparing to unpack .../00-mysql-server-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package libhtml-tagset-perl. Preparing to unpack .../01-libhtml-tagset-perl_3.20-4_all.deb ... Unpacking libhtml-tagset-perl (3.20-4) ... Selecting previously unselected package liburi-perl. Preparing to unpack .../02-liburi-perl_1.76-2_all.deb ... Unpacking liburi-perl (1.76-2) ... Selecting previously unselected package libhtml-parser-perl. Preparing to unpack .../03-libhtml-parser-perl_3.72-5_amd64.deb ... Unpacking libhtml-parser-perl (3.72-5) ... Selecting previously unselected package libcgi-pm-perl. Preparing to unpack .../04-libcgi-pm-perl_4.46-1_all.deb ... Unpacking libcgi-pm-perl (4.46-1) ... Selecting previously unselected package libfcgi-perl. Preparing to unpack .../05-libfcgi-perl_0.79-1_amd64.deb ... Unpacking libfcgi-perl (0.79-1) ... Selecting previously unselected package libcgi-fast-perl. Preparing to unpack .../06-libcgi-fast-perl_1%3a2.15-1_all.deb ... Unpacking libcgi-fast-perl (1:2.15-1) ... Selecting previously unselected package libencode-locale-perl. Preparing to unpack .../07-libencode-locale-perl_1.05-1_all.deb ... Unpacking libencode-locale-perl (1.05-1) ... Selecting previously unselected package libhtml-template-perl. Preparing to unpack .../08-libhtml-template-perl_2.97-1_all.deb ... Unpacking libhtml-template-perl (2.97-1) ... Selecting previously unselected package libtimedate-perl. Preparing to unpack .../09-libtimedate-perl_2.3200-1_all.deb ... Unpacking libtimedate-perl (2.3200-1) ... Selecting previously unselected package libhttp-date-perl. Preparing to unpack .../10-libhttp-date-perl_6.05-1_all.deb ... Unpacking libhttp-date-perl (6.05-1) ... Selecting previously unselected package libio-html-perl. Preparing to unpack .../11-libio-html-perl_1.001-1_all.deb ... Unpacking libio-html-perl (1.001-1) ... Selecting previously unselected package liblwp-mediatypes-perl. Preparing to unpack .../12-liblwp-mediatypes-perl_6.04-1_all.deb ... Unpacking liblwp-mediatypes-perl (6.04-1) ... Selecting previously unselected package libhttp-message-perl. Preparing to unpack .../13-libhttp-message-perl_6.22-1_all.deb ... Unpacking libhttp-message-perl (6.22-1) ... Selecting previously unselected package mecab-utils. Preparing to unpack .../14-mecab-utils_0.996-10build1_amd64.deb ... Unpacking mecab-utils (0.996-10build1) ... Selecting previously unselected package mecab-ipadic. Preparing to unpack .../15-mecab-ipadic_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mecab-ipadic-utf8. Preparing to unpack .../16-mecab-ipadic-utf8_2.7.0-20070801+main-2.1_all.deb ... Unpacking mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Selecting previously unselected package mysql-server. Preparing to unpack .../17-mysql-server_8.0.36-0ubuntu0.20.04.1_all.deb ... Unpacking mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up libmecab2:amd64 (0.996-10build1) ... Setting up mysql-client-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up libhtml-tagset-perl (3.20-4) ... Setting up liblwp-mediatypes-perl (6.04-1) ... Setting up libencode-locale-perl (1.05-1) ... Setting up mecab-utils (0.996-10build1) ... Setting up libevent-core-2.1-7:amd64 (2.1.11-stable-1) ... Setting up libio-html-perl (1.001-1) ... Setting up libtimedate-perl (2.3200-1) ... Setting up libnuma1:amd64 (2.0.12-1) ... Setting up mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up libfcgi-perl (0.79-1) ... Setting up liburi-perl (1.76-2) ... Setting up libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ... Setting up libhttp-date-perl (6.05-1) ... Setting up mecab-ipadic (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up mysql-server-core-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ... Compiling IPA dictionary for Mecab. This takes long time... reading /usr/share/mecab/dic/ipadic/unk.def ... 40 emitting double-array: 100% |###########################################| /usr/share/mecab/dic/ipadic/model.def is not found. skipped. reading /usr/share/mecab/dic/ipadic/Noun.org.csv ... 16668 reading /usr/share/mecab/dic/ipadic/Symbol.csv ... 208 reading /usr/share/mecab/dic/ipadic/Postp.csv ... 146 reading /usr/share/mecab/dic/ipadic/Noun.demonst.csv ... 120 reading /usr/share/mecab/dic/ipadic/Others.csv ... 2 reading /usr/share/mecab/dic/ipadic/Verb.csv ... 130750 reading /usr/share/mecab/dic/ipadic/Prefix.csv ... 221 reading /usr/share/mecab/dic/ipadic/Noun.verbal.csv ... 12146 reading /usr/share/mecab/dic/ipadic/Noun.adjv.csv ... 3328 reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999 reading /usr/share/mecab/dic/ipadic/Noun.csv ... 60477 reading /usr/share/mecab/dic/ipadic/Noun.nai.csv ... 42 reading /usr/share/mecab/dic/ipadic/Conjunction.csv ... 171 reading /usr/share/mecab/dic/ipadic/Adverb.csv ... 3032 reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19 reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328 reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42 reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202 reading /usr/share/mecab/dic/ipadic/Suffix.csv ... 1393 reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91 reading /usr/share/mecab/dic/ipadic/Adj.csv ... 27210 reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199 reading /usr/share/mecab/dic/ipadic/Noun.adverbal.csv ... 795 reading /usr/share/mecab/dic/ipadic/Adnominal.csv ... 135 reading /usr/share/mecab/dic/ipadic/Interjection.csv ... 252 reading /usr/share/mecab/dic/ipadic/Noun.others.csv ... 151 emitting double-array: 100% |###########################################| reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316 emitting matrix : 100% |###########################################| done! update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Setting up libhtml-parser-perl (3.72-5) ... Setting up libhttp-message-perl (6.22-1) ... Setting up mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode Renaming removed key_buffer and myisam-recover options (if present) mysqld will log errors to /var/log/mysql/error.log mysqld is running as pid 5102 Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service. Setting up libcgi-pm-perl (4.46-1) ... Setting up libhtml-template-perl (2.97-1) ... Setting up mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up libcgi-fast-perl (1:2.15-1) ... Processing triggers for systemd (245.4-4ubuntu3.23) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9.15) ... ```

次の作業が必要だったらしい https://dev.mysql.com/doc/refman/8.0/ja/data-directory-initialization.html けど、初っ端で躓く。 home/../..にて、 /usr/local/mysqlが無い /usr/local/はある

:/usr/local$ ls
bin  ensure-gss-startup-order.sh  etc  games  include  lib  man  sbin  share  src
shari-sushi commented 6 months ago

公式ドキュメントでたらいまわしにされたあげくよくわからず。

Details

``` /var/log/mysql$ cat error.log | grep password 2024-05-07T15:48:43.240044Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. ```

sudo mysql -u root

で入れた。orz

https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql-ja

注: このチュートリアルでMySQLシェル内にユーザーを追加する場合、ユーザーのホストをサーバーのIPアドレスではなく、localhostとして指定します 。localhostは「このコンピューター」を意味するホスト名で、MySQLはこの特定のホスト名を特別に扱います。 そのホストを持つユーザーがMySQLにログインすると、Unixソケットファイルを使用してローカルサーバーに接続しようとします。したがって、通常、サーバーにSSHで接続する場合、またはローカルmysqlクライアントを実行してローカルMySQLサーバーに接続する場合に、localhostが使用されます。

※注意 ユーザー作成

CREATE USER 'USER'@'IP' IDENTIFIED BY 'password';

  • IPについて
  • 今回はlocalhostとした。
  • これはMySQLでは特に特別視されているようで、127.0.0.1とは扱いが違うらしい。 何とかソケットを使って接続している…。
  • これがバックエンドから処理する際は、localhostと書いていても、内部処理で127.0.0.1に変換される可能性がある。その場合は、MySQL側で127.0.0.1のユーザーを作成する必要がある。
  • PC上やDocker上のMySQLではlocalhostで接続できていたので完全に落とし穴。
  • passwordについて
  • LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary

の3段階のバリデーションが用意されている様子で、デフォルトはLOWと思われる。

↓3段階あるソース(作業ログ)

`sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql`

``` sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql sudo: mysql_install_db: command not found :/bin$ sudo apt-get purge mysql-server mysql-client mysql-common Reading package lists... Done Building dependency tree Reading state information... Done Package 'mysql-client' is not installed, so not removed The following packages were automatically installed and are no longer required: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libnuma1 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-core-8.0 mysql-server-core-8.0 Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: mysql-client-8.0* mysql-common* mysql-server* mysql-server-8.0* 0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded. After this operation, 1621 kB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 62711 files and directories currently installed.) Removing mysql-server (8.0.36-0ubuntu0.20.04.1) ... Removing mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Removing mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Removing mysql-common (5.8+1.0.5ubuntu2) ... Processing triggers for man-db (2.9.1-1) ... (Reading database ... 62668 files and directories currently installed.) Purging configuration files for mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... Purging configuration files for mysql-common (5.8+1.0.5ubuntu2) ... dpkg: warning: while removing mysql-common, directory '/etc/mysql' not empty so not removed Processing triggers for systemd (245.4-4ubuntu3.23) ... :/bin$ sudo rm -rf /etc/mysql /var/lib/mysql :/bin$ sudo apt-get install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: mysql-client-8.0 mysql-common mysql-server-8.0 Suggested packages: mailx tinyca The following NEW packages will be installed: mysql-client-8.0 mysql-common mysql-server mysql-server-8.0 0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B/1365 kB of archives. After this operation, 1621 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Preconfiguring packages ... Selecting previously unselected package mysql-common. (Reading database ... 62648 files and directories currently installed.) Preparing to unpack .../mysql-common_5.8+1.0.5ubuntu2_all.deb ... Unpacking mysql-common (5.8+1.0.5ubuntu2) ... Selecting previously unselected package mysql-client-8.0. Preparing to unpack .../mysql-client-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-common (5.8+1.0.5ubuntu2) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Selecting previously unselected package mysql-server-8.0. (Reading database ... 62675 files and directories currently installed.) Preparing to unpack .../mysql-server-8.0_8.0.36-0ubuntu0.20.04.1_amd64.deb ... Unpacking mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... Selecting previously unselected package mysql-server. Preparing to unpack .../mysql-server_8.0.36-0ubuntu0.20.04.1_all.deb ... Unpacking mysql-server (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-client-8.0 (8.0.36-0ubuntu0.20.04.1) ... Setting up mysql-server-8.0 (8.0.36-0ubuntu0.20.04.1) ... update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode Renaming removed key_buffer and myisam-recover options (if present) mysqld will log errors to /var/log/mysql/error.log mysqld is running as pid 21487 Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service. Setting up mysql-server (8.0.36-0ubuntu0.20.04.1) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for systemd (245.4-4ubuntu3.23) ... :/bin$ sudo mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Skipping password set for root as authentication with auth_socket is used by default. If you would like to use password authentication instead, this can be done with the "ALTER_USER" command. See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y Success. All done! ```

shari-sushi commented 6 months ago

GoとMySQLの接続

https://zenn.dev/nananaoto/articles/c56bc2b38834b32c8fd7

環境変数を設定するだけで済むと思うけど、ネットで調べるとDocker前提の話ばかり出てくる。 会社ではCloud Runつかってるぽいけど…? https://zenn.dev/nananaoto/articles/c56bc2b38834b32c8fd7#%E3%83%AD%E3%83%BC%E3%82%AB%E3%83%AB%E3%81%8B%E3%82%89cloud-build%E3%82%92%E5%AE%9F%E8%A1%8C

今日中にデプロイして動作確認する(curl可)という目標ができたので、ハードコードすれば何とかなることは後回し。

shari-sushi commented 6 months ago

4