centos7下elasticsearch-6.2.4安装

本文详细介绍了在CentOS7系统中安装Elasticsearch-6.2.4的全过程,包括JDK环境配置、Elasticsearch下载与解压、创建非root用户、修改目录权限、配置Elasticsearch相关文件如elasticsearch.yml、sysctl.conf和limits.conf,以及启动、停止Elasticsearch的方法和常见错误解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

elasticsearch-6.2.4安装

1. jdk环境变量配置

自行百度,这里不再介绍安装

2. elasticsearch下载

官网下载elasticsearch
在这里插入图片描述

3. 解压elasticsearch

[root@master elasticsearch]# tar -zxvf elasticsearch-6.2.4.tar.gz

4. 创建用户

从5.0开始,ElasticSearch 安全级别提高了,不允许采用root帐号启动,所以我们要添加一个用户。

#创建bigdata 用户组
[root@master elasticsearch]# groupadd bigdata
#创建用户es
[root@master elasticsearch]# useradd es
#为es用户设置密码es(密码过段会提示)
[root@master elasticsearch]# passwd es
更改用户 es 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
#将es用户添加到bigdata组
[root@master elasticsearch]#  usermod -G bigdata es
#设置sudo权限
[root@master elasticsearch]# visudo
#找到root ALL=(ALL) ALL一行,添加es用户,如下
root    ALL=(ALL)       ALL
es      ALL=(ALL)       ALL
#切换用户
[root@master elasticsearch]# su es
[es@master elasticsearch]$ 

5. 修改目录权限

更改elasticsearch-6.2.4文件夹以及内部文件的所属用户为es, 用户组组为bigdata,-R表示逐级(N层目录)

#注意:如果想创建软连接建议先为源文件夹设置所属用户,并使用root用户授权后再切换到es用户下创建软连接操作

[root@master elasticsearch]# ll
总用量 255516
drwxr-xr-x.  8 root root      4096 4月  13 2018 elasticsearch-6.2.4
-rw-r--r--.  1 root root  29056810 5月  18 2019 elasticsearch-6.2.4.tar.gz
drwxrwxr-x. 12 1000 root      4096 4月  13 2018 kibana-6.2.4-linux-x86_64
-rw-r--r--.  1 root root  85348919 5月  18 2019 kibana-6.2.4-linux-x86_64.tar.gz
drwxr-xr-x. 11 root root      4096 5月  15 22:17 logstash-6.2.4
-rw-r--r--.  1 root root 147224408 5月  18 2019 logstash-6.2.4.tar.gz
[root@master elasticsearch]#  sudo chown -R es:bigdata elasticsearch-6.2.4
[root@master elasticsearch]#  sudo chown -R es:bigdata kibana-6.2.4-linux-x86_64
[root@master elasticsearch]#  sudo chown -R es:bigdata logstash-6.2.4
[root@master elasticsearch]# ll -h
总用量 250M
drwxr-xr-x.  8 es   bigdata 4.0K 4月  13 2018 elasticsearch-6.2.4
-rw-r--r--.  1 root root     28M 5月  18 2019 elasticsearch-6.2.4.tar.gz
drwxrwxr-x. 12 es   bigdata 4.0K 4月  13 2018 kibana-6.2.4-linux-x86_64
-rw-r--r--.  1 root root     82M 5月  18 2019 kibana-6.2.4-linux-x86_64.tar.gz
drwxr-xr-x. 11 es   bigdata 4.0K 5月  15 22:17 logstash-6.2.4
-rw-r--r--.  1 root root    141M 5月  18 2019 logstash-6.2.4.tar.gz
#创建软连接
[es@master elasticsearch]$ ln -s /home/bag/elasticsearch/elasticsearch-6.2.4 /home/soft/elasticsearch/elasticsearch
[es@master elasticsearch]$ ln -s /home/bag/elasticsearch/kibana-6.2.4-linux-x86_64 /home/soft/elasticsearch/kibana
[es@master elasticsearch]$ ln -s /home/bag/elasticsearch/logstash-6.2.4 /home/soft/elasticsearch/logstash
[es@master elasticsearch]$ 

6. ElasticSearch 配置

6.1 修改elasticsearch.yml

进入到elasticsearch的config目录下然后vim elasticsearch.yml

#修改network.host和http.port
#network.host为当前服务器ip
network.host: 192.168.221.5
http.port: 9200

6.2 修改/etc/sysctl.conf

切换到root用户

[root@master elasticsearch]# vim /etc/sysctl.conf
#添加如下内容
vm.max_map_count=655360

6.3 修改/etc/security/limits.conf

切换到root用户

#添加如下内容
* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 4096
# End of file

7. ElasticSearch启动与停止

7.1 注意切换到es用户下,进入到elasticsearch根目录下执行

