yujin2010good
作者yujin2010good·2018-11-27 09:43
系统工程师·大型零售巨头

elasticsearch-6.1.2安装配置维护

字数 7305阅读 1254评论 0赞 2

参考手册:https://cloud.tencent.com/developer/article/1011050

es版本:
3台6.1.2的版本的作ES集群用于日志和报表,安装插件如下:

a. elasticsearch-analysis-ik 6.1.2
b. Elasticsearch-head 6.1.2 可视化管理平台

系统环境:centos7.5
es版本:elasticsearch-6.1.2
jdk:1.8
主机ip
192.168.2.126
192.168.2.127
192.168.2.128

1、软件下载

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.2.tar.gz

2、jdk安装

wget ftp://10.249.100.249/pub/jdk/jdk8/*

3、安装es

tar -xzvf elasticsearch-6.1.2.tar.gz -C /usr/local/
cd /usr/local/
mv elasticsearch-6.1.2/ elasticsearch

4、建立data目录和log目录

mkdir -p /data/elasticsearch/data
mkdir -p /data/elasticsearch/logs

5、建立用户(es不能用root运行)

useradd es
chown -R es:es /usr/local/elasticsearch
chown -R es:es /data

6、系统参数优化

vim /usr/local/elasticsearch/config/jvm.options
-Xms4g
-Xmx4g

vi /etc/sysctl.conf
vm.max_map_count=262144
fs.file-max=655360

vi /etc/security/limits.conf

es         soft   memlock      unlimited
es        hard   memlock      unlimited

7、编辑配置文件

[root@ip-192-168-202-126 ~]# grep '^[a-z]' /usr/local/elasticsearch/config/elasticsearch.yml
cluster.name: es6.1.2
node.name: node-126
node.master: true
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["192.168.2.126", "192.168.2.127", "192.168.2.128"]
gateway.recover_after_nodes: 3

[root@ip-192-168-202-127 bin]# grep '^[a-z]' /usr/local/elasticsearch/config/elasticsearch.yml
cluster.name: es6.1.2
node.name: node-127
node.master: true
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["192.168.2.126", "192.168.2.127", "192.168.2.128"]
gateway.recover_after_nodes: 3

[root@ip-192-168-202-128 ~]# grep '^[a-z]' /usr/local/elasticsearch/config/elasticsearch.yml
cluster.name: es6.1.2
node.name: node-128
node.master: true
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["192.168.2.126", "192.168.2.127", "192.168.2.128"]
discovery.zen.minimum_master_nodes: 2
gateway.recover_after_nodes: 3

8、启动

su - es
/usr/local/elasticsearch/bin/elasticsearch -d

查找ES进程
ps -ef | grep elastic
杀掉ES进程
kill -9 2382(进程号)
重启ES
sh elasticsearch -d

9、检查

