一、安装kibana
下载地址https://artifacts.elastic.co/downloads/kibana/kibana-6.2.3-linux-x86_64.tar.gz
二、准备工作,添加ELK用户,用ELK用户启动elk
useradd elk
usermod -s /sbin/nologin #不让elk用户来登录系统
解压安装kibana
tar -zxvf kinana-6.2.3-linux-x86_64.tar.gz
mv kinana-6.2.3-linux-x86_64 /usr/local/kibana
三、kibana配置文件
vim /usr/local/kibana/config/kibana.yml修改如下内容
server.port:5601
server.host:"0.0.0.0"
#elasticsearch.url:"http://localhost:9200"
#elasticsearch.username:"user"(配置连接elasticsearch的用户名密码)
#elasticsearch.password:"pass"
四、把kibana目录改为elk用户
chown -R elk:elk /usr/local/kibana
五、脚本启动
vim /usr/local/kibana/bin/start.sh
nohup /usr/local/kibana/bin/kibana >>/tmp/kibana.log &
2>>/tmp/kibana.log
chmod a+x /usr/local/kibana/bin/start.sh
六、普通用户启动
su -s /bin/bash elk 'ussr/local/kibana/bin/start.sh'
如有防火墙需要放行tcp5601
需要进行安全加固,因为kibana默认没有任何权限限制需要将kibana的server.host改成127.0.0.1
安装nginx
配置nginx源cd /etc/yum.repos.d/
touch nginx.repo
将以下内容贴进去
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
执行yum install -y nginx
在nginx的配置文件中去修改/etc/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 65;
server {
listen 5609;
access_log /usr/local/nginx/logs/kibana_access.log main;#日志记录,可以查看到访问的IP,后面放行允许访问的
error_log /usr/local/nginx/logs/kibana_error.log error;#日志记录
location / {
allow 127.0.0.1;#这里默认是本机的,如果需要修改成运行访问的IP,在下面一行添加
deny all;
# auth_basic "elk auth";通过认证的方式访问
#auth_basic_user_file /usr/local/nginx/conf/htpasswd;通过认证的方式访问
proxy_passhttp://127.0.0.1:5601;
}
}
}
printf "elk:$(openssl passwd -1r00t@123)\n" >/usr/local/nginx/conf/htpasswd#这里配置用户名密码
配置完之后nprintf "elk:$(openssl passwd -1 r00t@123)\n" >/usr/local/nginx/conf/htpasswdginx -t 检查下
使用nginx -s reload 重读配置文件不需要重启
七、elasticsearch 安装
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.tar.gz
tar -zxvf elasticsearch-6.2.3.tar.gz
mv elasticsearch-6.2.3.tar.gz /usr/local/elasticsearch
修改配置文件
vim elasticsearch.yml
path.data: /usr/local/elasticsearch/data
path.logs: /usr/local/elasticsearch/logs
network.host: 127.0.0.1
http.port: 9200
修改完之后,需要修改elasticsearch文件用户所属组
chown -R elk:elk /usr/localelasticsearch/
如果机器配置较低 需要修改jvm.options配置文件
-Xms 500M#默认是1G
-Xmx 500M
配置启动脚本start.sh
/usr/local/elasticsearch/bin/elasticsearch -d
脚本执行权限
chmod a+x /usr/local/elasticsearch/bin/start.sh
启动elasticsearchbash
su -s /bin/ elk "/usr/local/elasticsearch/bin/start.sh"
日志文件在/usr/local/elasticsearch/logs/elasticsearch.log
如果要配置在外网上面需要修改内核参数
需要修改的内容
vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
vim /etc/security/limits.d/20-nproc.conf
* soft nproc 10240
* hard nproc 10240
vim /etc/sysctl.conf
vm.max_map_count = 262144需要执行sysctl -p生效
这样就监听在外网IP上了,建议监控内网机器
八、logstash安装
https://artifacts.elastic.co/downloads/logstash/logstash-6.2.3.tar.gz
tar -zxvf logstash-6.2.3.tar.gz
mv logstash-6.2.3 /usr/local/logstash
logstash配置logstash.conf
input {
file {
path => "/usr/local/nginx/logs/kibana_access.log"
}
}
output {
elasticsearch {
hosts => ["http://127.0.0.1:9200"]
}
logstash 启动脚本
vim /usr/local/logstash/bin/start.sh
/usr/local/logstash/bin/logstash -f /usr/local/logstash/config/logstash.conf >>/tmp/logstash.log 2>>/tmp/logstash.log &
chmod a+x /usr/local/logstash/bin/start.sh
启动时间较长
登录kibana上面再management中配置
完成后再discover中查看。