centos7 单实例安装 + 分布式安装ElasticSearch7.x + elasticsearch-head插件 + ik分词记录

一  单实例安装

下载地址:https://www.elastic.co/cn/downloads/elasticsearch 

  • ES 5,安装需要 JDK 8 以上
  • ES 6.5,安装需要 JDK 11 以上
  • ES 7.2.1,内置了 JDK 12

下载后解压

创建启动用户 es,不能使用root启动

adduser es

chown -R es.es ./elasticsearch-7.6.0

su es  如果出现  bash-4.2$

执行:cp -a /etc/skel/.bashrc /home/es

启动:./bin/elasticsearch    (当你看到如下图标识说明启动成功了)

二  安装head插件

插件下载地址:https://github.com/mobz/elasticsearch-head

解压

cd  cd elasticsearch-head-master

启动elasticsearch-head需要npm安装nodejs

node -v   (如果未找到命令)

官网下载地址 : https://nodejs.org/en/download/

wget https://nodejs.org/dist/v9.3.0/node-v9.3.0-linux-x64.tar.xz

解压

xz -d node-v9.3.0-linux-x64.tar.xz

tar -xf node-v9.3.0-linux-x64.tar

cd node-v9.3.0-linux-x64/bin/

ls

创建软连接

ln -s /home/node-v9.3.0-linux-x64/bin/node /usr/bin/node

ln -s /home/node-v9.3.0-linux-x64/bin/npm /usr/bin/npm

ln -s /home/node-v9.3.0-linux-x64/bin/npx /usr/bin/npx

然后切换到head插件目录 安装

安装 npm install

如果报错上图错误执行:npm install phantomjs-prebuilt@2.1.14 --ignore-scripts

启动:npm run start

启动后注意你的防火墙如果开启的要开启你的9100端口,不然只能本机访问

1、安装firewalld
root执行 # yum install firewalld firewall-config

2、运行、停止、禁用firewalld
启动:# systemctl start firewalld
查看状态:# systemctl status firewalld 或者 firewall-cmd --state
停止:# systemctl disable firewalld

禁用:# systemctl stop firewalld

3、firewalld规则添加
查看所有打开的端口
firewall-cmd --zone=public --list-ports
添加一个端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
删除一个端口
Firewall-cmd --zone=public --remove-port=80/tcp --permanent
更新防火墙规则
firewall-cmd --reload

ok 访问成功,但是head插件还没链接到elasticsearch,是因为es和head是属于两个独立的进程,需要配置跨域访问

vi es/config/elasticsearch.yml

添加 

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

network.host: 0.0.0.0 

修改 es7内存 find / -type f -name 'jvm.options'

 当 network.host 设置为  0.0.0.0 的时候 es会启动线上模式,检测会更加严格,常见错误

 1  2  3 错误

ulimit -Hn
ulimit -Sn

vi /etc/security/limits.conf   加入下面内容  (修改后重启centos生效)

*               soft    nproc           4096
*               hard    nproc           4096
*               soft    nofile          65536
*               hard    nofile          65536

vi /etc/sysctl.conf   追加   vm.max_map_count = 262144    sysctl -p 生效

错误 4 修改 elasticsearch.yml文件追加  cluster.initial_master_nodes: ["master"]  告诉es你现在有几个节点

启动   http://192.168.255.129:9100/

 三  安装 IK 分词

1.下载或编译

启动项有 ik 应该就没问题了,确认还得具体测试分词效果(这里不展示如何创建索引添加mappings 测试分词,可百度) 

四  搭建分布式elasticsearch集群

把你的es安装包和ik分词scp到另外两台服务器按照上面步骤解压安装

elasticserach.yml 文件配置详解

