LoginSignup
0
0

More than 3 years have passed since last update.

【コピペで行ける】CentOS7環境でRubyOnRailsを動かす_01

Last updated at Posted at 2019-11-04

1.はじめに

こんにちわ、tmorikawaです。

最近仕事でタイトルの環境を作ることがあったのですがこれがまた面倒だったので、Qiita上に安定動作するまでの設定を書きますね。

2.CentOSの設定

2.1.~2.5.まではOSの基本的な設定になります。
私は面倒だったのでrootユーザ使っていますが、使えない人はsudo利用してください。
※適当に作った環境なので、このままプロダクトに使うのは非推奨ですよ

2.1.ssh設定

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.org

vim /etc/ssh/sshd.config

PermitRootLoginをnoに変更、コメントアウトを外す
(rootでのログイン禁止)

 To disable tunneled clear text passwords, change to no here!の
PasswordAuthenticationをyesに
(コメントアウトを外す)

Change to no to disable s/key passwordsの
ChallengeResponseAuthenticationをnoに

2.2.ベース設定

■ベースアップデート

yum -y groupinstall base
yum -y groupinstall development
yum -y groupinstall network-tools

yum -y install epel-release

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

vim /etc/yum.repos.d/MariaDB.repo

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

2.3.ユーザ作成

(新規作成したサーバにてユーザ作成)
(groupadd -g →gidを指定してグループ作成)

groupadd -g 1000 butamayo

□ユーザー追加(UID指定)
(ユーザーid1000で、butamayoグループに、butamayoユーザーを追加)
useradd -u 1000 -g butamayo butamayo

□ユーザーが作成されたことを確認

cat /etc/passwd

□ユーザーパスワード設定
passwd butamayo


cp -rp /etc/sudoers sudoers.bak

vim /etc/sudoers


## Allows people in group wheel to run all commands
#%wheel  ALL=(ALL)       ALL

コメントアウトをはずす


cd /etc/pam.d 

cp -rp su su.bak

vim /etc/pam.d/su
#auth        required        pam_wheel.so use_uid
コメントアウトを外す

gpasswd -a butamayo wheel

usermod -g wheel butamayo

getent group wheel

cp -rp /etc/login.defs /etc/login.defs_bak

diff /etc/login.defs /etc/login.defs_bak

vim /etc/login.defs


「SU_WHEEL_ONLY」の項目を末尾に追記して保存。

SU_WHEEL_ONLY yes


diff /etc/login.defs /etc/login.defs_bak

2.4.Apacheインストール

【httpd】
yum -y install httpd mod_ssl

systemctl enable httpd

service httpd restart

2.5.MariaDB設定

vim /etc/my.cnf

#[mysqld]に以下を追記
character-set-server=utf8
slow_query_log=ON
long_query_time = 5
slow_query_log_file = /var/log/mariadb/mariadb_slow.log

#[mysqld_safe]の以下の記述を変更

log-error=/var/log/mariadb/mariadb.log

↓

log-error=/var/log/mariadb/mariadb_error.log

yum -y install pv

yum -y install mariadb mariadb-server

service mariadb start && systemctl enable mariadb

mysql_secure_installation

#パスワード hogehoge

mysql -u root -p

#password hogehoge

CREATE DATABASE `stg_rails` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE DATABASE `pro_rails` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;


exit


echo "[mysqladmin] \password = hogehoge \user= root" > /root/.my.cnf & chmod 600 /root/.my.cnf





■ログローテ設定

vim /etc/logrotate.d/mariadb

/var/log/mariadb/mariadb_error.log
/var/log/mariadb/mariadb_slow.log {
        create 640 mysql mysql
        daily
            missingok
            rotate 30
            compress
            dateext
            ifempty        
    postrotate
        if test -x /usr/bin/mysqladmin && \
           /usr/bin/mysqladmin ping &>/dev/null
        then
           /usr/bin/mysqladmin flush-logs
        fi
    endscript
}

とりあえずここまでがOSの基本設定です。
Railsを動かすための設定だけ見たい人は次の記事を見てくださいね。

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