Elasticsearch集群安装部署
Elasticsearch集群安装部署
1.系统环境说明
目前使用的系统环境为Centos Linux release 7.4.1708 (core)
,linux
版本的内核Linux version 3.10.0-693.2.2e17.x86_64
.
机器地址:172.31.178.92,172.31.178.93
2.安装配置JDK 1.8
2.1 jdk下载并解压缩
[root@UDC-1 jdk]# pwd
/opt/jdk
[root@UDC-1 jdk]# tar -zxvf jdk-8u151-linux-x64.tar.gz
2.2 编辑环境变量
[[email protected]1 jdk]# vim /etc/profile
export JAVA_HOME=/opt/jdk/jdk1.8
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib/tool.jar:$JAVA_HOME/lib/dt.jar
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
[[email protected]1 jdk]# source /etc/profile
2.3 查看JDK版本
[root@UDC-1 jdk]# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
3.Elasticsearch下载安装
3.1 下载、解压包
使用wget下载
[[email protected]UDC-1 data]# pwd
/data
[[email protected]UDC-1 data]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.tar.gz
[[email protected]UDC-1 data]# tar -zxvf elasticsearch-6.3.2.tar.gz
[[email protected]UDC-1 data]# rm -rf elasticsearch-6.3.2.tar.gz
[[email protected]UDC-1 data]# mv elasticsearch-6.3.2/ elasticsearch
3.2 创建用户、授权、切换用户
从5.0开始,Elasticsearch安全级别提高了,不允许采用root账户启动,所以添加一个用户。
[root@UDC-1 data]# useradd es
[root@UDC-1 data]# passwd es
Changing password for user es.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@UDC-1 data]# usermod -G es es
[root@UDC-1 data]# chown -R es:es elasticsearch/
[root@UDC-1 data]# su es
3.3 Elasticsearch 配置
-
修改elasticsearch.yml
[[email protected]1 elasticsearch]$ vim config/elasticsearch.yml cluster.name: my-application node.name: node-1 network.host: 0.0.0.0 http.port: 9200 discovery.zen.ping.unicast.hosts: ["172.31.178.92", "172.31.178.93"] discovery.zen.minimum_master_nodes: 1 #末尾添加以下三行是解决跨域问题,为后面安装head插件做准备 http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-credentials: true
-
修改/etc/sysctl.conf
切换到root用户
[[email protected] elasticsearch]# vim /etc/sysctl.conf
添加如下内容
vm.max_map_count=262144
用命令sysctl -p生效
[[email protected] elasticsearch]# sysctl -p
-
修改文件/etc/security/limits.conf
[[email protected] elasticsearch]# vim /etc/security/limits.conf
添加如下内容
* soft nofile 65536 * hard nofile 65536 * soft nproc 2048 * soft nproc 4096
-
ElasticSearch启动
-d是后台启动
[[email protected] elasticsearch]$ bin/elasticsearch -d
-
查询
-
ElasticSearch停止
[es@UDC-1 elasticsearch-head-master]$ jps 32592 Jps 32385 Elasticsearch [es@UDC-1 elasticsearch-head-master]$ kill -9 32385
两台机器均做上面的操作,唯一注意配置文件中node.name修改node-2 即可
然后分别启动两台台机器 ./bin/elasticsearch -d 查看配置路径的日志信息,启动成功!
3.4 安装ik分词
每台机器安装ik后重启
[[email protected] elasticsearch]$ ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.2/elasticsearch-analysis-ik-6.3.2.zip
注意:6.3.2为对应的Elasticsearch版本号。
3.5 head插件安装
我使用的是ES6.3版本,head插件可以单独部署,并远程连接ES服务器,通过REST API来处理交互。只需要在一台机器上安装head插件即可。
3.5.1 下载head插件并解压
[es@UDC-1 elasticsearch]$ wget https://github.com/mobz/elasticsearch-head/archive/master.zip
[es@UDC-1 elasticsearch]$ unzip master.zip
3.5.2 安装node
切换root用,安装node到/data目录
[root@UDC-1 data]# pwd
/data
[root@UDC-1 data]# wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.4.7-linux-x64.tar.gz
[root@UDC-1 data]# tar -zxvf node-v4.4.7-linux-x64.tar.gz
[root@UDC-1 data]# rm -rf node-v4.4.7-linux-x64.tar.gz
[root@UDC-1 data]# mv node-v4.4.7-linux-x64/ node
[root@UDC-1 data]# vim /etc/profile
export NODE_HOME=/data/node
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules
[root@UDC-1 data]# source /etc/profile
3.5.3 安装grunt
grunt是基于Node.js的项目构建工具,可以进行打包压缩、测试、执行等等的工作,head插件就是通过grunt启动.
[[email protected]UDC-1 data]$ cd /data/elasticsearch/elasticsearch-head-master/
[[email protected]UDC-1 elasticsearch-head-master]# npm install -g grunt-cli #执行后会在/data/node/lib生产node_modules文件夹
查看是否安装成功
[root@UDC-1 elasticsearch-head-master]# grunt -version
grunt-cli v1.3.0
3.5.4 修改head插件源码
- 修改服务器监听地址:Gruntfile.js。增加hostname:’*’
[[email protected] elasticsearch-head-master]# vim Gruntfile.js
connect: {
server: {
options: {
port: 9100,
base: '.',
keepalive: true,
hostname:'*'
}
}
-
修改连接地址:_site/app.js
将
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
中的localhost
换成47.104.191.52
(使用公网ip)[root@UDC-1 elasticsearch-head-master]# vim _site/app.js (function( app, i18n ) { var ui = app.ns("ui"); var services = app.ns("services"); app.App = ui.AbstractWidget.extend({ defaults: { base_uri: null }, init: function(parent) { this._super(); this.prefs = services.Preferences.instance(); this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://172.31.178.92:9200"; if( this.base_uri.charAt( this.base_uri.length - 1 ) !== "/" ) { // XHR request fails if the URL is not ending with a "/" this.base_uri += "/";
3.5.5 安装head依赖包
[root@UDC-1 elasticsearch-head-master]# su es
[es@UDC-1 elasticsearch-head-master]$ npm install
3.5.5 运行head
先启动es集群,在/data/elasticsearch/elasticsearch-head-master/
下启动grunt
[es@UDC-1 elasticsearch-head-master]$ grunt server
去浏览器查看地址:http://47.104.191.52:9100/
上一篇: laravel数据填充 --小丑
下一篇: C++ tab键实现自动补全输入功能
推荐阅读
-
在centos7下安装和部署java8和mysql
-
一张图讲解最少机器搭建FastDFS高可用分布式集群安装说明
-
Spark新手入门——2.Hadoop集群(伪分布模式)安装
-
Docker 简单部署 ElasticSearch的实现方法
-
Spring Cloud Alibaba | Nacos集群部署
-
Springboot 2.0.x 集成基于Centos7的Redis集群安装及配置
-
JAVAEE——宜立方商城06:Redis安装、数据类型和持久化方案、Redis集群分析与搭建、实现缓存和同步
-
elasticsearch安装head插件
-
Mysql基于Mysql Cluster+MysqlRouter的集群部署方案
-
阿里云服务器CentOS 6.3下快速安装部署 LAMP 、vsftpd 环境的方法