LoginSignup
5
4

More than 5 years have passed since last update.

Redisをいじくり倒す環境をVagrant+Ansibleで構築する

Posted at

Redisをいじくり倒してパフォーマンス検証することになったので環境構築してみる。

必要なもの

  • Vagrant
  • VirtualBox
  • Ansible

準備

Vagrantをいれる

ここからダウンロードしていれる。

VirtualBoxをいれる

ここからダウンロードしていれる。

Ansibleをいれる

brew install ansible

VagrantのBOXを追加する

今回はCentOS 7をいれる。

vagrant box add cent7 https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box

適当なディレクトリを作成し、移動する。

mkdir hoge
cd hoge

Vagrant初期化。

vagrant init cent7

Vagrantfileができるので以下のコメントアウトを外す。

config.vm.network "private_network", ip: "192.168.33.10"

Virtual Machineを起動する。

vagrant up

vagrant sshでもログインできるが、Vagrantfileで指定したipでログインできるかどうか試してみる。パスワードはvagrant

ssh vagrant@192.168.10.33

Ansibleの設定をする

inventory fileを作成する。ファイル名は適当に。

[test-server]
192.168.33.10

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant 
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible_connection=paramiko

ansible_connection=paramikoを指定しないとうまいことsshでログインできないので注意。

Playbookを作る。ファイル名は適当に。

playbook.yml
---
- hosts: test-server
  sudo: yes
  tasks:
    - name: libselinux-python install
      yum: name=libselinux-python state=latest
    - name: gcc install
      yum: name=gcc state=latest
    - name: redis source download
      get_url: >
        url=http://download.redis.io/releases/redis-2.8.19.tar.gz
        dest=/tmp/redis-2.8.19.tar.gz
    - name: redis unarchive
      command: >
        tar zxvf redis-2.8.19.tar.gz
        chdir=/tmp/
    - name: make
      command: >
        make
        chdir=/tmp/redis-2.8.19
    - name: make install
      command: >
        make install
        chdir=/tmp/redis-2.8.19
    - name: deamonize on
      replace: >
        dest=/tmp/redis-2.8.19/redis.conf
        regexp='daemonize no'
        replace='daemonize yes'
    - name: redis.conf copy
      shell: creates=/etc/redis.conf cp /tmp/redis-2.8.19/redis.conf /etc/redis.conf
    - name: redis start
      command: >
        redis-server /etc/redis.conf
      sudo: no

実行してみる

ansible-playbook -i hosts playbook.yml
PLAY [test-server] ************************************************************ 

GATHERING FACTS *************************************************************** 
ok: [192.168.33.10]

TASK: [libselinux-python install] ********************************************* 
ok: [192.168.33.10]

TASK: [gcc install] *********************************************************** 
ok: [192.168.33.10]

TASK: [redis source download] ************************************************* 
ok: [192.168.33.10]

TASK: [redis unarchive] ******************************************************* 
changed: [192.168.33.10]

TASK: [make] ****************************************************************** 
changed: [192.168.33.10]

TASK: [make install] ********************************************************** 
changed: [192.168.33.10]

TASK: [deamonize on] ********************************************************** 
changed: [192.168.33.10]

TASK: [redis.conf copy] ******************************************************* 
ok: [192.168.33.10]

TASK: [redis start] *********************************************************** 
changed: [192.168.33.10]

PLAY RECAP ******************************************************************** 
192.168.33.10              : ok=10   changed=5    unreachable=0    failed=0   

上のは2回に実行した結果なので初回の結果とは若干違うかも。最終的にok=10になってればOKだと思う。

確認してみる

vagrant sshでも直接sshでもどちらでもいいのでログインする。

vagrant ssh
[vagrant@localhost ~]$ redis-server -v
Redis server v=2.8.19 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=41ebe2a844e67838
[vagrant@localhost ~]$ redis-cli
127.0.0.1:6379> 

ちゃんと入ってる。成功。

参考

5
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
5
4