ELK 之 Elasticsearch集群部署(阿里云)(ansible-playbook自动化部署)

使用yum安装Elasticsearch
  • 下载并安装ES的yum公钥
[root@es1 ~]#  rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
  • 配置Elasticsearch的yum源
[root@es1 ~]#  vim /etc/yum.repos.d/elasticsearch.repo

[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
[root@es1 ~]#  yum clean all
[root@es1 ~]#  yum repolist
[root@es1 ~]#  yum makecache
[root@es1 ~]#  yum -y install elasticsearch
[root@es1 ~]# vim  +54 /etc/elasticsearch/elasticsearch.yml 

原为: network.host: 192.168.0.1

改为: network.host: 0.0.0.0

[root@es1 ~]# systemctl start elasticsearch.service
[root@es1 ~]# systemctl enabled elasticsearch.service
[root@es1 ~]# ss -nutlp  | grep java

tcp LISTEN 0 50 :::9200 ::😗 users:((“java”,pid=910,fd=109))
tcp LISTEN 0 50 :::9300 ::😗 users:((“java”,pid=910,fd=91))

[root@es1 ~]# curl 192.168.1.11:9200

{
“name” : “Geb”,
“cluster_name” : “elasticsearch”,
“cluster_uuid” : “tSfRijFeQaaOFVRWckJ8GA”,
“version” : {
“number” : “2.4.6”,
“build_hash” : “5376dca9f70f3abef96a77f4bb22720ace8240fd”,
“build_timestamp” : “2017-07-18T12:17:44Z”,
“build_snapshot” : false,
“lucene_version” : “5.5.4”
},
“tagline” : “You Know, for Search”

浏览器中输入ip地址和端口访问试试,如果访问被拒绝,添加防火墙设置(我的阿里云服务器是需要设置的)
[root@es1 ~]# iptables -I INPUT -p tcp --dport 9200 -j ACCEPT

利用ansible-playbook批量部署elasticsearch集群

主机名IP规划角色
es1192.168.1.11管理机
es2192.168.1.12集群node
es3192.168.1.13集群node
es4192.168.1.14集群node
es5192.168.1.15集群node

前提条件:

  1. 管理机安装ansible
  2. 创建好公钥和私钥并传给集群所有机器,能免密登入
  3. 确定所有机器时间同步

[root@es1 elasticsearch]# tree elasticsearch
elasticsearch
├── ansible.cfg
├── Centos-7.repo
├── elasticsearch.repo
├── elasticsearch.yml
├── essetup.retry
├── essetup.yml
├── hosts
└── myhost

[root@es1 elasticsearch]# vim ansible.cfg
[defaults]
inventory      = myhost
host_key_checking = False
[root@es1 elasticsearch]# vim Centos-7.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[root@es1 elasticsearch]# vim elasticsearch.repo
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1

[root@es1 elasticsearch]# vim elasticsearch.yml

修改下面四行:

cluster.name: myelk
node.name: {{ansible_hostname}}
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: [“es1”, “es2”, “es3”]

[root@es1 elasticsearch]# vim essetup.yml
---
- hosts: es
  remote_user: root
  tasks:
    - copy:
        src: "{{ item.src }}"
        dest: /etc/yum.repos.d/
        owner: root
        group: root
        mode: 0644
      with_items:
        - {src: Centos-7.repo}
        - {src: elasticsearch.repo}
    - copy:
        src: /etc/hosts
        dest: /etc/hosts
        owner: root
        group: root
        mode: 0644


    - name: install elasticsearch
      yum:
        name: java-1.8.0-openjdk,elasticsearch
        state: installed
    - template:
        src: elasticsearch.yml
        dest: /etc/elasticsearch/elasticsearch.yml
        owner: root
        group: root
        mode: 0644
      notify: reload elasticsearch
      tags: esconf
    - service:
        name: elasticsearch
        enabled: yes
  handlers:
    - name: reload elasticsearch
      service:
        name: elasticsearch
        state: restarted
[root@es1 elasticsearch]# vim hosts
# ::1           localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1       localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.1.11    es1
192.168.1.12    es2
192.168.1.13    es3
192.168.1.14    es4
192.168.1.15    es5

[root@es1 elasticsearch]# vim myhost

[es]
192.168.1.[11:15]
[root@es1 elasticsearch]# ansible-playbook essetup.yml 

PLAY [es] ************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************
ok: [192.168.1.11]
ok: [192.168.1.15]
ok: [192.168.1.14]
ok: [192.168.1.12]
ok: [192.168.1.13]

TASK [copy] **********************************************************************************************************************************************************************************
ok: [192.168.1.11] => (item={u’src’: u’Centos-7.repo’})
changed: [192.168.1.12] => (item={u’src’: u’Centos-7.repo’})
changed: [192.168.1.13] => (item={u’src’: u’Centos-7.repo’})
changed: [192.168.1.15] => (item={u’src’: u’Centos-7.repo’})
changed: [192.168.1.14] => (item={u’src’: u’Centos-7.repo’})
ok: [192.168.1.11] => (item={u’src’: u’elasticsearch.repo’})
changed: [192.168.1.12] => (item={u’src’: u’elasticsearch.repo’})
changed: [192.168.1.13] => (item={u’src’: u’elasticsearch.repo’})
changed: [192.168.1.15] => (item={u’src’: u’elasticsearch.repo’})
changed: [192.168.1.14] => (item={u’src’: u’elasticsearch.repo’})

TASK [install elasticsearch] *****************************************************************************************************************************************************************
ok: [192.168.1.11]
changed: [192.168.1.12]
changed: [192.168.1.14]
changed: [192.168.1.15]
changed: [192.168.1.13]

TASK [template] ******************************************************************************************************************************************************************************
changed: [192.168.1.11]
changed: [192.168.1.13]
changed: [192.168.1.14]
changed: [192.168.1.12]
changed: [192.168.1.15]

TASK [service] *******************************************************************************************************************************************************************************
ok: [192.168.1.11]
changed: [192.168.1.12]
changed: [192.168.1.14]
changed: [192.168.1.13]
changed: [192.168.1.15]

RUNNING HANDLER [reload elasticsearch] *******************************************************************************************************************************************************
changed: [192.168.1.11]
changed: [192.168.1.14]
changed: [192.168.1.12]
changed: [192.168.1.13]
changed: [192.168.1.15]

PLAY RECAP ***********************************************************************************************************************************************************************************
192.168.1.11 : ok=6 changed=2 unreachable=0 failed=0
192.168.1.12 : ok=6 changed=5 unreachable=0 failed=0
192.168.1.13 : ok=6 changed=5 unreachable=0 failed=0
192.168.1.14 : ok=6 changed=5 unreachable=0 failed=0
192.168.1.15 : ok=6 changed=5 unreachable=0 failed=0

访问集群网页,确定是否部署成功
[root@elk ~]$ curl firefox http://192.168.1.11:9200/_cluster/health?pretty
502 Bad Gateway

502 Bad Gateway


nginx
{ "cluster_name" : "myelk", "status" : "green", "timed_out" : false, "number_of_nodes" : 5, "number_of_data_nodes" : 5, "active_primary_shards" : 0, "active_shards" : 0, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 100.0 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值