es安装

ES搜索引擎学习之环境搭建


1.下载ElasticSearch6.2.4

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz

2.解压文件

tar -zxvf elasticsearch-6.2.4.tar.gz

3.重新命名

mv elasticsearch-6.2.4 /usr/local/elastic/elasticsearch

4.创建数据存放路径

mkdir /usr/local/elastic/elasticsearch/data

5.创建日志存放路径(如已存在不用创建)

mkdir /usr/local/elastic/elasticsearch/logs

6.创建用户并授权(因为es不能root用户运行)

useradd es

chown -R es:es /usr/local/elastic/elasticsearch

7. 修改es配置

#集群的名称

cluster.name: es6.2.4

#节点名称,其余两个节点分别为node-2 和node-3

node.name: node-1

#指定该节点是否有资格被选举成为master节点,默认是true,es是默认集群中的 第一台机器为master,如果这台机挂了就会重新选举master

node.master: true

#允许该节点存储数据(默认开启)

node.data: true

#索引数据的存储路径

path.data: /usr/local/elastic/elasticsearch/data

#日志文件的存储路径

path.logs: /usr/local/elastic/elasticsearch/logs

#设置为true来锁住内存。因为内存交换到磁盘对服务器性能来说是致命的,当jvm 开始swapping时es的效率会降低,所以要保证它不swap

bootstrap.memory_lock: true

#绑定的ip地址 这里所有都可访问

network.host: 0.0.0.0

#设置对外服务的http端口,默认为9200

http.port: 9200

# 设置节点间交互的tcp端口,默认是9300

transport.tcp.port: 9300

#Elasticsearch将绑定到可用的环回地址,并将扫描端口9300到9305以尝试连接到 运行在同一台服务器上的其他节点。

#这提供了自动集群体验,而无需进行任何配置。数组设置或逗号分隔的设置。每 个值的形式应该是host:port或host

#(如果没有设置,port默认设置会transport.profiles.default.port 回落到 transport.tcp.port)。

#请注意,IPv6主机必须放在括号内。默认为127.0.0.1, [::1]

discovery.zen.ping.unicast.hosts: ["ip:9300", "ip:9300", "ip:9300"]

#如果没有这种设置,遭受网络故障的集群就有可能将集群分成两个独立的集群 - 分裂的大脑 - 这将导致数据丢失

discovery.zen.minimum_master_nodes: 3

# 增加新的参数,这样head插件可以访问es,解决跨域访问问题

http.cors.enabled: true

http.cors.allow-origin: "*"

http.cors.allow-credentials: true

8. 调整jvm内存

vim /usr/local/elk/elasticsearch/config/jvm.options

#默认是1g官方建议对jvm进行一些修改,不然很容易出现OOM,参考官网改参数配置 最好不要超过内存的50%

-Xms1g

-Xmx1g

9. 分别启动各个节点的es

/usr/local/elastic/elasticsearch/bin/elasticsearch -d

注意:

查看进程是否启动

ps -ef|grep elasticsearch

发现并没有启动,什么原因呢?查看一下日志在我们配置的日志路径下:

cd ../logs

第一个坑:日志文件会以集群名称命名,查看es6.2.log文件,日志报以下异常:

[ERROR][o.e.b.Bootstrap ] [node-1] node validation exception

[3] bootstrap checks failed

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

[2]: memory locking requested for elasticsearch process but memory is not locked

[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决方法:

切回root用户su - root,修改配置

① vim /etc/security/limits.conf

soft nofile 65536

* hard nofile 65536

* soft nproc 2048

* hard nproc 4096

#我选择锁住swapping因此需要在这个配置文件下再增加两行代码

es soft memlock unlimited

es hard memlock unlimited

打开: vim /etc/sysctl.conf


执行一句命令sysctl -p使系统配置生效(使用root用户)。

Es不能使用root启动

10. 再次重启Elasticsearch

 

安装elasticsearch-head
1.安装nodejs和rpm

su - root

yum install epel-release

yum install nodejs npm

2.下载并安装elasticsearch-head

git clone https://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head

npm install

npm run start

3.修改elasticsearch参数,以便于head插件访问es

1.在elasticsearch下的elasticsearch.yml下新增一下两行: http.cors.enabled: true

http.cors.allow-origin: "*"

2.重启es

4.修改es-head的localhost地址

cd ./elasticsearch-head

vim Gruntfile.js

Add hostname

connect: {

server: {

options: {

hostname: '0.0.0.0',

port: 9100,

base: '.',

keepalive: true

}

}

}

5.修改head连接地址

1.cd ./elasticsearch-head #(elasticsearch-head源码文件夹)

2.vim ./_site/app.js

3.将localhost修改为ESdeIP地址 修改前:this.base_uri = this.config.base_uri; 修改后: this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://you ip address:9200";

6. 启动elasticsearch-head

cd elasticsearch-head(elasticsearch-head源码目录)

./node_modules/grunt/bin/grunt server

 

1、启动必须非root

2、多次启动会报错

3、后台启动

/usr/local/elastic/elasticsearch/bin/elasticsearch -d

4、是否启动查看

ps -ef | grep elasticsearch

5、启动日志查看

elasticsearch.log

posted @ 2019-07-01 19:03  zhaojq  阅读(1320)  评论(0编辑  收藏  举报