Elasticsearch安装部署及集群搭建,使用elasticsearch-head工具

安装部署Elastichead

1.到官网下载安装包(不同版本的需要的jdk版本是不同的,我的服务器是jdk8,下载使用了别的版本)

https://artifacts.elastic.co/downloads/elasticsearch

2.将下载好的安装包解压至自定义的目录下

tar xvzf elasticsearch-6.8.7.tar.gz  -C /server/

由于使用root用户启动会报错,因此创建别的用户启动

创建用户组esgroup,创建组下成员esuser,并将文件夹权限赋予用户

赋予文件权限

注意:Es默认启动内存为2G

修改配置文件内存大小:(由于测试环境是虚拟机所以要修改下es启动内存)

编辑config下的jvm.options文件,由于我是本地虚拟机搭建的,实际物理服务器若16G的内存,可以将-Xms8g  -Xmx8g

切换至esuser用户然后后台启动elasticsearch

su esuser

进入elasticsearch的bin目录下,后台启动,若不加参数-d表示直接启动,停止应用使用ctrl+c即可停止

./elasticsearch -d

发现拒绝连接,停止服务更改参数配置,查询进程的id,然后杀死即可

ps -ef | grep elasticsearch

然后进入elasticsearch的config目录下,编辑

将network.host的值配置为0.0.0.0

重新启动,这次不后台启动

错误一解决方法

在root用户下修改/etc/security/limits.conf文件,增加以下内容(前面是es用户)

解释:

(nofile)最大开打开文件描述符
(nproc)最大用户进程数
(memlock)最大锁定内存地址空间

esuser soft nofile 65536
esuser hard nofile 65536
esuser soft nproc 4096
esuser hard nproc 4096

ps:这里推荐一个实际生产集群中服务器的配置

*           soft   nofile       65535
*           hard   nofile       65535
es用户名 soft nofile 65536
es用户名 hard nofile 65536
es用户名 soft nproc 4096
es用户名 hard nproc 4096
es用户名 soft memlock unlimited
es用户名 hard memlock unlimited

错误二解决方法

同样root用户下修改/etc/sysctl.conf文件,增加配置

解释:限制一个进程拥有虚拟内存区域的大小

vm.max_map_count=262145

修改完,刷新一下配置

sysctl -p

ps:此处推荐一个实际生产集群中的服务器的配置

vm.max_map_count=655360
vm.swappiness=1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

 再次使用esuser用户启动服务

启动日志大概是这些,然后使用curl工具测试是否安装并启动成功

出现这个表示安装部署成功

安装elasticsearch-head图形化客户端管理工具

到官网下载配置包

https://github.com/mobz/elasticsearch-head

下载好后解压,进入到文件中,使用npm打包运行

npm安装方法参考

https://blog.csdn.net/xibei19921101/article/details/104636795

在该路径下打开cmd执行指令

npm install && npm run start

然后浏览器输入loclahost:9100即可打开elasticsearch-head

不过此时连接会显示集群健康值未连接

修改elasticsearch目录下config/elasticsearch.yml文件配置

在配置中加上配置,设置允许跨域

http.cors.enabled: true
http.cors.allow-origin: "*"

重新启动服务,成功

不使用npm启动也可以直接使用浏览器打开解压后文件里的index.html文件

此处推荐一个谷歌浏览器的插件,在谷歌应用商城可以下载,前提可以访问海外谷歌网址

https://chrome.google.com/webstore/detail/elasticsearch-head/ffmkiejjmecolpfloofpjologoblkegm

elasticsearch集群的搭建

1.修改/etc/security/limits.conf文件

增加以下配置参数值

*           soft   nofile       65535
*           hard   nofile       65535
es用户名 soft nofile 65536
es用户名 hard nofile 65536
es用户名 soft nproc 4096
es用户名 hard nproc 4096
es用户名 soft memlock unlimited
es用户名 hard memlock unlimited

2.修改/etc/sysctl.conf文件

vm.max_map_count=655360
vm.swappiness=1

