带上耳机世界与我无关

带上耳机世界与我无关

elasticsearch

一、概念

二、ELK集群部署

1) Elasticsearch 介绍
Elasticsearch(简称ES)是一个分布式、RESTful风格的搜索和数据分析引擎,用于集中存储日志数据
1.关闭防火墙和selinux,host绑定
192.168.8.138    h2    3G内存(这里设置一下虚拟机的内存)
192.168.8.139    h3    3G内存
2、部署jre环境(jdk-8u301-linux-x64.rpm)
# rpm -ivh jdk-8u301-linux-x64.rpm/etc/profile下写入
export JAVA_HOME=/usr/java/jdk1.8.0_301-amd64    #这里安装路径自动定位在这里
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/fre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HMOE/jre/bin:$PATH
[root@hd2 ~]# source /etc/profile   
#查看java版本
[root@hd2 ~]# java -version  
3、安装elasticsearch
[root@hd1 ~]# mkdir /opt/elk
[root@hd1 ~]# mv elasticsearch-7.9.3-linux-x86_64.tar.gz /opt/elk 
[root@hd1 ~]# cd /opt/elk
[root@hd1 elk]# tar zxvf elasticsearch-7.9.3-linux-x86_64.tar.gz 
[root@hd1 elk]# mv elasticsearch-7.9.3 elasticsearch
[root@hd1 elk]# cd elasticsearch 
[root@hd1 elasticsearch]# ls
bin	config	jdk	lib	LICENSE.txt	logs	modules 
这里启动不可以使用root用户,需要新创建一个用户es
4、配置最大进程
[root@hd1 ~]# useradd es
[root@hd1 ~]# chown -R es.es /opt/elk 
[root@hd1 ~]# ulimit -n
1024
调整进程最大值
[root@hd1 ~]# ulimit -n 65535
永久修改修改 (nofile number open file)
[root@hd1 ~]# tail -3 /etc/security/limits.conf
* hard nofile 65535
* soft nofile 65535
* soft nproc 4096
* hard nproc 4096 
# End of file
调整进程最大虚拟内存区域数量临时设置
[root@hd1 ~]# sysctl -w vm.max_map_count=262144 
vm.max_map_count = 262144
永久设置
[root@hd1 ~]# echo "vm.max_map_count=262144" >>/etc/sysctl.conf [root@hd1 ~]# sysctl -p
vm.max_map_count = 262144
配置完成后,需要重启用户,这里需要重启虚拟机  reboot
5、修改配置文件
[root@hd1 ~]# vi /opt/elk/elasticsearch/config/elasticsearch.yml 
cluster.name: elk-cluster	#集群的名称,两个节点保持一致
node.name: node-1	#集群节点的名字
path.data: /opt/elk/data #数据的路径
path.logs: /opt/elk/logs #日志的路径
network.host: 0.0.0.0	#监听的ip地址
http.port: 9200
discovery.seed_hosts: ["192.168.8.138", "192.168.8.139"] #发现集群中的其他节点cluster.initial_master_nodes: ["node-1"] #设置主节点
6、设置es的权限
[root@hd1 ~]# mkdir /opt/elk/data 
[root@hd1 ~]# mkdir /opt/elk/logs 
[root@hd1 ~]# chown -R es.es /opt/elk
7、生成启动脚本
[root@hd1 ~]# cat /usr/lib/systemd/system/elasticsearch.service 
[Unit]
Description=elasticsearch 
[Service]
User=es 
LimitNOFILE=65535
ExecStart=/opt/elk/elasticsearch/bin/elasticsearch 
ExecReload=/bin/kill -HUP $MAINPID 
KillMode=process
#Restart=on-failure

