安装部署
前置需求
- JDK6+(被监控的应用程序运行在jdk6及以上版本)
- JDK8+(SkyWalking collector和WebUI部署在jdk8及以上版本)
- Elasticsearch 5.x(集群模式或不使用)
- Zookeeper 3.4.10
- 被监控应用的宿主服务器系统时间(包含时区)与collectors,UIs部署的宿主服务器时间设置正确且相同
https://github.com/apache/skywalking/blob/5.x/docs/cn/Deploy-backend-in-cluster-mode-CN.md
ELK官网:https://www.elastic.co/
ELK官网文档:https://www.elastic.co/guide/index.html
ELK中文手册:https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html
ELK中文社区:https://elasticsearch.cn/
ELK-API :https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html
下载地址:https://www.elastic.co/cn/downloads/elasticsearch
- ES 5,安装需要 JDK 8 以上
- ES 6.5,安装需要 JDK 11 以上
- ES 7.2.1,内置了 JDK 12
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.0-linux-x86_64.tar.gz
tar -zxvf elasticsearch-7.7.0-linux-x86_64.tar.gz -C /export/server/
系统配置修改
* soft nofile 655350 #任何用户可以打开的最大的文件描述符数量,默认1024,这里的数值会限制tcp连接 * hard nofile 655350 * soft nproc 655350 #任何用户可以打开的最大进程数 * hard nproc 650000 @student hard nofile 65535 @student soft nofile 4096 @student hard nproc 50 #学生组中的任何人不能拥有超过50个进程,并且会在拥有30个进程时发出警告 @student soft nproc 30
soft是一个警告值,而hard则是一个真正意义的阀值,超过就会报错
新增内容如下:
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
* soft memlock unlimited
* hard memlock unlimited
vim /etc/sysctl.conf
新增内容如下:
vm.max_map_count=655360
fs.file-max=655360
vim /etc/security/limits.d/20-nproc.conf
将*号改为自己的用户名,如: es soft nproc 4096
执行 sysctl -p 让其生效
修改elasticsearch.yml文件,添加如下配置
# 主节点:
# 集群名称
cluster.name: "es_cluster"
# 节点名称 ,仅仅是描述名称,用于在日志中区分
node.name: node01
# 是否可以成为master节点
node.master: true
# 是否允许该节点存储数据,默认开启
node.data: true
# 网络绑定,这里我绑定 0.0.0.0,支持外网访问
network.host: ["0.0.0.0"]
# 设置对外服务的http端口,默认为9200
http.port: 9200
# 支持跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
# 设置节点间交互的tcp端口,默认是9300
transport.tcp.port: 9300
# 集群个节点IP地址,也可以使用els、els.shuaiguoxia.com等名称,需要各节点能够解析
discovery.zen.ping.unicast.hosts: ["node01","node02","node03"]
# 集群发现的节点ip
discovery.seed_hosts: ["node01","node02","node03"]
# 手动指定可以成为 mater 的所有节点的 name 或者 ip,这些配置将会在第一次选举中进行计算
cluster.initial_master_nodes: ["node01","node02","node03"]
# 数据仓储位置
path.data: /export/server/elasticsearch-7.7.0/data
path.logs: /export/server/elasticsearch-7.7.0/log
# 备份数据存储路径
path.repo: ["/export/server/elasticsearch-7.7.0/backup"]
# 为了避免脑裂,集群节点数最少为 半数+1
discovery.zen.minimum_master_nodes: 2
# es 应用是不锁住jvm内存
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#x-pack
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
#xpack.security.transport.ssl.verification_mode: false
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
分发至其他节点只需要修改下node.name,另外cluster.initial_master_nodes 允许为主节点的ip需要设置为单数
Elasticsearch6.3版本之后,自带xpack,不需要额外安装,各节点直接生成证书bin/elasticsearch-plugin install x-pack
bin/elasticsearch-certutil ca
bin/elasticsearch-certutil cert --ca /export/server/elasticsearch-7.7.0/elastic-stack-ca.p12
生成的elastic-certificates.p12文件拷贝到每个节点的config目录下
密码设置,这里的密码是你浏览器访问登陆es的密码,默认的用户是elastic. bin/elasticsearch-setup-passwords interactive
创建一个新的系统账户并添加权限
user add es
chown -R es elasticsearch-7.7.0
chgrp -R es elasticsearch-7.7.0
启动服务
su es
elasticsearch-7.7.0/bin/elasticsearch
后台运行ES
# 设置后台启动
bin/elasticsearch -p /tmp/elasticsearch-pid -d
结束进程
# 查看运行的pid
cat /tmp/elasticsearch-pid && echo
# 结束进程
kill -SIGTERM {pid}
curl -XGET"http://$(hostname):9200/_cluster/health?pretty=true"
2. 停止elasticsearch应用:
curl -XPOST "http:// $(hostname):9200/_shutdown"
3. 查看集群健康:
curl $(hostname):9200/_cluster/health?pretty
4. 检查集群状态:
curl $(hostname):9200/_cluster/stats?pretty
5. 节点状态:
curl $(hostname):9200/_nodes/process?pretty
curl $(hostname):9200/_nodes/node1/process?pretty
6. 当你不知道有那些属性可以查看时:
curl '$(hostname):9200/_cat/',会返回可以查看的属性
7.查看集群当前节点
$(hostname):9200/_cat/nodes
访问 http://192.168.199.181:9200/_cat/nodes
如果出现这种情况,没有发现另外两个节点就检查cluster_uuid,如果有不一致的就删除挂载目录data下的内容即可
验证
curl -i "http://node01:9200"
Elasticsearch Head Plugin前端工具安装
由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。
#wget https://npm.taobao.org/mirrors/node/v10.14.1/node-v10.14.1-linux-x64.tar.gz
wget https://nodejs.org/dist/v9.3.0/node-v9.3.0-linux-x64.tar.xz
tar -xvf node-v9.3.0-linux-x64.tar.xz
环境变量配置
vim /etc/profile.d/node.sh
#set for nodejs
export NODE_HOME=/export/server/node-v9.3.0-linux-x64
export PATH=$NODE_HOME/bin:$PATH
source /etc/profile
测试
node -v
npm -v
5.0可以通过elasticseach自带的plugin命令 安装elasticsearch-head,之后版本只能通过下载elasticsearch-head对应的源码包去安装
git clone git://github.com/mobz/elasticsearch-head.git
yum install bzip2
cd elasticsearch-head
npm install
配置修改
vim _site/app.js
# 修改 this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
# 在文件的4374行附近 # 这里的 localhost 是指进入elasticsearch-head页面时默认访问的ES集群地址,把她修改为其中一台ES节点的地址即可
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.199.181:9200";
修改后启动即可
grunt server
访问对应IP:9100就可以使用了
在安装 x-pack后,登录9200端口需要用户和密码,在使用elasticsearch head时,就不能直接访问9100了。
按照官方文档的要求,https://github.com/mobz/elasticsearch-head#connecting-to-elasticsearch
我们需要修改elasticsearch.yml配置文件。
添加
#跨域允许设置的头信息,默认为X-Requested-With,Content-Type,Content-Length
http.cors.allow-headers: Authorization,Content-Type
或
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
访问时,在url上需要添加用户名和密码:http://node01:9200/?auth_user=elastic&auth_password=123456
集群节点管理工具cerebro部署
wget https://github.com/lmenezes/cerebro/releases/download/v0.9.1/cerebro-0.9.1.tgz
tar -zxvf cerebro-0.9.1.tgz -C /export/server/
执行bin/cerebro启动cerebro
访问node01:9000/即可
日志分析平台Kibana部署
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.7.0-linux-x86_64.tar.gz
tar -zxvf kibana-7.7.0-linux-x86_64.tar.gz -C /export/server/
#配置文件config/kibana.yml添加
server.port: 5601
server.host: "0.0.0.0" #必须为0.0.0.0 否则浏览器无法访问到
elasticsearch.hosts: ["http://此处填入es节点1IP地址:9200", "http://此处填入es节点2IP地址:9200","http://此处填入es节点3IP地址:9200"]
elasticsearch.username: "kibana"
elasticsearch.password: "[填入es集群的kibana密码]"
chown -R es kibana-7.7.0-linux-x86_64
chgrp -R es kibana-7.7.0-linux-x86_64/
su es
kibana-7.7.0-linux-x86_64/bin/kibana
访问节点IP:5601
用户名为elastic