服务器1 :192.168.2.89node
服务器2 :192.168.2.90linux
服务器3 :192.168.2.91git
[root@localhost soft]# pwd /root/soft [root@localhost soft]# mkdir -p ES/config [root@localhost soft]# cd ES [root@localhost ES]# mkdir data [root@localhost ES]# mkdir plugins [root@localhost ES]# cd ES/config/ [root@localhost config]# touch es.yml [root@localhost ES]# firewall-cmd --add-port=9300/tcp success [root@localhost ES]# firewall-cmd --add-port=9301/tcp success [root@localhost ES]# firewall-cmd --add-port=9302/tcp success 别忘了从新加载下防火墙 =============================我这边暴露端口采用的linux的宝塔面板==============
描述:在root文件夹下,新建soft文件夹,在soft文件夹下建ES文件夹,在ES文件夹下建data,config,plugins 三个文件夹github
es.yml文件内容以下,copy进去便可,copy到这台机器ES/config/es.yml中docker
#集群名 cluster.name: elasticsearch-cluster #当前机器下的es节点名字 node.name: es-node1 #指绑定这台机器的任何一个ip network.bind_host: 0.0.0.0 #当前机器的ip(这样设置,可让别的机器能够经过这个ip来和这个es通信,不设置,别的机器不能经过这个ip和这台机器上的es通信) network.publish_host: 192.168.2.89 #设置对外服务的http端口,默认为9200 http.port: 9200 #设置节点之间交互的tcp端口,默认是9300 transport.tcp.port: 9300 #是否容许跨域REST请求 http.cors.enabled: true #容许 REST 请求来自何处 http.cors.allow-origin: "*" #节点角色设置 node.master: true node.data: true #有成为主节点资格的节点列表 discovery.zen.ping.unicast.hosts: ["192.168.2.89:9300","192.168.2.90:9300","192.168.2.91:9300"] #集群中一直正常运行的,有成为master节点资格的最少节点数(默认为1) # (totalnumber of master-eligible nodes / 2 + 1) discovery.zen.minimum_master_nodes: 2
下载ik分词器,版本要和es版本一致,这里es和ik都是5.6.7的。包括kibana也是5.6.7vim
ik分词器链接:https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v5.6.7centos
下载 elasticsearch-analysis-ik-5.6.7.zip 到桌面,在桌面上新建文件夹 ik ,把 elasticsearch-analysis-ik-5.6.7.zip 解压到ik跨域
文件夹里,并删除 .zip文件,把ik文件夹上传到 服务器上的ES/plugins/文件下便可,其余不须要作什么浏览器
固然你的目录结构和个人不同也行,只要你本身改的清楚就行服务器
在centos窗口中,修改配置sysctl.conf
vim /etc/sysctl.conf
加入以下内容:
vm.max_map_count=262144
保存退出,在执行以下命令,让其生效
sysctl -p
机器1 192.168.2.89 的es.yml
#集群名 cluster.name: elasticsearch-cluster #当前机器下的es节点名字 node.name: es-node1 #指绑定这台机器的任何一个ip network.bind_host: 0.0.0.0 #当前机器的ip(这样设置,可让别的机器能够经过这个ip来和这个es通信,不设置,别的机器不能经过这个ip和这台机器上的es通信) network.publish_host: 192.168.2.89 #设置对外服务的http端口,默认为9200 http.port: 9200 #设置节点之间交互的tcp端口,默认是9300 transport.tcp.port: 9300 #是否容许跨域REST请求 http.cors.enabled: true #容许 REST 请求来自何处 http.cors.allow-origin: "*" #节点角色设置 node.master: true node.data: true #有成为主节点资格的节点列表 discovery.zen.ping.unicast.hosts: ["192.168.2.89:9300","192.168.2.90:9300","192.168.2.91:9300"] #集群中一直正常运行的,有成为master节点资格的最少节点数(默认为1) # (totalnumber of master-eligible nodes / 2 + 1) discovery.zen.minimum_master_nodes: 2
机器二 192.168.2.90 机器下的es.yml文件,其实就是 network.publish_host: 192.168.2.90 ,和node.name (node节点名字)不同而已
#集群名 cluster.name: elasticsearch-cluster #当前机器下的es节点名字 node.name: es-node2 #指绑定这台机器的任何一个ip network.bind_host: 0.0.0.0 #当前机器的ip(这样设置,可让别的机器能够经过这个ip来和这个es通信,不设置,别的机器不能经过这个ip和这台机器上的es通信) network.publish_host: 192.168.2.90 #设置对外服务的http端口,默认为9200 http.port: 9200 #设置节点之间交互的tcp端口,默认是9300 transport.tcp.port: 9300 #是否容许跨域REST请求 http.cors.enabled: true #容许 REST 请求来自何处 http.cors.allow-origin: "*" #节点角色设置 node.master: true node.data: true #有成为主节点资格的节点列表 discovery.zen.ping.unicast.hosts: ["192.168.2.89:9300","192.168.2.90:9300","192.168.2.91:9300"] #集群中一直正常运行的,有成为master节点资格的最少节点数(默认为1) # (totalnumber of master-eligible nodes / 2 + 1) discovery.zen.minimum_master_nodes: 2
机器三 192.168.2.91 下的es.yml文件
#集群名 cluster.name: elasticsearch-cluster #当前机器下的es节点名字 node.name: es-node3 #指绑定这台机器的任何一个ip network.bind_host: 0.0.0.0 #当前机器的ip(这样设置,可让别的机器能够经过这个ip来和这个es通信,不设置,别的机器不能经过这个ip和这台机器上的es通信) network.publish_host: 192.168.2.91 #设置对外服务的http端口,默认为9200 http.port: 9200 #设置节点之间交互的tcp端口,默认是9300 transport.tcp.port: 9300 #是否容许跨域REST请求 http.cors.enabled: true #容许 REST 请求来自何处 http.cors.allow-origin: "*" #节点角色设置 node.master: true node.data: true #有成为主节点资格的节点列表 discovery.zen.ping.unicast.hosts: ["192.168.2.89:9300","192.168.2.90:9300","192.168.2.91:9300"] #集群中一直正常运行的,有成为master节点资格的最少节点数(默认为1) # (totalnumber of master-eligible nodes / 2 + 1) discovery.zen.minimum_master_nodes: 2
拉去镜像命令:(三台机器都同样)
docker pull elasticsearch:5.6.7
启动镜像命令:
机器一启动es命令:
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /root/soft/ES/config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /root/soft/ES/data:/usr/share/elasticsearch/data -v /root/soft/ES/plugins:/usr/share/elasticsearch/plugins --name ES01 elasticsearch:5.6.7
机器二启动es命令:
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /root/soft/ES/config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /root/soft/ES/data:/usr/share/elasticsearch/data -v /root/soft/ES/plugins:/usr/share/elasticsearch/plugins --name ES02 elasticsearch:5.6.7
机器三启动es命令:
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /root/soft/ES/config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /root/soft/ES/data:/usr/share/elasticsearch/data -v /root/soft/ES/plugins:/usr/share/elasticsearch/plugins --name ES03 elasticsearch:5.6.7
命令解释:
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" :设置jvm的初始内存和最大内存,我这里内存不够,因此设置小了,你能够根据你本身的状况设置
-d :后台i启动
-p 9200:9200 -p 9300:9300 :docker容器和宿主机的端口映射
-v /root/soft/ES/config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml:-v 是外部挂载命令符,
这个意思是:把root/soft/ES/config/es.yml 挂在到es的docker容器里,替代es容器里本来的elasticsearch.yml
-v /root/soft/ES/data:/usr/share/elasticsearch/data :意思同上,就是把es容器的数据存到/root/soft/ES/data里
-v /root/soft/ES/plugins:/usr/share/elasticsearch/plugins :意思同上,就是把/root/soft/ES/plugins 文件夹 替代es的docker容器本来的plugins,这里面能够放一下es的插件,好比 ik 分析器,等,这样作是为了删除docker容器时,不影响插件,而不是向其余的,到docker容器里去装插件,要是docker容器删了,里面的插件就没了,每次都要进容器里面装插件。外部挂在,不存在这样的问题,删了就删了,从新run一个就像,data,config和plugins都在外面。
--name ES01 elasticsearch:5.6.7 启动的这个容器名字是 ES01 ,elasticsearch:5.6.7是启动的es版本
启动后能够在浏览器中测试 ip:port便可
如:http://192.168.2.89:9200/ ,http://192.168.2.90:9200/ ,http://192.168.2.91:9200/
6 下面安装head插件和kibana,套路,拉取对象,启动镜像,便可
head插件:
docker pull mobz/elasticsearch-head:5 docker run -d -p 9100:9100 --name es-manager mobz/elasticsearch-head:5
浏览器访问:http://192.168.2.89:9100/
docker pull kibana:5.6.7 docker run --name kibana -e ELASTICSEARCH_URL=http://192.168.2.89:9200 -p 5601:5601 -d kibana:5.6.7
到此结束!