[es@ip-192-168-202-126 ~]$ curl localhost:9200
{
  "name" : "node-126",
  "cluster_name" : "es6.1.2",
  "cluster_uuid" : "-k1nGSoAQri3ToEqSoQHYg",
  "version" : {
    "number" : "6.1.2",
    "build_hash" : "5b1fea5",
    "build_date" : "2018-01-10T02:35:59.208Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
[es@ip-192-168-202-126 ~]$ jps
14817 Elasticsearch
15928 Jps
[es@ip-192-168-202-127 ~]$ curl localhost:9200
{
  "name" : "node-127",
  "cluster_name" : "es6.1.2",
  "cluster_uuid" : "-k1nGSoAQri3ToEqSoQHYg",
  "version" : {
    "number" : "6.1.2",
    "build_hash" : "5b1fea5",
    "build_date" : "2018-01-10T02:35:59.208Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
[es@ip-192-168-202-127 ~]$ jps
15026 Elasticsearch
16091 Jps

es@ip-192-168-202-128 ~]$ curl localhost:9200
{
  "name" : "node-128",
  "cluster_name" : "es6.1.2",
  "cluster_uuid" : "-k1nGSoAQri3ToEqSoQHYg",
  "version" : {
    "number" : "6.1.2",
    "build_hash" : "5b1fea5",
    "build_date" : "2018-01-10T02:35:59.208Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
[es@ip-192-168-202-128 ~]$ jps

16033 Jps
14968 Elasticsearch

或者登陆检查
http://192.168.2.126:9200/
http://192.168.2.127:9200/
http://192.168.2.128:9200/

Elasticsearch的健康检查

https://www.elastic.co/guide/en/elasticsearch/guide/current/_cluster_health.html

Elasticsearch提供了自身用于健康检查的API,会返回一组JSON的数据:
curl -XGET http://192.168.2.126:9200/_cluster/health
curl -XGET http://192.168.2.126:9200/_cluster/health?pretty=true

同时,官方还提供了多样监控信息,可以通过cat API的方式来返回需要的数据:
https://www.elastic.co/guide/en/elasticsearch/guide/current/_cat_api.html
curl -XGET http://192.168.2.128:9200/_cat/health

对集群中的任意一个节点去查询,此节点都会从搜集到整个集群的信息进行返回:
curl -XGET http://192.168.2.128:9200/_cat/nodes?v

Elasticsearch有green/yellow/red 三种不同的状态级别,
green 表示所有节点分片正常,yellow 表示主节点分片正常,副本节点分片存在故障或丢失,red 表示主节点分片丢失,在搜索时只能返回部分结果。

[es@ip-192-168-202-127 ~]$ curl -XGET http://192.168.2.126:9200/_cluster/health?pretty=true
{
  "cluster_name" : "es6.1.2",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "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
}
[es@ip-192-168-202-127 ~]$ curl -XGET http://192.168.2.128:9200/_cat/health
1534565131 12:05:31 es6.1.2 green 3 3 0 0 0 0 0 0 - 100.0%
[es@ip-192-168-202-127 ~]$ curl -XGET http://192.168.2.128:9200/_cat/nodes?v
ip              heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.2.126            7          63   0    0.02    0.16     0.15 mdi       -      node-126
192.168.2.127            7          62   0    0.00    0.07     0.08 mdi       *      node-127
192.168.2.128            4          63   1    0.00    0.06     0.08 mdi       -      node-128
[es@ip-192-168-202-127 ~]$ curl -XGET http://192.168.2.127:9200/_cat/nodes?v
ip              heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.2.126            7          63   0    0.01    0.15     0.15 mdi       -      node-126
192.168.2.127            4          62   0    0.00    0.06     0.08 mdi       *      node-127
192.168.2.128            4          63   0    0.00    0.06     0.08 mdi       -      node-128

==============================================
#集群的名称
cluster.name: es6.2
#节点名称,其余两个节点分别为node-2 和node-3
node.name: node-1
#指定该节点是否有资格被选举成为master节点,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master
node.master: true
#允许该节点存储数据(默认开启)
node.data: true
#索引数据的存储路径
path.data: /usr/local/elk/elasticsearch/data
#日志文件的存储路径
path.logs: /usr/local/elk/elasticsearch/logs
#设置为true来锁住内存。因为内存交换到磁盘对服务器性能来说是致命的,当jvm开始swapping时es的效率会降低,所以要保证它不swap
bootstrap.memory_lock: true
#绑定的ip地址
network.host: 0.0.0.0
#设置对外服务的http端口,默认为9200
http.port: 9200
# 设置节点间交互的tcp端口,默认是9300 
transport.tcp.port: 9300
#Elasticsearch将绑定到可用的环回地址,并将扫描端口9300到9305以尝试连接到运行在同一台服务器上的其他节点。
#这提供了自动集群体验,而无需进行任何配置。数组设置或逗号分隔的设置。每个值的形式应该是host:port或host
#(如果没有设置,port默认设置会transport.profiles.default.port 回落到transport.tcp.port)。
#请注意,IPv6主机必须放在括号内。默认为127.0.0.1, [::1]
discovery.zen.ping.unicast.hosts: ["192.168.8.101:9300", "192.168.8.103:9300", "192.168.8.104:9300"]
#如果没有这种设置,遭受网络故障的集群就有可能将集群分成两个独立的集群 - 分裂的大脑 - 这将导致数据丢失
discovery.zen.minimum_master_nodes: 2

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

2

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广