LoginSignup
0
2

More than 5 years have passed since last update.

vagrantにcentos7とnginxをインストールして、ブラウザで表示するまで

Last updated at Posted at 2018-06-24

タイトルどおりのメモです!
varnishの練習のために、環境を構築してみました。
(学習用のため正確ではないかと思います。注意ください。varnishがそもそもあまり分かっていないので、これで練習できるのかなど、よく分かってなかったりします笑)
varnishに関しては、一切触れていません。
また別記事にできたらと思います。


作業フォルダを作成して以下のコマンドを実行
vagrant init centos/7

表示されたコマンドを実行
vagrant up
インストール開始

出力されたので何気なくメモ
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key

接続
vagrant ssh

参考:
https://qiita.com/grachro/items/4d34a43a9a57946f3693

rootユーザに
sudo su -

vi /etc/yum.repos.d/nginx.repo
nginx.reposを作成
コピペ元
https://www.nginx.com/resources/wiki/start/topics/tutorials/install/

nginxインストール
sudo yum install nginx

Is this ok [y/d/N]: y

nginx起動
sudo service nginx start

エラー
Redirecting to /bin/systemctl start nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2018-06-24 06:26:52 UTC; 3min 34s ago
Docs: http://nginx.org/en/docs/
Process: 2923 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

SELinuxあたりのエラー?

以下のコマンドで確認
getenforce

SELinuxが有効になっている
Enforcing

セキュリティ的にあれだが、テストのため無効に修正。

/etc/selinux/config ファイル内のSELINUX=disabledにして
再起動:reboot
再接続:vagrant ssh
rootユーザに切り替え:sudo su -
確認:getenforce
 -> Disabled

参考:
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/selinux_users_and_administrators_guide/sect-security-enhanced_linux-working_with_selinux-changing_selinux_modes

再度nginx起動(centos6とかのコマンド?)
sudo service nginx start
エラー?
Redirecting to /bin/systemctl start nginx.service

centos7はsystemctlコマンドを使用する
systemctl start nginx
(停止時:systemctl enable nginx)

参考:
https://labs.precs.co.jp/2014/12/16/75/

nginxの起動状態の確認コマンド
sudo systemctl status nginx

nginxのプロセス確認
ps aux | grep nginx

ポート確認
ss -an | grep LISTEN | grep :80

centosにnginxをインストールして表示するまで
https://hajipro.com/local-development-environment-mac/vagrant-centos7-nginx (すごい参考になりました)
http://vdeep.net/centos7-nginx
https://weblabo.oscasierra.net/nginx-centos7-install/

ブラウザにアクセスできない。。。
そもそもvagrantfileなるものにアドレスの設定していなかった...
修正
vagrantfile
config.vm.network "private_network", ip: "192.168.33.10"

vagrant up
vagrant ssh
sudo -su

nginxの起動状態の確認コマンド
sudo systemctl status nginx

nginx再起動
centos7はsystemctlコマンドを使用する
systemctl start nginx
(停止時:systemctl enable nginx)

ブラウザに192.168.33.10でアクセス
open http://192.168.33.10/index.html

表示された!!

ファイヤーフォールやSELInuxの設定周りをどうするかも、学習せねば!

 
 
次の記事: varnishをvagrantにインストールする


メモ

vagrant init (centos/7とか) / 初期化、vagrantfileの作成
vagrant up / 起動
vagrant ssh / ログイン
vagrant halt / 終了

vagrant reload / リロード

vim
コピー:yy
ペースト:p
行削除:dd
1文字削除:x

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