虚拟机工具:VirtualBox
Ubuntu 镜像:ubuntu-16.04.2-server-amd64.iso 下载地址(http://101.96.8.142/releases.ubuntu.com/16.04.2/ubuntu-16.04.2-server-amd64.iso)
Elasticsearch 版本:2.4.1 下载地址(https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.1/elasticsearch-2.4.1.tar.gz)
JDK:1.8 +
配置虚拟机和网络
- 打开 VirtualBox 安装 Ubuntu镜像 (步骤略)
- 设置虚拟机上网方式为“桥接网卡”,这样,虚拟机可以通过物理机上网。,如图:
- 为了区分多台虚拟机,我将虚拟机重命名,如第一台:ubuntu01-192.168.6.4 ,如图:
- 将虚拟机自动获取ip改成静态ip。 打开虚拟机,输入用户名,密码。输入命令ifconfig获取自动获取ip
- 修改成静态ip。输入命令:sudo vi /etc/network/interfaces 输入密码,进入修改页面,其中:gateway 和 dsn-nameservers是必须要配置的,dsn-nameservers不配的话上不了外网。修改如图:
- 保存并重启网络,输入:sudo /etc/init.d/networking restart
- 复制虚拟机镜像。
- 其中,副本名称改成新的虚拟机名称
- 将下载好的elasticsearch-2.4.1.tar.gz 解压。(命令:tar -zxvf elasticsearch-2.4.1.tar.gz)
- elasticsearch为了防止集群发生脑裂,elasticsearch要求节点只少2n+1台,我搭建了三台。
- 分别打开三台虚拟机,进入elasticsearch-2.4.1/config 下,编辑elasticsearch.yml。
cluster.name: my-application //cluster.name:为集群名称,同一集群cluster.name必须一样,加入新节点时可以自动加入该集群node.name: node-1 //节点名称 不同几点名称要不一致network.host: 192.168.6.4 //该节点iphttp.port: 9200 //该节点端口,不同节点端口要不一致discovery.zen.ping.unicast.hosts: ["192.168.6.4", "192.168.6.7","192.168.6.8"] //设置新节点被启动时能够发现的主节点列表(主要用于不同网段机器连接)
ubuntu02-192.168.6.7节点cluster.name: my-application
node.name: node-2
network.host: 192.168.6.7
http.port: 19200
discovery.zen.ping.unicast.hosts: ["192.168.6.4", "192.168.6.7","192.168.6.8"]
ubuntu03-192.168.6.8节点cluster.name: my-application
node.name: node-3
network.host: 192.168.6.8
http.port: 29200
discovery.zen.ping.unicast.hosts: ["192.168.6.4", "192.168.6.7","192.168.6.8"]
4. 启动每台elasticsearch , 进入 elasticsearch/bin下,执行./elasticsearch -d
5. ubuntu01-192.168.6.4节点执行curl -XGET "http://192.168.6.4:9200"
返回:
{
"name" : "node-1",
"cluster_name" : "my-application",
"cluster_uuid" : "MIRxeE5ZTGe1fhf3HbeHHQ",
"version" : {
"number" : "2.4.1",
"build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",
"build_timestamp" : "2016-09-27T18:57:55Z",
"build_snapshot" : false,
"lucene_version" : "5.5.2"
},
"tagline" : "You Know, for Search"
}
ubuntu02-192.168.6.7节点执行curl -XGET "http://192.168.6.7:19200"
返回:
{
"name" : "node-2",
"cluster_name" : "my-application",
"cluster_uuid" : "MIRxeE5ZTGe1fhf3HbeHHQ",
"version" : {
"number" : "2.4.1",
"build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",
"build_timestamp" : "2016-09-27T18:57:55Z",
"build_snapshot" : false,
"lucene_version" : "5.5.2"
},
"tagline" : "You Know, for Search"
}
ubuntu01-192.168.6.8节点执行curl -XGET "http://192.168.6.8:29200"
返回:
{
"name" : "node-3",
"cluster_name" : "my-application",
"cluster_uuid" : "MIRxeE5ZTGe1fhf3HbeHHQ",
"version" : {
"number" : "2.4.1",
"build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",
"build_timestamp" : "2016-09-27T18:57:55Z",
"build_snapshot" : false,
"lucene_version" : "5.5.2"
},
"tagline" : "You Know, for Search"
}
说明三个节点es可以正常运行。
6. 安装es集群管理插件Elasticsearch-head。
进入其中一台虚拟机,如ubuntu01-192.168.6.4节点,进入elasticsearch/bin下,执行./plugin install mobz/elasticsearch-head
按装完成,访问http://192.168.6.4:9200/_plugin/head/
看到如下:
7. 或安装插件kopf,进入elasticsearch/bin下,执行./plugin install lmenezes/elasticsearch-kopf ,访问http://192.168.6.4:9200/_plugin/kopf 会更美观一些。
8. 试一下分片。
PUT /http://192.168.6.4:9200/fristindex
{
"settings": {
"number_of_shards": 3, //分片个数
"number_of_replicas": 2 // 每个分片对应的备份数量
}
}
返回
{
"acknowledged": true
}刷新http://192.168.6.4:9200/_plugin/head/ 便可以看到效果
9. 添加新的节点 只需要定义 cluster.name,node.name,network.host,http.port四个属性即可,(discovery.zen.ping.unicast.hosts: ["192.168.6.4", "192.168.6.7","192.168.6.8"] 保持不变)。启动es刷新http://192.168.6.4:9200/_plugin/head/ 便可以看到效果
写博客真是个累活,累死我了~~~~
本文详细介绍了如何使用VirtualBox和Ubuntu 16.04搭建Elasticsearch 2.4.1集群,包括配置虚拟机网络、安装Elasticsearch、配置集群参数、安装管理插件等关键步骤。
3483

被折叠的 条评论
为什么被折叠?



