日志系列【分布式日志系统搭建Elasticsearch】

1.下载es安装包,并上传之服务器

地址:https://www.elastic.co/cn/downloads/elasticsearch

 2.解压

tar -zxvf elasticsearch-7.3.0-linux-x86_64.tar.gz

3.修改配置文件,单机只用修改红色部分即可

cd elasticsearch-7.3.0/config/
vim elasticsearch.yml
# 如果需要部署集群,集群需要同样的集群名
cluster.name: my-application

# 每个 node 的名字需要唯一
node.name: node-1

# 注意一定要是路径后面加上/var/lib/elasticsearch/nodes,要不然无法加入集群,单机不需要
# path.data: /var/lib/elasticsearch/nodes
# path.logs: /var/log/elasticsearch

# 配置服务器的内网地址,有文档配置的 0.0.0.0 或 localhost,但是后面出现了问题,暂未研究什么原因
network.host: 192.168.0.134

# 配置端口号,默认 9200
http.port: 9200

# 配置集群节点,多个服务器["node-1", "node-2"]
cluster.initial_master_nodes: ["node-1"]
# discovery.seed_hosts: ["192.168.0.146", "192.168.0.147", "192.168.0.148"]

# 解决跨域
http.cors.enabled: true
http.cors.allow-origin: "*"

4.启动es,其中/config/jvm.options 为启动的 JVM 配置,默认为-Xms1g -Xmx1g ….该配置根据自己的实际需求修改。 注意:启动时,不可以使用 root 用户。 进入 Elasticsearch 上级这里我们创建一个 elsearchuser 用户

#回退到/usr/local/app/elasticsearch-7.15.2的上一级目录
cd /usr/local/app
# 创建 elsearch 组
groupadd elsearch
useradd  elsearchuser(用户名) -g elsearch(组名) -p mima(密码)

# 给新创建用户文件夹执行权限
chown -R elsearchuser:elsearch /usr/local/app/elasticsearch-7.15.2

# 切换 elsearchuser 用户
su elsearchuser
cd /
elasticsearch-7.15.2/bin
#启动过程有点慢,耐心等待
sh elasticsearch &

 访问ip:9200,出现上图,即说明es搭建好了。

可能会遇到的问题

4.1.Native controller process has stopped - no new native processes can be started或者bootstrap checks failed

解决方案:切换到root用户

[root@localhost ~]# vim /etc/security/limits.conf
#在文件的末尾加上
* soft nofile 65536
* hard nofile 65536
[root@localhost security]# vi /etc/sysctl.conf 
vm.max_map_count = 655360
在文件最底部加上上面内容
[root@localhost security]# sysctl -p
查看是否填加成功
vm.max_map_count = 655360

修改完之后,关掉连接,重新连接服务器

4.2.Exception in thread “main” java.nio.file.AccessDeniedException: /usr/local/elasticsearch

解决方案:

# 给新创建用户文件夹执行权限
chown -R elsearchuser:elsearch /usr/local/app/elasticsearch-7.15.2

5.服务器安装nodejs

sudo yum -y install nodejs

6.下载head插件,直接download,然后传到服务器,unzip解压

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

npm install 时,不用管上面的错误,npm run start执行完毕后,访问ip:9100,至此,说明安装成功!

cd /usr/local/app/elasticsearch-head-master
# 安装 module
npm install
# 运行 head 插件
npm run start    
原文地址:https://www.cnblogs.com/hujunwei/p/15565352.html