avatar
童琦杰
Oct 13, 2019Technology

Ubuntu下安装Elasticsearch

JAVA安装

安装JAVA SDK

bash
sudo apt-get update
sudo apt-get install default-jdk

设置JAVA_HOME环境变量

bash
sudo vim /etc/environment

添加以下内容

/etc/environment
JAVA_HOME="/usr/lib/jvm/[YOUR_JAVA_VERSION]"

刷新配置

bash
source /etc/environment

Elasticsearch安装

官网下载deb包,建议用迅雷下载: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-amd64.deb

使用以下命令安装

bash
sudo dpkg -i elasticsearch-7.6.2-amd64.deb

配置Elasticsearch

bash
sudo vim /etc/elasticsearch/elasticsearch.yml

修改配置文件

/etc/elasticsearch/elasticsearch.yml
yml
cluster.name: YOUR_CLUSTER_NAME
node.name: YOUR_NODE_NAME
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["YOUR_NODE_NAME"]

配置服务自动启动

bash
sudo systemctl enable elasticsearch.service

启动停止服务

bash
sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service

测试是否运行

bash
curl -X GET "http://localhost:9200/?pretty"

Kibana安装

官网下载deb包:https://artifacts.elastic.co/downloads/kibana/kibana-oss-7.6.2-amd64.deb

使用以下命令安装

bash
sudo dpkg -i kibana-oss-7.6.2-amd64.deb

配置Elasticsearch

bash
sudo vim /etc/kibana/kibana.yml

修改配置文件

/etc/kibana/kibana.yml
yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]

配置服务自动启动

bash
sudo systemctl enable kibana.service

启动停止服务

bash
sudo systemctl start kibana.service
sudo systemctl stop kibana.service

测试是否运行:http://localhost:5601

Kibana配置nginx下auth_basic授权

修改配置文件

/etc/kibana/kibana.yml
yml
server.basePath: "/kibana"

配置nginx代理

nginx
server {
        listen 80;
        listen [::]:80;
        server_name _;
        location /kibana/ {
                auth_basic "authorization";
                auth_basic_user_file /your/password/file;
                rewrite ^/kibana/(.*)$ /$1 break;
                proxy_pass http://localhost:5601/;
        }
}

生成密码文件

bash
openssl passwd -apr1 this-is-your-password

问题

1.Elasticsearch启动失败,错误提示如下

systemctl status elasticsearch
Sep 25 20:40:56 elasticsearch systemd[1]: elasticsearch.service: Start operation timed out. Terminating.
Sep 25 20:40:57 elasticsearch systemd[1]: elasticsearch.service: Failed with result 'timeout'.
Sep 25 20:40:57 elasticsearch systemd[1]: Failed to start Elasticsearch.

修改启动超时时间

/usr/lib/systemd/system/elasticsearch.service
TimeoutStartSec=500

2.创建文档时报以下错误:

json
{"error":{"root_cause":[{"type":"cluster_block_exception","reason":"index [logging] blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"}],"type":"cluster_block_exception","reason":"index [logging] blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"},"status":403}

检查磁盘空间是否已满,清理空间

© 2015-2022 tongqijie.com 版权所有沪ICP备17000682号