LoginSignup
0
3

More than 5 years have passed since last update.

ABテスト環境を構築する(その1)

Last updated at Posted at 2017-05-17

やってみたいこと

nginx でロードバランスを行い、WEB#1/WEB#2 を起動して apache のログを fluend でログサーバへ転送してその内容をリアルタイムで確認して ABテスト環境のベースを作成したい。

動機

WEB#1/WEB#2 で冗長構成で運用されているサービスをいつも見かけるけど。その中で自分のリリースしたサービスが本当に価値のあるものあのかを確認できるようにすることで技術を提案できるのではとおもったから

環境構築

いつもどおり Vagrant で仮想環境を構築

Vagrantfile
  config.vm.define "nginx" do |node|
      node.vm.box = "centos7"
      node.vm.network "forwarded_port", guest: 80, host: 8080
      node.vm.network :private_network, ip: "192.168.33.10", virtualbox__intnet: "intnet"
  end
  config.vm.define "web1" do |node|
      node.vm.box = "centos7"
      #node.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2222
      #node.vm.network "forwarded_port", guest: 80, host: 8080
      node.vm.network :private_network, ip: "192.168.33.100", virtualbox__intnet: "intnet"
  end
  config.vm.define "web2" do |node|
      node.vm.box = "centos7"
      node.vm.network "forwarded_port", guest: 80, host: 8082
      node.vm.network :private_network, ip: "192.168.33.102", virtualbox__intnet: "intnet"
  end

nginx インストール

ここの centos 用の設定を参照
https://www.nginx.com/resources/wiki/start/topics/tutorials/install/

/etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

$ sudo yum -y install nginx
$ nginx -v
今回インストールしたバージョンはnginx version: nginx/1.12.0でした

nginx 起動

$ sudo systemctl start nginx
$ sudo systemctl status nginx
nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled)
   Active: active (running) since 火 2017-05-16 14:02:29 UTC; 6s ago
     Docs: http://nginx.org/en/docs/
  Process: 21017 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
  Process: 21015 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 21019 (nginx)
   CGroup: /system.slice/nginx.service
           ├─21019 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─21020 nginx: worker process

 5月 16 14:02:28 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
 5月 16 14:02:28 localhost.localdomain nginx[21015]: nginx: the configuration file /etc/nginx/nginx.conf... ok
 5月 16 14:02:28 localhost.localdomain nginx[21015]: nginx: configuration file /etc/nginx/nginx.conf tes...ful
 5月 16 14:02:28 localhost.localdomain systemd[1]: PID 20976 read from file /run/nginx.pid does not exist.
 5月 16 14:02:29 localhost.localdomain systemd[1]: Started nginx - high performance web server.
Hint: Some lines were ellipsized, use -l to show in full.

nginx 動作確認

apache インストール

共通設定
$ sudo systemctl stop firewalld
$ sudo ssytemctl disable firewalld
$ sudo yum install httpd
$ sudo systemctl status httpd
$ sudo systemctl start httpd
$ sudo systemctl status httpd
$ sudo systemctl enable httpd
web#1
$ sudo echo "<html><body>web1 running ...</body></html>" > /var/www/html/index.html 
$ curl localhost
<html><body>web1 running ...</body></html>
web#2
$ sudo echo "<html><body>web2 running ...</body></html>" > /var/www/html/index.html 
$ curl localhost
<html><body>web2 running ...</body></html>

ロードバランス設定

web#1/web#2 に nginx のロードバランスできるように設定

/etc/nginx/conf.d/server.conf
upstream myapp1 {
    server 192.168.33.100;
    server 192.168.33.102;
}

server {
    listen       80;
    location / {
        set $do_not_cache 0;
        proxy_pass http://myapp1;
    }
}

ちょっとはまりました。上記フォルダに default.conf があり server.conf を作成した場合に default.conf の設定を参照していてロードバランスの確認が出来なかったです。

nginx
$ sudo systemctl restart nginx

動作確認

http://localhost:8080

最後に

前回の Fluentd ってどんなことができるのか試してみたかった(メモ+α)を活用して今後は apache のサーバログを使ってABテストの準備環境を作成したいと思います。

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