3
1

EC2慣れしてしまった人に向けたAmazon Lightsailの備忘録

Last updated at Posted at 2024-02-07

はじめに

EC2に慣れていると、Lightsailでのコマンドやパスの違いに毎回戸惑うので、備忘録としてここに記します。

ドキュメントルート

$ pwd
/home/bitnami/htdocs

パス

Apache

$ sudo cat /opt/bitnami/apache2/conf/bitnami/bitnami.conf

ログファイル

$ pwd
/opt/bitnami/apache2/logs

PHP

$ sudo cat /opt/bitnami/php/lib/php.ini 

MariaDB

$ sudo cat /opt/bitnami/mariadb/conf/my.cnf

Supervisor

$ sudo cat /etc/supervisor/conf.d/xxxxx.conf

起動

ApacheやMariaDBの起動コマンド。

Apache

$ sudo /opt/bitnami/ctlscript.sh start apache
Started apache

MariaDB

$ sudo /opt/bitnami/ctlscript.sh start mariadb
Started mariadb

Supervisor

$ sudo supervisorctl reload
Started supervisord

エラーに関する備忘録

ERROR 2002 (HY000): Can't connect to local server through socket '/opt/bitnami/mariadb/tmp/mysql.sock' (13)

ローカルのMariaDBの起動時に上記のエラーになる場合があります。
原因には下記の3つが考えられます。

  1. そもそもMariaDBが起動していない
  2. mysql.sockファイルが存在しない
  3. my.cnfに記述されたmysql.sockファイルのパスが間違っている

私の場合は、なぜか2が原因でMariaDBの起動に失敗する事が多いので、2の対処方法について記します。

通常、MariaDBの再起動でmysql.sockファイルが作られるのですが、再起動コマンドに失敗してしまう事があります。
そんな場合はmysql.sockファイルを手動で作成してからMariaDBを再起動します。

$ sudo touch /opt/bitnami/mariadb/tmp/mysql.sock
$ sudo chown mysql:mysql /opt/bitnami/mariadb/tmp/mysql.sock
$ sudo chmod 660 /opt/bitnami/mariadb/tmp/mysql.sock

やっぱり再起動コマンドに失敗する場合は、Lightsailのコンソールからインスタンスの再起動をするとうまく起動してくれます。

停止

ApacheやMariaDBの停止コマンド。

Apache

$ sudo /opt/bitnami/ctlscript.sh stop apache
Stopped apache

MariaDB

$ sudo /opt/bitnami/ctlscript.sh stop mariadb
Stopped mariadb

Supervisor

$ sudo supervisorctl stop
Stopped supervisord

再起動

ApacheやMariaDBの再起動コマンド。

Apache

$ sudo /opt/bitnami/ctlscript.sh restart apache
Restarted apache

MariaDB

$ sudo /opt/bitnami/ctlscript.sh restart mariadb
Restarted mariadb

Supervisor

$ sudo supervisorctl reload
Restarted supervisord

ステータス確認

ApacheやMariaDBのステータス確認コマンド。

まとめて確認

$ sudo /opt/bitnami/ctlscript.sh status
apache already running
mariadb not running
php-fpm already running

個別に確認

Apache

$ sudo /opt/bitnami/ctlscript.sh status apache
apache already running

MariaDB

$ sudo /opt/bitnami/ctlscript.sh status mariadb
mariadb already running

Supervisor

$ sudo supervisorctl status
xxxxx-queue:xxxxx-queue_00       RUNNING   pid 11296, uptime 0:00:02
xxxxx-queue:xxxxx-queue_01       RUNNING   pid 11297, uptime 0:00:02

エラーに関する備忘録

Cannot find any running daemon to contact. If it is running, make sure you are pointing to the right pid file (/var/run/gonit.pid)

ステータス確認コマンドの実行時に、何らかの理由でgonitプロセスが停止していてステータスが取得できず、上記のエラーになる場合があります。
そんな時はgonitを実行してステータスの再取得を行います。

$ sudo gonit
Starting gonit daemon
$ sudo gonit status

Uptime                         4s
Last Check                     2024-02-07 09:32:15.746035815 +0900 JST m=+0.011323676
Next Check                     2024-02-07 09:34:15.746035815 +0900 JST m=+120.011323676
Pid                            1797
Pid File                       /var/run/gonit.pid
Control File                   /etc/gonit/gonitrc
Socket File                    /var/run/gonit.sock
Log File                       /var/log/gonit.log
Process 'apache'
  status                                        Running
  pid                                               737
  uptime                                             4s
  monitoring status                           monitored

Process 'mariadb'
  status                                        Stopped
  uptime                                             0s
  monitoring status                           monitored

Process 'php-fpm'
  status                                        Running
  pid                                               681
  uptime                                             4s
  monitoring status                           monitored

参考サイト

おわりに

以上、Lightsailに関する備忘録でした。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1