LoginSignup
11
13

More than 5 years have passed since last update.

CentOS7のセットアップ備忘録

Last updated at Posted at 2016-03-08

お名前.com のVPS環境を前提としてメモ

1. OSインストール

-rootパスワードの設定
-ユーザー作成(管理者に設定)

2. eth0有効化

デフォルトだとデバイスが切られているので有効化。
このままだと何もできないので必須。

# nmcli con mod eth0 connection.autoconnect "yes"
# nmcli device disconnect eth0
# nmcli device connect eth0

3. SSH設定

$ sudo vi /etc/ssh/sshd_config
#RSAAuthentication yes
#PubkeyAuthentication yes
↓公開鍵認証を有効
RSAAuthentication yes
PubkeyAuthentication yes

sshd再起動で有効化。
反映されたら認証キーでssh接続できるか確認。
$ sudo service sshd restart

秘密鍵を作成して公開鍵をsftpでCentOSへ転送

[LOCAL]
$ cd ~/.ssh
$ ssh-keygen -t rsa
$ ssh-add -K ~/.ssh/id_rsa
[REMOTE]
$ mkdir ~/.ssh
$ touch .ssh/authorized_keys
$ chmod 700 .ssh
$ chmod 600 .ssh/authorized_keys
[LOCAL]
$ scp ~/.ssh/id_rsa.pub username@aaa.bbb.ccc.ddd:~/.ssh/authorized_keys

接続が成功したらセキュリティ向上としてパスワード認証とrootログインを禁止
$ sudo vi /etc/ssh/sshd_config

#PermitRootLogin yes
↓rootでのログインを禁止
PermitRootLogin no

#PasswordAuthentication yes
↓パスワード認証ログインを禁止
PasswordAuthentication no

$ sudo service sshd restart

4. 主要パッケージのインストール

yumを最新化して諸々インストール

# yum -y update
# yum -y install vim wget httpd git epel-release openssl-devel readline-devel zlib-devel zlib sqlite-devel gcc-c++ glibc-headers readline libffi-devel wgetlibyaml-devel bzip2 libpng-devel
# yum -y groupinstall "Development Tools" //既にインストールされている環境だとインストールがコケる可能性がある
# yum -y install java-1.8.0-openjdk-devel.x86_64

rbenvでRubyもインストール

rbenvのソースダウンロード

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

パスを通して有効化するとrbenvが利用可能になる

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ source ~/.bashrc
$ rbenv --version

インストールできるバージョンを確認して最新版をインストール
(すげー時間かかる)

$ rbenv install -l
$ rbenv install 2.5.1
$ rbenv global 2.5.1
$ ruby -v

gemのアップデートとbundlerのインストール

$ gem update --system
$ gem install bundler

Node.jsのインストール

*NVMの最新バージョンはGitHubで確認
https://github.com/creationix/nvm

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
$ source ~/.bashrc
$ nvm install stable
$ node -v
$ nvm alias default stable

Pythonのインストール

$ cd /usr/local/src
# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
# tar zxvf Python-3.5.2.tgz
# cd  Python-3.5.2
# ./configure --prefix=/usr/local/python-3.5
# make
# make install

パスを通す

$ vim ~/.bashrc
export PATH=/usr/local/python-3.5/bin:$PATH

$ source ~/.bashrc
$ python3 -V

インストールしたrbenv NVM Pythonをsuでも利用できるようにパスを通す

# vim ~/.bashrc
~/.bashrc
source /home/(username)/.bashrc

追記したら.bashrcを読み込んでsuでも利用できるか確認

# source ~/.bashrc
# ruby -v
# node -v
# python3 -V

同じくsudoでも叩けるようにする

MongoDBのインストール

参考URL
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

# vim /etc/yum.repos.d/mongodb-org-4.0.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

インストール

# yum install mongodb-org
$ systemctl start mongod
$ sudo chkconfig mongod on

nginxのインストール

# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# yum -y install nginx
$ nginx -v

5.ポート構成の確認

$ firewall-cmd --list-all --zone=public

許可するサービスの追加と反映

# firewall-cmd --add-service=http --zone=public --permanent
# firewall-cmd --add-service=https --zone=public --permanent
# firewall-cmd --add-service=ssh --zone=public --permanent
# firewall-cmd --add-port=8080/tcp --zone=public --permanent
# firewall-cmd --reload

6.Wordpressのインストール

デフォルトだとアップロード上限が8MBまでなので不便な場合がある。
適当に上限を変えておく。

/etc/php.ini
post_max_size = 50M
upload_max_filesize = 50M
/etc/nginx/conf.d/***.conf
server{
  #上限を変更
  client_max_body_size 50M; 
}

PHP7とNginxを再起動して反映を確認する

$ sudo systemctl restart php-fpm
$ sudo systemctl restart nginx
11
13
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
11
13