centos7.9安装 Elasticsearch 和 Kibana,Kibana要用证书方式连接Elasticsearch
时间: 2023-12-20 14:52:51 浏览: 120
好的,下面是安装 Elasticsearch 和 Kibana,并且使用证书连接 Elasticsearch 的步骤:
1. 安装 Elasticsearch
执行以下命令:
```
sudo yum install -y java-1.8.0-openjdk-devel
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo vi /etc/yum.repos.d/elasticsearch.repo
```
在 elasticsearch.repo 文件中添加以下内容:
```
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
```
保存并退出文件,然后执行以下命令安装 Elasticsearch:
```
sudo yum install -y elasticsearch
```
2. 配置 Elasticsearch
打开 Elasticsearch 配置文件 /etc/elasticsearch/elasticsearch.yml,设置以下参数:
```
cluster.name: my-cluster
node.name: my-node-1
network.host: 0.0.0.0
http.port: 9200
xpack.security.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.key: /etc/elasticsearch/elasticsearch.key
xpack.security.http.ssl.certificate: /etc/elasticsearch/elasticsearch.crt
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.key: /etc/elasticsearch/elasticsearch.key
xpack.security.transport.ssl.certificate: /etc/elasticsearch/elasticsearch.crt
```
保存并退出文件,然后执行以下命令启动 Elasticsearch:
```
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch
```
3. 安装 Kibana
执行以下命令:
```
sudo vi /etc/yum.repos.d/kibana.repo
```
在 kibana.repo 文件中添加以下内容:
```
[kibana-7.x]
name=Kibana repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
```
保存并退出文件,然后执行以下命令安装 Kibana:
```
sudo yum install -y kibana
```
4. 配置 Kibana
打开 Kibana 配置文件 /etc/kibana/kibana.yml,设置以下参数:
```
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["https://localhost:9200"]
elasticsearch.username: "kibana"
elasticsearch.password: "kibanapassword"
elasticsearch.ssl.certificateAuthorities: [ "/etc/kibana/ca.crt" ]
elasticsearch.ssl.verificationMode: certificate
```
保存并退出文件,然后执行以下命令启动 Kibana:
```
sudo systemctl enable kibana
sudo systemctl start kibana
```
5. 生成证书
执行以下命令生成证书:
```
cd /etc/elasticsearch
sudo /usr/share/elasticsearch/bin/elasticsearch-certutil cert -out elasticsearch.zip
sudo unzip elasticsearch.zip
sudo mv elasticsearch /etc/kibana/
sudo chown -R kibana:kibana /etc/kibana/elasticsearch
```
6. 配置权限
执行以下命令给 kibana 用户赋予访问 Elasticsearch 的权限:
```
sudo /usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto
```
运行上述命令后,会生成一个密码列表,将其中的 kibana 用户的密码记录下来。
7. 配置防火墙规则
执行以下命令打开 5601 和 9200 端口:
```
sudo firewall-cmd --zone=public --add-port=5601/tcp --permanent
sudo firewall-cmd --zone=public --add-port=9200/tcp --permanent
sudo firewall-cmd --reload
```
至此,Elasticsearch 和 Kibana 安装和配置完成,并且 Kibana 使用证书连接 Elasticsearch。
阅读全文