[Install]
WantedBy=multi-user.target
8、启动测试
[root@hd1 ~]# systemctl daemon-reload 
[root@hd1 ~]# systemctl start elasticsearch
查看启动报错,一般是看日志
# journalctl -u elasticsearch
查看监听的端口,9300用于内部集群之间的通信
[root@hd1 config]# ss -ant |grep 9300 LISTEN	0	128	:::9300	:::*
[root@hd1 config]# ss -ant |grep 9200 LISTEN	0	128	:::9200	:::*
**********************************************************************
配置192.168.8.139
[root@hd2 ~]# mkdir -p /opt/elk 
[root@hd2 ~]# useradd es
[root@hd1 ~]# scp -r /opt/elk/* root@192.168.1.12:/opt/elk/ #将8.138的文件scp过来
[root@hd2 ~]# cd /opt/elk
[root@hd2 elk]# ls
data elasticsearch logs 
[root@hd2 elk]# rm -rf logs/* 
[root@hd2 elk]# rm -rf data/*
将配置文件指定master的属性注释掉,将node的名字改成node-2
[root@hd2 elk]#cd /opt/elk/elasticsearch/config/
[root@hd2 config]# grep master_nodes: elasticsearch.yml 
node.name: node-2
#cluster.initial_master_nodes: ["node-1"]
将启动脚本文件拷贝过去
[root@hd1 ~]# scp -r /usr/lib/systemd/system/elasticsearch.service root@192.168.8.139:/usr/lib/systemd/system/
启动服务
[root@hd2 ~]# useradd es
[root@hd2 ~]# chown -R es.es /opt/elk/
[root@hd2 ~]# ulimit -n 65535 
[root@hd2 ~]# vi /etc/security/limits.conf
* hard nofile 65535
* soft nofile 65535
* soft nproc 4096
* hard nproc 4096 
[root@hd2 ~]# sysctl -w vm.max_map_count=262144 
vm.max_map_count = 262144
[root@hd2 ~]# echo "vm.max_map_count=262144" >>/etc/sysctl.conf 
[root@hd2 ~]# sysctl -p
这里需要重启用户 reboot
[root@hd2 ~]# systemctl daemon-reload 
[root@hd2 ~]# systemctl start elasticsearch 
[root@hd2 ~]# ps -ef |grep elastic

查看报错--日志
# cat /opt/elk/logs/elk-cluster.log
# journalctl -u elasticsearch

查看集群各个节点状态
# curl -XGET "http://127.0.0.1:9200/"
{
"name" : "node-2", 
"cluster_name" : "elk-cluster",
"cluster_uuid" : "6Bq-5r02QD2fvGQqGOv4Kg", 
"version" : {
"number" : "7.9.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "c4138e51121ef06a6404866cddc601906fe5c868", 
"build_date" : "2020-10-16T10:36:16.141335Z",
"build_snapshot" : false, 
"lucene_version" : "8.6.2",
"minimum_wire_compatibility_version" : "6.8.0", 
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
这里的uuid必须是一样的,如果不一样就是没有同步

查看集群情况,带*号的表示是master
[root@hd1 ~]# curl -XGET 'http://127.0.0.1:9200/_cat/nodes?pretty' 
192.168.8.138 10 74 6 0.16 0.29 0.20 dilmrt * node-1
192.168.8.139 16 75 5 0.04 0.20 0.18 dilmrt - node-2

Master和Slave的区别: 
Master的职责:
统计各node节点状态信息、集群状态信息统计、索引的创建和删除、索引分配的管理、关闭node节点等
Savle的职责:
同步数据、等待机会成为Master

三、图形化界面

图形管理ES
[root@hd1 ~]# cd /opt/elk/ 
[root@hd1 elk]# rz -y
elasticHD_linux_amd64.zip 
[root@hd1 elk]# unzip elasticHD_linux_amd64.zip 
Archive: elasticHD_linux_amd64.zip
inflating: ElasticHD
[root@hd1 elk]# nohup ./ElasticHD &
[root@hd1 elk]# tail nohup.out -f
To view elasticHD console open http://0.0.0.0:9800 in browser 
exec: "xdg-open": executable file not found in $PATH
访问页面
192.168.8.138:9800

四、部署安装logstash


待续…

10-25 04:51