LoginSignup
5
4

More than 5 years have passed since last update.

Amazon EC2でsolr cloudを構築してみる

Last updated at Posted at 2016-06-12

solr cloudのバージョンUP検証をAmazon EC2を利用してやってみる。
※実行するとEC2の利用料金が掛かります。
利用料金詳細はこちら

必要なもの

  • AWSアカウント/Amazon EC2 のシークレットキー/キーペア

  • Amazon VPC(172.31.0.0/16)
    VPCの作成はプロビジョニング対象から外しています

  • 以下、使用するツールのインストール

使用するツール

  • TerraForm
    インフラ(EC2)のセットアップを行う

  • Ansible 
    アプリのセットアップ行う

手順

  1. EC2のセットアップ(2台)

  2. EC2インスタンスへsolr cloudセットアップ

EC2セットアップ

TerraformでEC2のプロビジョニングを行う。
サンプルソース

  • tfファイルを作成
    プロビジョニング設定の.tfファイルを作成する
variable "access_key" {}
variable "secret_key" {}

provider "aws" {
    access_key = "${var.access_key}"
    secret_key = "${var.secret_key}"
    region = "ap-northeast-1"
}

resource "aws_instance" "solr1" {
    ami = "ami-b1b458b1"
    key_name = "devenv-key"
    instance_type = "t2.small"
    vpc_security_group_ids = [
        "${aws_security_group.allow_local.id}"
    ]
    private_ip = "172.31.1.1"
}

resource "aws_instance" "solr2" {
    ami = "ami-b1b458b1"
    key_name = "devenv-key"
    instance_type = "t2.small"
    vpc_security_group_ids = [
        "${aws_security_group.allow_local.id}"
    ]
    private_ip = "172.31.1.2"
}

resource "aws_security_group" "allow_local" {
    name = "allow_local"
    description = "Allow Only Local traffic"
    ingress {
        from_port = 0
        to_port = 0
        protocol = "-1"
        cidr_blocks = ["xxx.xxx.xxx.xxx/32","172.31.0.0/16"]
    }
    egress {
        from_port = 0
        to_port = 0
        protocol = "-1"
        cidr_blocks = ["0.0.0.0/0"]
    }
}

※ securityグループでインターネット接続元のGrobal IPとVPC内の接続のみ許可

  • tfvarsファイルを作成
    AWS CLIを利用できるようにアクセスキー/シークレットキーを.tfvarsに記載する
access_key="[AWS accessKeyを記載]"
secret_key="[AWS secretKeyを記載]"
  • EC2のプロビジョニングを検証
terraform plan -var-file=secret.tfvars
  • EC2のプロビジョニングを実行
terraform apply -var-file=secret.tfvars

Solr Cloud構築

AnsibleでSolr Cloudの構築を行う。
サンプルソース

  • hostsの作成
[solr]
solr1 ansible_ssh_host=[AWSで払い出されたGrobal Ipを記載] ansible_ssh_user=ec2-user local_ip=172.31.1.1 myid=1
solr2 ansible_ssh_host=[AWSで払い出されたGrobal Ipを記載] ansible_ssh_user=ec2-user local_ip=172.31.1.2 myid=2
  • ymlの作成
    アプリセットアップ用のyml作成
- hosts: solr
  become: yes
  vars:
    solr_version: 6.0.1
    zookeeper_version: 3.4.8
  tasks:a
    - name: wget install
      yum: name=wget state=installed

    - name: jdk download #headerを利用し、認証スキップ
      shell: 'wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm'
      when: install_skip is undefined

    - name: jdk install
      shell: rpm -ivh jdk-8u91-linux-x64.rpm
      when: install_skip is undefined

    - name: solr dowonload
      get_url: url=http://archive.apache.org/dist/lucene/solr/{{solr_version}}/solr-{{solr_version}}.tgz dest=/opt/ mode=0755
      when: install_skip is undefined

    - name: solr unarchive
      unarchive: src=/opt/solr-{{solr_version}}.tgz dest=/opt/ copy=no

    - name: zookeeper dowonload
      get_url: url=http://ftp.jaist.ac.jp/pub/apache/zookeeper/zookeeper-{{zookeeper_version}}/zookeeper-{{zookeeper_version}}.tar.gz dest=/opt/ mode=0755
      when: install_skip is undefined

    - name: zookeeper unarchive
      unarchive: src=/opt/zookeeper-{{zookeeper_version}}.tar.gz dest=/opt/ copy=no
      when: install_skip is undefined

    - name: create zookeeper data dir
      file: path=/var/zookeeper state=directory owner=root

    - name: write myid file #zookeeper myidファイル作成
      template: src=myid dest=/var/zookeeper

    - name: setting zookeeper conf ##zookeeper設定ファイル作成
      template: src=zoo.cfg dest=/opt/zookeeper-{{zookeeper_version}}/conf/
  • セットアップ実行(※AWSキーペアを用意しておくこと)
ansible-playbook -i hosts --private-key=devenv-key.pem provisioning.yml -v
  • solr cloud起動
#zookeeper起動
/opt/zookeeper-{{zookeeper_version}}/bin/zkServer.sh start
#solr起動
/opt/solr-{{solr_version}}/bin/solr start -c -z 172.31.1.1:2181,172.31.1.2:2181
  • solr セットアップ
    割愛(※以下、Solr APIを利用してセットアップ)
    Collection API 

EC2インスタンスの削除

TerraformでEC2の削除を行う。

  • 検証
terraform plan -destroy -out=./terraform.tfstate -var-file=secret.tfvars
  • EC2インスタンスの削除実行
terraform apply ./terraform.tfstate

最後に

cloud、toolを使えば、サクッと様々なバージョンの挙動が検証できました。
今回はawsの勉強も兼ねているため、vagrantではなくec2を利用してみました。

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