Google Cloud Platform上に立てたCentOS7にgogsをインストールする方法のご紹介です。
まずは、データベースを作成しましょう。以下では「create database gogs;」コマンドで「gogs」データベースを作成しています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@gogs ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.7.25 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database gogs; Query OK, 1 row affected (0.00 sec) mysql> exit [root@gogs ~]# |
「gogs」を公式サイトからダウンロードして、解凍します。
1 2 |
[root@gogs ~]# curl -O https://dl.gogs.io/0.11.86/gogs_0.11.86_linux_amd64.tar.gz [root@gogs ~]# tar zxf gogs_0.11.86_linux_amd64.tar.gz |
表示が多くなるためtarコマンドのオプション「v」は外していますが、実際に実行するときには「tar zxvf …」としたほうが良いかと思います。
早速実行してみます。
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@gogs ~]# cd gogs [root@gogs gogs]# ./gogs web 2019/03/03 12:48:19 [ WARN] Custom config '/root/gogs/custom/conf/app.ini' not found, ignore this if you're running first time 2019/03/03 12:48:19 [TRACE] Custom path: /root/gogs/custom 2019/03/03 12:48:19 [TRACE] Log path: /root/gogs/log 2019/03/03 12:48:19 [TRACE] Log Mode: Console (Trace) 2019/03/03 12:48:19 [ INFO] Gogs 0.11.86.0130 2019/03/03 12:48:19 [ INFO] Cache Service Enabled 2019/03/03 12:48:19 [ INFO] Session Service Enabled 2019/03/03 12:48:19 [ INFO] SQLite3 Supported 2019/03/03 12:48:19 [ INFO] Run Mode: Development 2019/03/03 12:48:19 [ INFO] Listen: http://0.0.0.0:3000 |
これで、ブラウザでアクセスしてみましょう。
アクセスするIPアドレスはGCPで確認してみましょう。
このインスタンスの場合、外部IPが「34.85.55.102」なので、「http://34.85.55.102:3000」にアクセスしてみましょう。
はい、何も表示されないと思います。
GCPで標準で設定されているファイヤーウォールではhttpは80番しか空いていないことが原因です。
3000番ポートでアクセスできるようにしてみましょう。
サーバで実行した「./gogs web」はそのままにしておいてください。
ブラウザでVMインスタンスの管理画面にいきます。
ここで以下のように「ネットワークの詳細の表示」をクリックします。
「ファイアウォール ルールとルートの詳細」の「default-allow-http」の欄をみると「プロトコル / ポート」の箇所が「tcp:80」になっていることがわかります。
「default-allow-http」をクリックします。
下にスクロールします。
「プロトコルとポート」の箇所を「80」から「3000」に変更します。その後「保存」をクリック。
これで設定は完了です。
この状態で「http://34.85.55.102:3000」にアクセスしてみましょう。
以下の通り、Gogsのインストール画面が表示されると思います。
「./gogs web」のコマンドを「Ctrl + C」等で止めると画面は表示されなくなりますのでご注意ください!
また、今回はGCPだったのでブラウザで操作を行いましたが、環境によっては以下のようにfirewall-cmdで3000番ポートを許可してあげる必要があります。
1 2 3 |
# firewall-cmd --add-port=3000/tcp --zone=public --permanent success # systemctl restart firewalld |