LoginSignup
4
4

More than 1 year has passed since last update.

centos7設定手順

Last updated at Posted at 2018-09-10

OSの確認

cat /etc/redhat-release

yumを最新状態にする

yum clean all && yum -y update

必要そうなパッケージをインストール

yum install -y git wget vim mysql-devel

selinuxの無効化

  • 確認
getenforce
# Enforcing だった場合は有効
  • selinuxを無効に設定
vi /etc/selinux/config
# SELINUXS = enforcing -> SELINUX=disabled
  • サーバーを再起動
reboot
  • 確認
getenforce
# Disabled だった場合は無効

ユーザーの作成

useradd my_user
passwd my_user

鍵設定

  • 秘密鍵の作成
ssh-keygen -t rsa -b 4096 -C "sample@sample.com"
  • 公開鍵の設定
cd
mkdir .ssh
chmod 700 .ssh
vi authorized_keys
# ログインを許容する公開鍵を登録
chmod 600 authorized_keys

sshのポートを変える

  • firewalldの設定を変更
cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/ssh.xml
vi /etc/firewalld/services/ssh.xml
# 22 -> 任意のポート番号
sudo firewall-cmd --reload
  • sshポートの変更
vi /etc/ssh/sshd_config
# Portを任意のポート番号に変更
# PermitRootLoginもnoに
systemctl restart sshd

ファイアウォールの設定

  • firewalldのインストール
yum install -y firewalld
  • firewalldの起動
systemctl start firewalld.service
  • firewalldの自動起動
systemctl enable firewalld.service
  • 開放するポートの追加の反映
firewall-cmd --add-service=ssh --permanent
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
firewall-cmd --reload
  • 開放しているポートの確認
firewall-cmd --list-all

言語の設定

  • locale設定
localectl set-locale LANG=ja_JP.utf8
  • 確認
localectl
  • nkfコマンドインストール
yum install -y  epel-release
yum install -y nkf --enablerepo=epel

時刻の同期

date && chronyc -a makestep && date

タイムゾーンの設定

  • 東京の存在を確認
timedatectl list-timezones | grep Tokyo
  • 設定
timedatectl set-timezone Asia/Tokyo
  • 確認
timedatectl
  • crondも再起動が必要
systemctl restart crond.service

ruby(rbenv)

refs: https://qiita.com/abgata20000/items/8bfd25d76692063cc012

node.js(ndenv)

  • nodeユーザーを作成
groupadd node
usermod -aG node myuser
groups myuser
  • ndenvを設定
cd /usr/local
git clone https://github.com/riywo/ndenv.git ndenv
mkdir ndenv/plugins
cd ndenv/plugins
git clone https://github.com/riywo/node-build.git node-build

cd /usr/local

chgrp -R node ndenv
chmod -R g+rwxX ndenv


echo 'export PATH="/usr/local/ndenv/bin:$PATH"' >> /etc/profile.d/ndenv.sh
echo 'export PATH="/usr/local/ndenv/plugins/node-build/bin:$PATH"' >> /etc/profile.d/ndenv.sh
echo 'eval "$(ndenv init -)"' >> /etc/profile.d/ndenv.sh

source /etc/profile.d/ndenv.sh

echo $PATH

  • node.jsをインストール
ndenv install -l
ndenv install v10.22.1
ndenv global  v10.22.1
ndenv rehash
node -v
curl -s https://raw.githubusercontent.com/tophat/yvm/master/scripts/install.js | node

nginx

  • リポジトリを設定
vi /etc/yum.repos.d/nginx.repo

中身は

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
  • nginxをインストール
yum install -y nginx
  • nginxの確認
nginx -v
  • 自動起動
systemctl enable nginx
  • 起動
systemctl start nginx
  • 停止
systemctl stop nginx
  • 再起動
systemctl restart nginx
  • 状態確認
systemctl status nginx
  • 設定ファイルの確認
nginx -t

certbotをインストール

sudo yum -y install certbot python2-certbot-nginx
  • SSL証明書を取得
certbot certonly --webroot --agree-tos --debug -m sample@sample.jp -d sample -w /var/www/letsencrypt-webroot
  • 自動更新を設定
crontab -e
0 4 * * * certbot renew --no-self-upgrade --debug --post-hook "service nginx restart"
4
4
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
4
4