1台目のサーバー設定をする(webのロードバランサ)
ServersManのVPSをシンプルプランで契約しました。
・とりあえずrootで入ります。(ssh接続できるポート番号がメールに記載されています)
・root以外の管理者ユーザーを作成してパスワードを設定
useradd -G wheel lb_web
passwd lb_web
・作成した管理者ユーザーでログインして、sudoコマンドが使えることを確認
sudo su -
Nginxをインストールしていきます。
・Nginxのリポジトリのインストール
sudo yum -y install http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
・Nginxのパッケージのインストール
sudo yum -y install --enablerepo=nginx nginx
・インストールされた確認
nginx -v
「http://IPアドレス」にアクセスするとServersManのVPSのシンプルプランの場合、Apacheがインストールされているので、今回はNginxを使いたいためApacheを停止させます。
sudo systemctl stop httpd
・iptablesのインストール
sudo yum -y install iptables-services
・80番ポートの開放
/etc/sysconfig以下にあるiptablesのファイルに一行追記します。
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
COMMIT
sudo systemctl start iptables
sudo systemctl enable iptables
sudo systemctl status iptables
・Nginxの起動と自動起動の設定
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
sudo systemctl status nginx.service
・iptablesとNginxの自動起動設定が正常に設定されているか確認
sudo systemctl list-unit-files -t service | grep -e iptables -e nginx
「http://IPアドレス」にアクセスして、「Welcome to nginx!」が表示されていれば成功。