然后刷新下配置

sysctl -p

3.修改es的config下的elasticsearch.yml文件

(1)修改第一台服务器的配置文件

#集群名(一个集群所有节点的集群名称必须一致)
cluster.name: escluster
#节点名(不同节点,名称不能一致)
node.name: node1-128
network.host: 0.0.0.0
#当前节点的服务端口号
http.port: 9200
transport.host: 0.0.0.0
#节点之间通信端口
transport.tcp.port: 9300
#Paths:切忌使用默认位置,当ES升级时会造成数据丢失。当多个节点共享同一台服务器时,不能使用相同的路径。
#path.data:数据储存路径,多个位置用逗号隔开
#path.logs:日志储存路径
#启动之前一定要配置好目录,并赋予所有者
path.data: /home/esuser/esdata/elasticsearch-node1/data
path.logs: /home/esuser/esdata/elasticsearch-node1/logs
#设置集群的初始节点列表,集群互通端口为9300
discovery.zen.ping.unicast.hosts: ["192.168.236.128:9300", "192.168.236.129:9300", "192.168.236.130:9300"]
#表示集群最少的master数,如果集群的最少master数据少于指定的数,将无法启动,
#	官方推荐node master数设置为集群数/2+1,
#	我这里三台ES服务器,配置最少需要两台master,整个集群才可正常运行
discovery.zen.minimum_master_nodes: 2
#自动发现拼其他节点超时时间
#discovery.zen.ping_timeout: 10s
#主节点(true:是 false:不是)
node.master: true
#存储数据(true:存储 false:不存储)
node.data: true
#参与选举(true:参与 false:不参与)
#node.ingest: true
#锁住物理内存,避免内存交换(禁用swap,生产环境必须设置为true);有swap内存的可以开启此项,若需设置为false,
#	参考:https://elasticsearch.cn/article/149
bootstrap.memory_lock: true
#bootstrap.system_call_filter,Centos6不支持SecComp---需设置为false,如果为CentOS7则可设置为true
bootstrap.system_call_filter: false
#跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.sql.enabled: false
xpack.security.enabled: false

#配置线程队列
thread_pool.write.size: 32
thread_pool.write.queue_size: 100000
processors: 32
thread_pool.bulk.size: 20
thread_pool.bulk.queue_size: 2000
thread_pool.index.size: 32
thread_pool.index.queue_size: 2000
thread_pool.search.size: 90
thread_pool.search.queue_size: 4000
indices.fielddata.cache.size: 30%

注意:配置文件中的冒号和值有空格,path的目录一定要先配置好并赋予文件所属权限

(2)配置第二台服务器的文件

cluster.name: escluster
node.name: node2-130
network.host: 0.0.0.0
http.port: 9200
path.data: /home/esuser/esdata/elasticsearch-node2/data
path.logs: /home/esuser/esdata/elasticsearch-node2/logs
discovery.zen.ping.unicast.hosts: ["192.168.236.128:9300", "192.168.236.129:9300", "192.168.236.130:9300"]
discovery.zen.minimum_master_nodes: 2
node.master: true
node.data: true
node.attr.rack: r1
bootstrap.memory_lock: true
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.sql.enabled: false
xpack.security.enabled: false

(3)配置第三台服务器的配置

cluster.name: escluster
node.name: node3-129
network.host: 0.0.0.0
http.port: 9200
path.data: /home/esuser/esdata/elasticsearch-node3/data
path.logs: /home/esuser/esdata/elasticsearch-node3/logs
discovery.zen.ping.unicast.hosts: ["192.168.236.128:9300", "192.168.236.129:9300", "192.168.236.130:9300"]
discovery.zen.minimum_master_nodes: 2
node.master: true
node.data: true
node.attr.rack: r1
bootstrap.memory_lock: true
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.sql.enabled: false
xpack.security.enabled: false

最后开放服务器的9200以及9300端口,分别启动服务即可

4.创建一个索引,查看集群分部信息,以及副本分区状态在es-head工具中查看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值