Windows7 をホストにして オンプレミス HackMD サーバーを立ち上げてみた



発端

Twitter上の以下スレッドのやりとりが元で、はけたさんの発言から知ったのがきっかけです。

調べてみるとオンプレミスで構築できるという情報があったので、「会社で使えそう」と考えて構築手順をまとめてみました。

次項記載の環境において、何も考えずに構築完了まで操作できます。

Windows7上で、仮想環境もDockerもGitも入ってない状態から最後までセットアップする手順は一応無かったので、備忘録としては割りと有意義かも知れません。

▼構築環境

ホストOS Windows7
仮想環境 Virtual Box
Dockerホスト 仮想CentOS7
仮想環境立上補助 Vagrant

1 VirtualBoxインストール

https://www.oracle.com/virtualization/technologies/vm/downloads/virtualbox-downloads.html

2 Vagrantインストール

https://www.vagrantup.com/downloads.html

3 PC再起動

4 Powershellを3以上に上げる

補足:2だと以下のメッセージが出ます。

C:\Vagrant\centos>vagrant init centos/7
Vagrant failed to initialize at a very early stage:

The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

  Installed version: 2

  Minimum required version: 3

4.1 インストーラーダウンロード

https://www.microsoft.com/en-us/download/details.aspx?id=54616

4.2 実行ポリシーを変更

Powershellを管理者権限で起動、以下コマンドを実行。

PS C:\> Set-ExecutionPolicy Remotesigned

補足:初期値だとスクリプトに署名がないと実行できない

4.3 インストール

PS C:\> E:\download\powershell\Win7AndW2K8R2-KB3191566-x64\Install-WMF5.1.ps1

5 Boxを検索し、CentOSインストール to 仮想環境

5.1 検索

https://app.vagrantup.com/boxes/search

↓ 検索

https://app.vagrantup.com/centos/boxes/7

5.2 フォルダ作成

PS C:\> mkdir C:\Vagrant\centos

5.3 Vagrant初期化

5.3.1 初期化コマンドを入力

PS C:\> cd C:\Vagrant\centos
PS C:\Vagrant\centos> vagrant init centos/7

以下、出力されるメッセージ。

PS C:\Windows\system32> vagrant init centos/7
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
PS C:\Windows\system32>

5.3.2 Vagrantfile編集

config.vm.network "private_network", ip: "192.168.33.10"    のコメントアウトを外す

5.3.3 仮想マシン起動

PS C:\Vagrant\centos> vagrant up

初回起動は結構時間がかかります。 ネットワーク環境にもよるかも。 自宅環境では約1時間かかりました。 以下、起動開始直後のメッセージ。

PS C:\Vagrant\centos> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'centos/7' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'centos/7'
    default: URL: https://vagrantcloud.com/centos/7
==> default: Adding box 'centos/7' (v1905.1) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/1905.1/providers/virtualbox.box
    default: Download redirected to host: cloud.centos.org
    default: Progress: 5% (Rate: 191k/s, Estimated time remaining: 0:44:44))

以下、起動完了後のメッセージ。

PS C:\Vagrant\centos> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'centos/7' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'centos/7'
    default: URL: https://vagrantcloud.com/centos/7
==> default: Adding box 'centos/7' (v1905.1) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/1905.1/providers/virtualbox.box
    default: Download redirected to host: cloud.centos.org
    default: Progress: 100% (Rate: 38791/s, Estimated time remaining: --:--:--)
==> default: Successfully added box 'centos/7' (v1905.1) for 'virtualbox'!
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '1905.1' is up to date...
==> default: Setting the name of the VM: centos_default_1568814798579_93674
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection reset. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /cygdrive/c/Vagrant/centos/ => /vagrant

5.3.4 仮想マシンにログイン

PS C:\Vagrant\centos> vagrant ssh

6 Dockerインストール

6.1 OS更新

$ su -
# yum update
# yum upgrade

6.2 公式リポジトリのインストール

# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

6.3 DOCKER CE のインストール

# yum install -y docker-ce docker-ce-cli containerd.io

6.4 docker-compose インストール

# curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose

7 Docker の起動・設定

7.1 Docker の起動

# systemctl start docker

7.2 自動起動設定

# systemctl enable docker

7.3 バージョンの確認

# docker --version

7.4 プロキシの設定

# mkdir -p /etc/systemd/system/docker.service.d
# vi /etc/systemd/system/docker.service.d/http-proxy.conf

/etc/systemd/system/docker.service.d/http-proxy.conf

[Service]
Environment="HTTP_PROXY=http://:@:" "HTTPS_PROXY=http://:@:" "NO_PROXY=localhost"

7.5 Docker 再起動

# systemctl daemon-reload
# systemctl restart docker

8 Git インストール

# yum install git

9 HackMD インストール・起動

9.1 githubからclone

# git clone https://github.com/hackmdio/docker-hackmd.git

9.2 HackMDを起動

# cd docker-hackmd && git pull
# docker-compose up

9.3 ブラウザで動作確認

http://192.168.33.10:3000

f:id:wd4096:20190919010253p:plain

オンプレミスでHackMD

ファイルのエクスポート画面

以下メニューから異なるファイル形式でエクスポート可能。

なお、オンプレミス版ではPDFのエクスポート機能が残っていますが、結構前に負荷の影響でPDF形式でのエクスポートは廃止された模様。

f:id:wd4096:20190924224351p:plain

PDFエクスポートについて

左がHackMDからのエクスポート結果。右がTyporaからのエクスポート結果。

HackMDからのエクスポートだと罫線が消えたり散々なので、Typoraにmdファイルをインポートして出力するのがよいと思います。

f:id:wd4096:20190924231514p:plain

▼参考サイト

  1. https://qiita.com/ozawan/items/160728f7c6b10c73b97e
  2. https://qiita.com/tettsu__/items/e1e445c8d7a975829902
  3. https://qiita.com/ymasaoka/items/b6c3ffea060bcd237478
  4. https://qiita.com/copei/items/710a2d05114ec1637268
  5. https://qiita.com/KosukeJin/items/bb0daaed9f058439e225<