2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7上にDockerでMySQL8、Nginxを動かしてRailsを起動するためにしたこと

Last updated at Posted at 2019-07-30

deploy用ユーザーの作成

# adduser hoge_user
# passwd hoge_user

visudoでrootになれるよう設定

localeの設定

# localectl set-locale LANG=ja_JP.utf8
一度ログアウトしてログイン
# locale
LANG=ja_JP.UTF8

ssh設定

rootでのsshはできなくする。
sshのportは2222に変更。

# vim /etc/ssh/sshd_config
PermitRootLogin -> no
Port -> 2222
# sshd -t
# sudo service sshd restart

firewalldの設定

httpとsshだけ解放。
sshはportを2222に変更する。

# cp -p /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/
portを2222に変更
# firewall-cmd --add-service=http --zone=public --permanent
# firewall-cmd --add-service=ssh --zone=public --permanent
# firewall-cmd --reload
success

※さくらVPSの場合混乱するので管理画面から操作できるパケットフィルタをOFFにする。

Docker

https://docs.docker.com/install/linux/docker-ce/centos/ の手順に従い作業

&

$ sudo systemctl enable docker # 自動起動設定
$ sudo systemctl start docker

docker-compose

https://docs.docker.com/compose/install/ の手順に従い作業

デプロイユーザーがdocker-composeを使えるように

# usermod -aG docker hoge_user
hoge_userは一回ログアウトしてログインしなおす。

rbenvでrubyインストール

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ exec $SHELL -l

ruby-buildインストール
$ mkdir -p "$(rbenv root)"/plugins
$ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

$ sudo yum install -y openssl-devel readline-devel zlib-devel
$ rbenv install 2.5.1
$ rbenv global 2.5.1
$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

yarnインストール

$ curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
$ sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
$ sudo yum install yarn
$ yarn install

Webサーバー,DB起動

$ docker-compose up --build

docker-compose.yml

version: '3'
services:
  mysql:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - mysql-db:/var/lib/mysql
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD
  nginx:
    build: ./nginx
    ports:
      - "$HOST_HTTP_PORT:80"
    volumes:
      - ../../my_app:/apps/my_app
      - ../log/nginx:/var/log/nginx
      - ../public:/usr/share/nginx/html
volumes:
  mysql-db:
    driver: local
2
0
1

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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?