略
# vi /etc/hosts
添加以下内容
192.168.1.241 p241
192.168.1.242 p242
192.168.1.243 p243
192.168.1.244 p244
192.168.1.245 p245
192.168.1.246 p246
192.168.1.247 p247
192.168.1.248 p248
192.168.1.249 p249
# vi /etc/yum.repos.d/elasticsearch.repo
输入下面的代码
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
# dnf -y install --enablerepo=elasticsearch elasticsearch
# systemctl enable elasticsearch
# systemctl stop elasticsearch
# systemctl start elasticsearch
# systemctl restart elasticsearch
# curl -X GET localhost:9200
IP | 主机名 |
---|---|
centered 文本居中 | right-aligned 文本居右 |
IP | 主机名 | master | data | 备注 |
---|---|---|---|---|
192.168.1.241 | P241 | √ | Elasticsearch | |
192.168.1.242 | P242 | √ | ||
192.168.1.243 | P243 | √ | ||
192.168.1.244 | P244 | √ | ||
192.168.1.245 | P245 | √ | ||
192.168.1.246 | P246 | √ | ||
192.168.1.247 | P247 | Logstash | ||
192.168.1.248 | P248 | Kibana |
注:
分片(index.number_of_shards):默认为5,是你节点数量的1.5~3倍,3台机器分片数最多不超过9(3x3)个
副本(index.number_of_replicas):默认为1,设置为1-2个就能保证高可用了(设置为1的时候就是有2份数据了)
默认情况下,Elasticsearch假定您正在开发模式下工作。 如果未正确配置上述任何设置,则会向日志文件写入警告,但您将能够启动并运行Elasticsearch节点。
一旦配置了network.host之类的网络设置,Elasticsearch就会假定您正在转向生产并将上述警告升级为异常。 这些异常将阻止您的Elasticsearch节点启动。 这是一项重要的安全措施,可确保您不会因服务器配置错误而丢失数据。
vi /etc/elasticsearch/elasticsearch.yml
内容如下:
cluster.name: es-bj001
node.name: p241
node.master: true
node.data: false
path.data: /data/elasticsearch
path.logs: /log/elasticsearch
network.host: 192.168.1.241
discovery.seed_hosts: ["192.168.1.241","192.168.1.242","192.168.1.243"]
cluster.initial_master_nodes: ["192.168.1.241","192.168.1.242","192.168.1.243"]
注意,每台服务器的node.name、network.host都不同
vi /etc/elasticsearch/elasticsearch.yml
内容如下:
cluster.name: es-bj001
node.name: p24
node.master: false
node.data: true
path.data: /data/elasticsearch
path.logs: /log/elasticsearch
network.host: 192.168.1.24
discovery.seed_hosts: ["192.168.1.241","192.168.1.242","192.168.1.243"]
cluster.initial_master_nodes: ["192.168.1.241","192.168.1.242","192.168.1.243"]
注意,每台服务器的node.name、network.host都不同
vi /etc/elasticsearch/elasticsearch.yml
内容如下:
cluster.name: es-bj001
node.name: p247
node.master: false
node.data: false
node.ingest: false
path.data: /data/elasticsearch
path.logs: /log/elasticsearch
network.host: 192.168.1.24
discovery.seed_hosts: ["192.168.1.241","192.168.1.242","192.168.1.243"]
cluster.initial_master_nodes: ["192.168.1.241","192.168.1.242","192.168.1.243"]
注意,每台服务器的node.name、network.host都不同
vi /etc/elasticsearch/jvm.options
内容如下:
-Xms4g
-Xmx4g
这样将内存设置为4G,如果你的内存够大,可以设置为总内存的一半。
vi /etc/selinux/config
内容修改如下:
SELINUX=disabled
查看SELinux状态
# getenforce
Disabled
# /usr/sbin/sestatus -v
SELinux status: disabled
# systemctl disable firewalld #停掉防火墙开机启动
# systemctl stop firewalld #停掉防火墙服务
# systemctl status firewalld #停掉防火墙服务
# reboot
目录相关配置:
# mkdir -p /data/elasticsearch
# mkdir -p /log/elasticsearch
# chown -R elasticsearch:elasticsearch /data/elasticsearch
# chown -R elasticsearch:elasticsearch /log/elasticsearch
从241到248一台一台的启动
# systemctl stop elasticsearch
# systemctl start elasticsearch
# ps auxZ | grep -v grep | grep nginx
#index.number_of_shards: 6 #报致命错误
#index.number_of_replicas: 2 #报致命错误
#bootstrap.memory_lock: true #内存锁不住,服务无法启动,需要研究怎么解决
#node.ingest: false #等服务器集群大了再用这个参数
#http.port: 9200 #除非要改变默认端口,否则没必要配置这个参数
测试访问
# curl -X GET 192.168.1.241:9200
# curl -X GET 192.168.1.242:9200
# curl -X GET 192.168.1.243:9200
# curl -X GET 192.168.1.244:9200
# curl -X GET 192.168.1.245:9200
# curl -X GET 192.168.1.246:9200
# curl -X GET 192.168.1.247:9200
# curl -X GET 192.168.1.248:9200
elasticsearch启动后查看是否启动成功:
curl -X GET “http://192.168.1.241:9200/_cluster/health?pretty=true”
停止elasticsearch应用:
curl -X POST “http:// 192.168.1.241:9200/_shutdown”
查看集群健康:
curl 192.168.1.241:9200/_cluster/health?pretty
检查集群状态:
curl 192.168.1.241:9200/_cluster/stats?pretty
节点状态:
curl 192.168.1.241:9200/_nodes/process?pretty
curl 192.168.1.241:9200/_nodes/p241/process?pretty
当你不知道有那些属性可以查看时:
curl ‘192.168.1.241:9200/_cat/’ #会返回可以查看的属性
pretty指令是美化显示的意思。