ブログサーバの移転ログ

サーバ移転することにしたのでUbuntu環境を構築します。
移転といってもさくらのVPS→さくらのVPSです、メモリやディスク容量などをアップデートします。

環境

Before After
運営 さくらVPS v4 さくらVPS v5
CPU 仮想2core 仮想3core
MEM 1GB 2GB
SSD 50GB 200GB

OS確認

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.1 LTS
Release:	22.04
Codename:	jammy

Emacsインストール

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install emacs

init.elを作成

// emacsを開く
$ emacs ~/.emacs.d/init.el
// 最低限これだけあればまあなんとかなるので追記
; Backward -> \C-h
(global-set-key "\C-h" 'delete-backward-char)

MySQL

インストール

$ sudo apt install mysql-server

確認

$ sudo service mysql status
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-11-23 17:41:14 JST; 13s ago
    Process: 4405 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 4413 (mysqld)
     Status: "Server is operational"
      Tasks: 39 (limit: 2237)
     Memory: 364.1M
        CPU: 616ms
     CGroup: /system.slice/mysql.service
             └─4413 /usr/sbin/mysqld

ログイン

$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.31-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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>

ユーザ作成

mysql> CREATE USER '{ユーザ名}'@'localhost' IDENTIFIED BY '{パスワード}';
Query OK, 0 rows affected (0.01 sec)

権限設定

mysql> GRANT ALL PRIVILEGES ON *.* TO '{ユーザ名}'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)

再読み込み

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

参考:

Nginx

インストール

$ sudo apt install nginx

HHTPポート開放

sudo ufw allow 80

SSL証明書のためLet's encryptをインストール

$ sudo apt install certbot

SSLポート開放

$ sudo ufw allow 443
ルールを追加しました
ルールを追加しました (v6)

Node.js

Ghost blogはNodejs v16.xが推奨なのでapt installは使わず

インストール

$ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
$ node -v // バージョン確認
v16.18.1

$ npm -v // npmのバージョン確認 古い
8.19.2

参考

npm アップデート

npmが自動でインストールされるが古いためアップデートする

$ sudo npm install -g npm
$ npm -v
9.1.2

Ghost Blog

ポート開放でNginx用の設定をしろとある

sudo ufw allow 'Nginx Full'

Ghost cliのインストール

sudo npm install ghost-cli@latest -g

参考:

Ghostブログの開設

対話式で作成(途中SSLの設定など失敗してやり直したりした)

$ ghost install

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org



✔ Checking system Node.js version - found v16.18.1
✔ Checking logged in user
✔ Checking current folder permissions
✔ Checking system compatibility
✔ Checking for a MySQL installation
✔ Checking memory availability
✔ Checking free space
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v5.23.0
✔ Finishing install process
? Enter your blog URL: https://blog.uso400.net
? Enter your MySQL hostname: localhost
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: blog_uso400_net_prod
✔ Configuring Ghost
✔ Setting up instance
+ sudo chown -R ghost:ghost /var/www/blog.uso400.net/content
✔ Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? Yes
✔ Setting up "ghost" mysql user
? Do you wish to set up Nginx? Yes
+ sudo mv /tmp/blog-uso400-net/blog.uso400.net.conf /etc/nginx/sites-available/blog.uso400.net.conf
+ sudo ln -sf /etc/nginx/sites-available/blog.uso400.net.conf /etc/nginx/sites-enabled/blog.uso400.net.conf
+ sudo nginx -s reload
✔ Setting up Nginx
? Do you wish to set up SSL? Yes
? Enter your email (For SSL Certificate) {admin}@uso400.net
+ sudo /etc/letsencrypt/acme.sh --upgrade --home /etc/letsencrypt
+ sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --server letsencrypt --domain blog.uso400.net --webroot /var/www/blog.uso400.net/system/nginx-root --reloadcmd "nginx -s reload" --accountemail {admin}@uso400.net
+ sudo mv /tmp/blog-uso400-net/blog.uso400.net-ssl.conf /etc/nginx/sites-available/blog.uso400.net-ssl.conf
+ sudo ln -sf /etc/nginx/sites-available/blog.uso400.net-ssl.conf /etc/nginx/sites-enabled/blog.uso400.net-ssl.conf
+ sudo nginx -s reload
✔ Setting up SSL
? Do you wish to set up Systemd? Yes
+ sudo mv /tmp/blog-uso400-net/ghost_blog-uso400-net.service /lib/systemd/system/ghost_blog-uso400-net.service
+ sudo systemctl daemon-reload
✔ Setting up Systemd
+ sudo systemctl is-active ghost_blog-uso400-net
? Do you want to start Ghost? Yes
+ sudo systemctl start ghost_blog-uso400-net
+ sudo systemctl is-enabled ghost_blog-uso400-net
+ sudo systemctl enable ghost_blog-uso400-net --quiet
✔ Starting Ghost

Ghost uses direct mail by default. To set up an alternative email method read our docs at https://ghost.org/docs/config/#mail

------------------------------------------------------------------------------

Ghost was installed successfully! To complete setup of your publication, visit:

    https://blog.uso400.net/ghost/

その他

あとPostfixの導入なども追記していきます