cluster.name: ESES集群名称,同一个集群内的所有节点集群名称必须保持一致
node.name: slave2ES集群内的节点名称,同一个集群内的节点名称要具备唯一性
node.master: true允许节点是否可以成为一个master节点,ES是默认集群中的第一台机器成为master,如果这台机器停止就会重新选举
node.data: false允许该节点存储索引数据(默认开启)
path.data:ES是搜索引擎,会创建文档,建立索引,此路径是索引的存放目录.可以指定多个存储位置
path.logs:elasticsearch专门的日志存储位置
bootstrap.memory_lock: true在ES运行起来后锁定ES所能使用的堆内存大小,锁定内存大小一般为可用内存的一半左右;锁定内存后就不会使用交换分区。如果不打开此项,当系统物理内存空间不足,ES将使用交换分区,ES如果使用交换分区,那么ES的性能将会变得很差
network.host: 0.0.0.0es的HTTP端口和集群通信端口就会监听在此地址上
network.tcp.no_delay: true是否启用tcp无延迟,true为启用tcp不延迟,默认为false启用tcp延迟
truenetwork.tcp.keep_alive: true是否启用TCP保持活动状态,默认为true
network.tcp.reuse_address: true是否应该重复使用地址。默认true,在Windows机器上默认为false
network.tcp.send_buffer_size: 128mbtcp发送缓冲区大小,默认不设置
network.tcp.receive_buffer_size: 128mbtcp接收缓冲区大小,默认不设置
transport.tcp.port: 9301设置集群节点通信的TCP端口,默认就是9300
transport.tcp.compress: true设置是否压缩TCP传输时的数据,默认为false
http.max_content_length: 200mb设置http请求内容的最大容量,默认是100mb
http.cors.enabled: true是否开启跨域访问
http.cors.allow-origin: "*"开启跨域访问后的地址限制,*表示无限制
http.port: 9201定义ES对外调用的http端口,默认是9200
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]在Elasticsearch7.0版本已被移除,配置错误。写入候选主节点的设备地址,来开启服务时就可以被选为主节点。默认主机列表只有127.0.0.1和IPV6的本机回环地址。上面是书写格式,discover意思为发现,zen是判定集群成员的协议,unicast是单播的意思,ES5.0版本之后只支持单播的方式来进行集群间的通信,hosts为主机
discovery.zen.minimum_master_nodes: 2在Elasticsearch7.0版本已被移除,配置无效,为了避免脑裂,集群的最少节点数量为,集群的总节点数量除以2加一
discovery.zen.fd.ping_timeout: 120s在Elasticsearch7.0版本已被移除,配置无效。探测超时时间,默认是3秒,我们这里填120秒是为了防止网络不好的时候ES集群发生脑裂现象
discovery.zen.fd.ping_retries: 6在Elasticsearch7.0版本已被移除,配置无效。探测次数,如果每次探测90秒,连续探测超过六次,则认为节点该节点已脱离集群,默认为3次
discovery.zen.fd.ping_interval: 15s在Elasticsearch7.0版本已被移除,配置无效。节点每隔15秒向master发送一次心跳,证明自己和master还存活,默认为1秒太频繁
discovery.seed_hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]Elasticsearch7新增参数,写入候选主节点的设备地址,来开启服务时就可以被选为主节点,由discovery.zen.ping.unicast.hosts:参数改变而来
cluster.initial_master_nodes: ["127.0.0.1:9301","127.0.0.1:9302"]Elasticsearch7新增参数,写入候选主节点的设备地址,来开启服务时就可以被选为主节点
cluster.fault_detection.leader_check.interval: 15sElasticsearch7新增参数,设置每个节点在选中的主节点的检查之间等待的时间。默认为1秒
discovery.cluster_formation_warning_timeout: 30sElasticsearch7新增参数,启动后30秒内,如果集群未形成,那么将会记录一条警告信息,警告信息未master not fount开始,默认为10秒
cluster.join.timeout: 30sElasticsearch7新增参数,节点发送请求加入集群后,在认为请求失败后,再次发送请求的等待时间,默认为60秒
cluster.publish.timeout: 90sElasticsearch7新增参数,设置主节点等待每个集群状态完全更新后发布到所有节点的时间,默认为30秒
cluster.routing.allocation.cluster_concurrent_rebalance: 32集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.node_concurrent_recoveries: 32添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_initial_primaries_recoveries: 32初始化数据恢复时,并发恢复线程的个数,默认4个

主节点配置

#开启跨域
http.cors.enabled: true
http.cors.allow-origin: "*"

cluster.name: amok
node.name: master
node.master: true
#是否压缩
transport.tcp.compress: true

network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["192.168.255.129","192.168.255.134","192.168.255.135"]
cluster.initial_master_nodes: ["192.168.255.129"]

从节点1

cluster.name: amok
node.name: slave1
node.master: false
http.port: 9200
transport.tcp.port: 9300
#是否压缩
transport.tcp.compress: true
network.host: 0.0.0.0
cluster.initial_master_nodes: ["192.168.255.129"]
discovery.seed_hosts: ["192.168.255.129","192.168.255.134","192.168.255.135"]

从节点2

cluster.name: amok
node.name: slave2
node.master: false
http.port: 9200
transport.tcp.port: 9300
#是否压缩
transport.tcp.compress: true
network.host: 0.0.0.0
cluster.initial_master_nodes: ["192.168.255.129"]
discovery.seed_hosts: ["192.168.255.129","192.168.255.134","192.168.255.135"]

transport.tcp.port: 9300  端口防火墙也要开启不然 从节点链接不到主节点 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值