如何在Ubuntu 18.04上安装Elasticsearch,Logstash和Kibana

Linux2021-01-29 07:35:25620条
在本教程中,我们将在Ubuntu 18.04服务器上重新安装Elastic Stack。您将学习如何安装Elastic Stack的所有组件(包括Filebeat,用于转发和集中日志和文件的Beat),并配置它们以收集和可视化系统日志。我们将在单个服务器上安装所有组件,我们将其称为Elastic Stack Server。

1. 安装JDK8

1.1到Oracle官网下载JDK8

本文下载的是jdk-8u281-linux-x64.tar.gz

1.2 将安装包拷贝到虚拟机或服务器上

1.3 创建目录

mkdir /usr/local/java

1.4 将安装包解压到刚才创建的java目录下

tar -zxvf jdk-8u281-linux-x64.tar.gz -C /usr/local/java/

1.5 配置环境变量

vi /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_281
export PATH=${JAVA_HOME}/bin:${PATH}

刷新profile文件,让配置生效。

source /etc/profile

1.6 查看java版本

root@VM-0-12-ubuntu:/usr/local/java/jdk1.8.0_281# java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

2. 安装ES7.10

2.1 安装apt-transport-https

sudo apt-get install apt-transport-https

2.2 将elasticsearch添加到api下载库中

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list

2.3 使用apt安装elasticsearch

sudo apt-get update && sudo apt-get install elasticsearch

2.4 启动elasticsearch

sudo -i service elasticsearch start
sudo -i service elasticsearch stop

2.5 设置密码访问

进入elasticsearch.yml文件,加上以下配置:

xpack.security.enabled: true

重启elasticsearch

以交互的方式设置用户名和密码:

root@VM-0-12-ubuntu:/usr/share/elasticsearch# /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_281/jre] does not meet this requirement
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana_system]: 
Reenter password for [kibana_system]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

3. 安装Kibana

3.1 apt安装Kibana

sudo apt-get install kibana

3.2 启动/停止Kibana

sudo -i service kibana start
sudo -i service kibana stop

3.3 访问Kibana

如果还未配置nginx,可以使用localhost:5601访问。

3.4 配置nginx,使用域名访问kibana

server {
    listen       80;
    server_name  你的kibana域名;
    access_log /usr/local/nginx/logs/kibana/access.log;
    error_log /usr/local/nginx/logs/kibana/error.log;

    location / {
        proxy_pass http://127.0.0.1:5601;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

3.5 如果elasticsearch设置了密码访问,需要修改kibana.yml中的配置:

elasticsearch.username: "elastic"
elasticsearch.password: "password"
评论啦~
暂无评论,快来抢沙发吧!