LoginSignup
7
15

More than 5 years have passed since last update.

ConoHa VPS (ubuntu 16.04) 初期設定メモ

Last updated at Posted at 2017-09-16

さくらVPSをずっと使っていたが、ConoHa VPSへの乗り換えを検討中。お安くて悪くない。

ConoHa VPSの契約

RAM1GB/SSD50GBプラン@東京リージョンを契約。月900円。お安い。
- ひとまずポート制限はなし。sshでログインしてから設定。
- ubuntu 16.04を選択。
- SSH Pubkeyは登録しない。仮想マシン作成時はユーザが作られないため、ユーザを作ってから登録する。

ドメインの設定

ドメイン管理はさくらインターネットのまま保持。
- さくらのドメイン管理画面から、当該ドメイン名のアドレスを変える。
- ConoHaのサーバ管理画面で、逆引きホスト名として当該ドメイン名を入れておく。念のため。

セキュリティ周りの初期設定

ユーザ作成 & ssh

SSHかコントロールパネルからrootでシェルログインをしてユーザ作成、sudoersに追加、ssh鍵の設定、viで適当に新しいユーザの公開鍵をコピペして登録、まで一気にやってしまう。

# adduser <new user>
# usermod -aG sudo <new user>
# su <new user>
$ mkdir ~/.ssh
$ touch ~/.ssh/authorized_keys
$ vi ~/.ssh/authorized_keys

sshd_configをいじってPort変更、Root/Passwordログインを禁止、公開鍵ログインのみとする。

$ sudo vi /etc/ssh/sshd_config
- Port 22
+ Port xxx # ポート変更

- PermitRootLogin yes
+ PermitRootLogin no

- PubkeyAuthentication no
+ PubkeyAuthentication yes #公開鍵ログイン

- PasswordAuthentication yes
+ PasswordAuthentication no

- UsePAM yes
+ usePAM no

$ sudo /etc/init.d/ssh restart

iptablesの設定

ufwで楽をする。

$ sudo ufw allow <ssh port> # ssh
$ sudo ufw allow 80   # http
$ sudo ufw allow 443  # https
$ sudo ufw default deny # デフォルトでは全部拒否
$ sudo ufw enable

確認。

$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip


To                         Action      From
--                         ------      ----
<ssh port>                 ALLOW IN    Anywhere                  
80                         ALLOW IN    Anywhere                  
443                        ALLOW IN    Anywhere                  
<ssh port> (v6)            ALLOW IN    Anywhere (v6)             
80 (v6)                    ALLOW IN    Anywhere (v6)             
443 (v6)                   ALLOW IN    Anywhere (v6)             

ホスト名変更

/etc/hosts/etc/hostnameが食い違ってるので、

/etc/hosts
127.0.0.1 conoha

/etc/hostname
conoha

みたいにしておく。

NTP

sysv-rc-conf経由で自動起動を設定しておく。

$ sudo apt-get install sysv-rc-conf
$ sudo apt-get remove ntpdate # ntpdateが悪さして起動しないことがあるので消す(いいのか?)
$ sudo sysv-rc-conf ntp on

Logwatchでgmail宛にログを投げる。

念のため。

$ sudo apt-get install logwatch
$ sudo cp /usr/share/logwatch/conf/logwatch.conf /etc/logwatch/conf/

gmail宛に編集。

/etc/logwatch/conf/logwatch.conf
- MailTo = root
+ MailTo = xxx@gmail.com

ドメイン管理の方でTXTフィールドを次のように書いとかないとGoogleに消される。

v=spf1 ip4:<ip addr> include:aspmx.googlemail.com a:<domain> ~all

postfixの送信アドレスも当該ドメインにしておく。

/etc/postfix/main.cf

- myhostname = <host>
+ myhostname = <domain>
+ mydomain = $myhostname
+ myorigin = $mydomain

+ append_dot_mydomain = yes
- append_dot_mydomain = no
+ append_at_myorigin = yes

- mydestination = $myhostname, localhost.localdomain, <host>, , localhost
+ mydestination = $myhostname, localhost.localdomain, localhost.$mydomain, localhost, $mydomain

しばらくは迷惑メール扱いになるので、地道にボックスを覗いて振り分ける。

Docker

サーバは全部Dockerで動かす所存。

リポジトリの設定

$ sudo apt-get update;
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # DockerのGPG鍵を導入
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable" # リポジトリ追加

Docker Community Editionの導入

$ sudo apt-get update; sudo apt-get install docker-ce
$ sudo docker run hello-world # 動作確認

Docker Composeの導入

$ sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# これ書いてる時点では1.16.1が最新。状況はgithubをチェック。 https://github.com/docker/compose/releases

$ sudo chmod +x /usr/local/bin/docker-compose # 実行権限付与
$ docker-compose --version # チェック
docker-compose version 1.16.1, build 6d1ac21

作った一般ユーザでDockerが利用できるようにしておく

sudo usermod -aG docker <new user>

参考:
Get Docker CE for Ubuntu
Install Docker Compose

7
15
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
7
15