0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

<Vagrant+VirtualBox(centos7)>ローカル仮想環境にnginxをインストール起動してみた

Posted at

はじめに

バージョンは以下で、挑戦。

Vagrant:2.2.14
VirtualBox:Oracle VM VirtualBox Manager 6.1.16
centos:7 2004.01
nginx:1.18.0

1.VagrantでVMware(VirtualBox)を起動

こちらを参考に
(Vagrant+VirtualBox)ローカルで仮想環境を立ち上げてみる

仮想環境を立ち上げた。

vagrant up

2.VirtualBox内にログイン

こちらのコマンドで、仮想環境内にログイン。

vagrant ssh
Last login: Fri Feb 26 07:38:33 2021

ハマりポイント

vagrant upで起動時に、

config.vm.synced_folder ".", "/vagrant",

としていると、2回目の起動時に、
仮想サーバー内の/vagrant/が上書きされて、sshに必要な/vagrant/.ssh/が消されちゃうので、
例えば、3階層にしておくといいっぽい。

config.vm.synced_folder ".", "/home/vagrant/working_directory",

3.nginxの導入

コマンドはこれ。

sudo su -
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 
yum install nginx

<解説>

  • sudo su -:管理者rootにユーザー切り替え。
  • rpmコマンド:centos7に合ったnginxのパッケージをインストール
    • Red Hat系のLinuxディストリビューションで使われているRPM(Red Hat Package Manager)パッケージを扱うことができるパッケージ管理コマンド
    • -i:install
    • -v:情報表示を増やす
    • -h:インストール時の経過を「#」マークで表示
  • yumコマンド:yumコマンドでnginx自体をインストール
    • CentOSなどで使われている「Yum(Yellowdog Updater Modified)」というパッケージ管理システム

rpmとyumの使い分け

CentOSのようにYumに対応している環境なら基本的にyumコマンドでパッケージのインストールやアップデートなどを行い、
新しいソフトウェアやマイナーなソフトウェアなど、yumコマンドではまだ扱えないパッケージに対しては、rpmコマンドを使うと良い

4.nginxの起動/停止

# 起動
sudo systemctl start nginx
# ステータス確認
sudo systemctl status nginx
# 停止
sudo systemctl stop nginx
# 自動起動設定もできる
sudo systemctl enable nginx

※権限があれば、sudoなくても大丈夫。

無事、サーバーが立ち上がった!!!

スクリーンショット 2021-02-26 17.17.07.png

5. 仮想環境から抜けて、仮想環境も停止

exit
logout
Connection to 127.0.0.1 closed.

exitでポンポンポンポンしまくる。

抜けたら、

vagrant halt

停止を確認。

==> default: [vagrant-hostsupdater] Removing hosts
==> default: [vagrant-hostsupdater] Removing hosts
==> default: Attempting graceful shutdown of VM...
==> default: [vagrant-hostsupdater] Removing hosts
==> default: [vagrant-hostsupdater] Removing hosts
==> default: [vagrant-hostsupdater] Removing hosts
==> default: [vagrant-hostsupdater] Removing hosts
==> default: [vagrant-hostsupdater] Removing hosts
==> default: [vagrant-hostsupdater] Removing hosts
==> default: [vagrant-hostsupdater] Removing hosts
==> default: [vagrant-hostsupdater] Removing hosts

vagrant-hostsupdaterは便利なプラグインです。etc/hostsを自動で更新してくれる。

まとめ

仮想環境(VMware)のOS(centOS7)にサーバー(ミドルウェアnginx)が立ち上がった。
なんだか、一つの魔法を使って村を作った気分だ。(感動)

以上、
ありがとうございました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?