ElasticSearch
基本概念
-
索引: 含有相同属性的文档集合。
-
类型:索引可以定义一个或多个类型,文档必须属于一个类型。
-
文档:文档是可以被索引的基本数据单元。
-
分片:每个索引都有多个分片,每个分片是一个Lucene 索引。
-
备份:拷贝一份分片就完成了分片的备份。
安装启动
官网下载地址
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1.tar.gz
tar -zxvf elasticsearch-6.5.1.tar.gz
mkdir /guaoran/elk
mv elasticsearch-6.5.1 /guaoran/elk/
启动
/guaoran/elk/elasticsearch-6.5.1/bin/elasticsearch
报错:
[root@localhost bin]# ./elasticsearch
[2019-05-05T14:23:10,893][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
原因 及 解决 :
ElasticSearch 不允许 root 用户启动,所以需要单独创建一个用户来运行。
-
创建用户 : useradd guaoran(用户名) -g elk(所属组名) -p 123456(密码)
groupadd elk
useradd guaoran -g elk -p 123456
-
授权访问组权限 chown -R guaoran(用户名):elk(所属组名) /path
chown -R guaoran:elk /guaoran/elk
chmod -R 777 /guaoran/elk
su guaoran
-
修改启动参数
vi /guaoran/elk/elasticsearch-6.5.1/config/elasticsearch.yml
绑定 ip 默认是 127.0.0.1
,修改为
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
-
切换用户(su guaoran
)后重新启动 ,依然报错,错误如下:
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2019-05-05T15:30:08,742][INFO ][o.e.n.Node ] [QKqC8YA] stopping ...
[2019-05-05T15:30:08,763][INFO ][o.e.n.Node ] [QKqC8YA] stopped
[2019-05-05T15:30:08,763][INFO ][o.e.n.Node ] [QKqC8YA] closing ...
[2019-05-05T15:30:08,800][INFO ][o.e.n.Node ] [QKqC8YA] closed
[2019-05-05T15:30:08,803][INFO ][o.e.x.m.j.p.NativeController] [QKqC8YA] Native controller process has stopped - no new native processes can be started
修改配置
su root
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
echo "* soft memlock unlimited" >> /etc/security/limits.conf
echo "* hard memlock unlimited" >> /etc/security/limits.conf
echo "vm.max_map_count = 262144" >> /etc/sysctl.conf
sysctl -p
ulimit -l unlimited
-
开放端口
#添加
firewall-cmd --zone=public --add-port=9200/tcp --permanent
#重新载入
firewall-cmd --reload
#查看所有打开的端口
firewall-cmd --zone=public --list-ports
-
检测是否启动
http://192.168.45.135:9200/
http://192.168.45.134:9200/
http://192.168.45.131:9200/
-
启动后台运行
/guaoran/elk/elasticsearch-6.5.1/bin/elasticsearch -d
集群配置
在 elasticsearch.yml
中根据角色进行添加以下内容
master:
#集群名称
cluster.name: elasticsearch
#节点 ID,保证唯一
node.name: master
#标记是否为主节点
node.master: true
network.host: 0.0.0.0
#允许跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
slave
#集群名称三个节点保持一致
cluster.name: elasticsearch
#从节点 ID,保证唯一
node.name: slave-1
#集群的 IP 组,配置主节点 IP 即可
discovery.zen.ping.unicast.hosts: ["192.168.45.135","192.168.45.134","192.168.45.131"]
network.host: 0.0.0.0
快速启动一个集群节点实例
/guaoran/elk/elasticsearch-6.5.1/bin/elasticsearch -Ecluster.name=my_cluster -Epath.data=my_cluster_node1 -Enode.name=node1 -Ehttp.port=5100 -d
集群的状态
-
green 指所有主副分片都正常分配
-
yellow 指所有主分片都正常分配
-
red 有主分片未分配
三种状态只是代表分片的工作状态,并不是代表整个es集群是否能够对外提供服务