您好,登录后才能下订单哦!
# CentOS中怎么使用Elasticsearch搭建可视化服务
## 前言
Elasticsearch作为一款强大的分布式搜索和分析引擎,在企业级数据检索、日志分析等场景中广泛应用。但原生Elasticsearch仅提供REST API接口,直接操作不够直观。本文将详细介绍在CentOS系统中部署Elasticsearch并集成Kibana可视化平台的完整流程,包含性能优化和安全配置建议。
---
## 一、环境准备
### 1.1 系统要求
- **操作系统**:CentOS 7/8(本文以CentOS 7.9为例)
- **硬件配置**:
- 最低2核CPU,4GB内存(生产环境建议8GB+)
- 磁盘空间根据数据量预估(SSD推荐)
- **网络要求**:
- 开放9200(ES)、5601(Kibana)端口
```bash
firewall-cmd --permanent --add-port={9200,5601}/tcp
firewall-cmd --reload
Elasticsearch依赖Java运行环境:
# 安装OpenJDK 11
yum install -y java-11-openjdk
# 验证安装
java -version
# 导入GPG密钥
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# 创建repo文件
cat <<EOF > /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
# 安装Elasticsearch
yum install -y elasticsearch
编辑/etc/elasticsearch/elasticsearch.yml
:
cluster.name: my-es-cluster
node.name: node-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0
http.port: 9200
discovery.type: single-node # 单节点模式
xpack.security.enabled: true # 启用安全功能
# 设置开机自启
systemctl daemon-reload
systemctl enable elasticsearch
# 启动服务
systemctl start elasticsearch
# 检查状态
curl -XGET "http://localhost:9200/_cluster/health?pretty" -u elastic
首次运行会输出默认密码,请妥善保存。
yum install -y kibana
编辑/etc/kibana/kibana.yml
:
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]
elasticsearch.username: "kibana_system"
elasticsearch.password: "自动生成的密码"
i18n.locale: "zh-CN" # 中文界面
# 生成Kibana系统用户密码
/usr/share/elasticsearch/bin/elasticsearch-reset-password -u kibana_system
# 启动服务
systemctl enable kibana
systemctl start kibana
生成自签名证书:
mkdir /etc/elasticsearch/certs
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/elasticsearch/certs/elasticsearch.key \
-out /etc/elasticsearch/certs/elasticsearch.crt
修改ES配置:
xpack.security.http.ssl:
enabled: true
keystore.path: certs/elasticsearch.crt
keystore.password: ""
通过Kibana界面操作:
1. 访问http://<服务器IP>:5601
2. 进入”Stack Management” > “安全” > “角色”
3. 创建只读角色示例:
- 集群权限:monitor
- 索引权限:read
, view_index_metadata
# 下载航班数据样本
wget https://download.elastic.co/demos/kibana/gettingstarted/flights.json
# 导入ES(需认证)
curl -XPOST "http://localhost:9200/flights/_bulk?pretty" \
-H "Content-Type: application/json" \
--data-binary @flights.json \
-u elastic:<password>
创建索引模式:
flights*
作为模式名称构建可视化图表:
编辑/etc/elasticsearch/jvm.options
:
-Xms4g # 最小堆内存
-Xmx4g # 最大堆内存(不超过物理内存50%)
# 创建索引时指定分片
PUT /logs-2023.08.01
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
}
}
indices.queries.cache.size: 10%
indices.fielddata.cache.size: 30%
max virtual memory areas vm.max_map_count [65530] is too low
sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
curl -XGET localhost:9200
journalctl -u kibana -f
通过本文的详细指导,您已在CentOS系统上成功搭建了Elasticsearch搜索服务与Kibana可视化平台。建议进一步探索: - 集成Logstash构建ELK日志系统 - 使用APM实现应用性能监控 - 通过Watcher功能设置告警机制
注意事项:生产环境务必配置完备的安全策略,包括定期密码轮换、网络ACL限制等。官方文档是获取最新信息的最佳途径:Elastic官方文档 “`
该文档包含以下特点: 1. 结构化分步指南,适合不同基础用户 2. 包含安全配置、性能优化等进阶内容 3. 提供实际可执行的命令和配置片段 4. 中英文混合的关键术语标注 5. 典型问题排查方案 6. 扩展学习建议 7. 符合Markdown语法规范
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。