[es@master bin]$ ./elasticsearch
[2019-05-15T23:04:30,213][INFO ][o.e.n.Node               ] [] initializing ...
[2019-05-15T23:04:30,326][INFO ][o.e.e.NodeEnvironment    ] [7UhuTlZ] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [36.8gb], net total_space [45.4gb], types [rootfs]
[2019-05-15T23:04:30,326][INFO ][o.e.e.NodeEnvironment    ] [7UhuTlZ] heap size [1007.3mb], compressed ordinary object pointers [true]
[2019-05-15T23:04:30,327][INFO ][o.e.n.Node               ] node name [7UhuTlZ] derived from node ID [7UhuTlZPRwW_eqHCeSDiyw]; set [node.name] to override
[2019-05-15T23:04:30,328][INFO ][o.e.n.Node               ] version[6.2.4], pid[14938], build[ccec39f/2018-04-12T20:37:28.497551Z], OS[Linux/3.10.0-957.10.1.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_73/25.73-b02]
[2019-05-15T23:04:30,
开源实时日志分析ELK平台能够完美的解决我们上述的问题,ELK由ElasticSearch、Logstash和Kiabana三个开源工具组成。 官方网站:https://www.elastic.co/products Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。 Logstash是一个完全开源的工具,他可以对你的日志进行收集、过滤,并将其存储供以后使用(如,搜索)。 Kibana 也是一个开源和免费的工具,它Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。 ELK下载:https://www.elastic.co/downloads/ ELK工作原理: ElasticSearch 配置ElasticSearch: 1 2 unzip elasticsearch-6.2.4.zip cd elasticsearch-6.2.4 然后编辑ES的配置文件: 1 vi config/elasticsearch.yml 修改以下配置项: 1 2 3 4 5 6 7 cluster.name=es_cluster node.name=node0 path.data=/tmp/elasticsearch/data path.logs=/tmp/elasticsearch/logs #当前hostname或IP,我这里是node1 network.host=node1 network.port=9200 其他的选项保持默认,然后启动ES: 1 nohup sh elasticsearch > nohup.log & 注意: 1.需要添加用户elk,ES不能以root用户进行启动 2.可能出现的错误: max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] 1 2 3 vi /etc/security/limits.conf elk soft nofile 819200 elk hard nofile 819200 max number of threads [1024] for user [work] likely too low, increase to at least [2048] 1 2 3 4 vi /etc/security/limits.d/90-nproc.conf * soft nproc 1024 #修改为: * soft nproc 2048 max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] 1 2 3 4 5 vi /etc/sysctl.conf #增加改行配置: vm.max_map_count=655360 #保存退出后,执行: sysctl -p 另外再配置ES的时候,threadpool.bulk.queue_size 已经变成了thread_pool.bulk.queue_size ,ES_HEAP_SIZE,ES_MAX_MEM等配置都变为ES_JAVA_OPTS这一配置项,如限制内存最大最小为1G: 1 export ES_JAVA_OPTS="-Xms1g -Xmx1g" 然后可以打开页面http://node1:9200/,将会看到以下内容:(我是通过外部访问虚拟机,因此为了简单没有配置host文件,直接用ip访问) Logstash 配置Logstash: 1 2 tar -zxvf logstash-6.2.4.tar.gz cd logstash-6.2.4 编写配置文件(名字和位置可以随意,这里我放在config目录下,取名为log_app.conf): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 vi config/log_app.config #以下为内容 input { file { path => "/usr/local/software/elk/app.log" start_position => "beginning" #从文件开始处读写 } # stdin {} #可以从标准输入读数据 } filter { #Only matched data are send to output. } output { # For detail config for elasticsearch as output, # See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html elasticsearch { action => "index" #The operation on ES hosts => "node1:9200" #ElasticSearch host, can be array. index => "applog" #The index to write data to. } } 其他的选项保持默认,然后启动Logstash: 1 2 # -f为指定配置文件 nohup sh ./bin/logstash -f ../config/log_app.config > nohup.log & 日志: Kibana 配置Kibana: 1 2 tar -zxvf kibana-6.2.4-linux-x86_64.tar.gz cd kibana-6.2.4-linux-x86_64 修改以下几项(由于是单机版的,因此host的值也可以使用localhost来代替,这里仅仅作为演示): 1 2 3 4 server.port: 5601 server.host: “node1” elasticsearch.url: http://node1:9200 kibana.index: “.kibana” 启动kibana: 1 nohup sh ./bin/kibana > nohup.log & 启动后界面: 然后需要创建index,步骤如下: ①点击左边iscover出现以下界面 ②按照注释配置,然后点击Next step,在第二页 选择@timestamp点击create创建 ③创建完成之后,可以看到以下一个界面,红框内是 自动生成的域,也可以理解为 跟数据库中的字段类似,其中有一个message字段,就是我们想要的日志信息。 ④再次点击Discover出现以下界面,可以看到默认搜索的是最后15分钟的日志,可以通过点击设置搜索的时间范围. ⑤可以点击右侧域的add设置需要显示的字段 添加完成之后,日志显示如下:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值