1.安装前端界面查看集群
[root@server1 ~]# ls
elasticsearch-6.6.1.rpm jdk-8u181-linux-x64.rpm
elasticsearch-head-master.zip nodejs-9.11.2-1nodesource.x86_64.rpm
[root@server1 ~]# unzip elasticsearch-head-master.zip
[root@server1 ~]# rpm -ivh nodejs-9.11.2-1nodesource.x86_64.rpm
2.配置npm并下载phantomjs安装包
确保虚拟机可以上网并配置镜像源
[root@server1 ~]# yum install -y bzip2
[root@server1 ~]# tar jxf phantomjs-2.1.1-linux-x86_64.tar.bz2
[root@server1 ~]# cd phantomjs-2.1.1-linux-x86_64/bin
[root@server1 bin]# cp phantomjs /usr/local/bin/
3.执行npm安装
[root@server1 ~]# cd elasticsearch-head-master
[root@server1 elasticsearch-head-master]# npm install
4.编辑配置文件要指向的web界面ip
[root@server1 elasticsearch-head-master]# vim _site/app.js
[root@server1 elasticsearch-head-master]# vim /etc/elasticsearch/elasticsearch.yml
4360 this.base_uri = this.config.base_uri || this.prefs.get(“app-base_uri”) || “http:/ /172.25.32.1:9200”;
5.编辑elasticsearch配置文件实现远程登陆
[root@server1 elasticsearch-head-master]# vim /etc/elasticsearch/elasticsearch.yml
64 http.cors.enabled: true
65 http.cors.allow-origin: “*”
[root@server1 elasticsearch-head-master]# systemctl restart elasticsearch.service
6.开启web界面将其打入后台并查看其端口
[root@server1 elasticsearch-head-master]# npm run start &
[root@server1 elasticsearch-head-master]# netstat -antlp
- 网页查看
添加节点
1.修改server1的配置文件
[root@server1 elasticsearch-head-master]# vim /etc/elasticsearch/elasticsearch.yml
71 discovery.zen.ping.unicast.hosts: [“server1”, “server2”,“server3”]
2.将elasticsearch的安装包scp到server2和server3上,并且将系统的limits.conf配置文件scp到server2和server3上
[root@server1 ~]# scp jdk-8u121-linux-x64.rpm server2:
[root@server1 ~]# scp jdk-8u121-linux-x64.rpm server3:
[root@server1 ~]# scp elasticsearch-6.6.1.rpm server2:
[root@server1 ~]# scp elasticsearch-6.6.1.rpm server3:
[root@server1 ~]# scp /etc/security/limits.conf server2:/etc/security/
[root@server1 ~]# scp /etc/security/limits.conf server3:/etc/security
[root@server1 ~]# scp /usr/lib/systemd/system/elasticsearch.service server2:/usr/lib/systemd/system/
[root@server1 ~]# scp /usr/lib/systemd/system/elasticsearch.service server3:/usr/lib/systemd/system/
[root@server1 ~]# scp /etc/elasticsearch/elasticsearch.yml server2:/etc/elasticsearch/
[root@server1 ~]# scp /etc/elasticsearch/elasticsearch.yml server3:/etc/elasticsearch/
4.在server2及其server3上安装elsticsearch并且配置相应的限制
以server2为例,server2与server3只需要修改相应的主机名与ip即可
5.关闭交换分区
[root@server2 ~]# swapoff -a
[root@server2 ~]# vim /etc/fstab
#/dev/mapper/rhel-swap swap swap defaults 0 0
在停止server1的工作后,会从工作节点随机选择一个节点作为主节点来进行工作,这个选择是随机的,即使在server1启动后也不会对之后新产生的主节点有影响,server1会作为从节点加入集群。
- 工作时可以设定节点工作状态
[root@server1 ~]# vim /etc/elasticsearch/elasticsearch.yml
node.master: true##主节点
node.data: false##不存储数据
[root@server2 ~]# vim /etc/elasticsearch/elasticsearch.yml
node.master: false##不做主节点
node.data: true##只做数据节点
[root@server3 ~]# vim /etc/elasticsearch/elasticsearch.yml
node.master: false##不做主节点
node.data: true##只做数据节点
两个状态都为false表示只做查询
node.master: false##不做主节点
node.data: false##只做数据节点
可以看到,数据存放在server2与server3上,而server1不会存储任何数据。