一、环境信息及安装前准备
主机角色(内存不要小于1G):
软件及版本(百度网盘链接地址和密码:链接: https://pan.baidu.com/s/17bYc8MRw54GWCQCXR6pKjg 提取码: f6w8) #如果失效可以发送邮件到13693200275@163.com
部署前操作:
关闭防火墙,关闭selinux(生产环境按需关闭或打开)
同步服务器时间,选择公网ntpd服务器或者自建ntpd服务器
二、ES集群安装配置
1.安装jvm依赖环境(其他节点相同操作)
[root@es-node1 ~]# rpm -ivh jdk-8u25-x64.rpm Preparing... ########################################### [100%] 1:jdk1.8.0_181 ########################################### [100%]
设置Java环境
[root@es-node-1 ~]# cat /etc/profile.d/java.sh #编辑java环境变量配置文件 export JAVA_HOME=/usr/java/latest export CLASSPATH=$JAVA_HOME/lib/tools.jar export PATH=$JAVA_HOME/bin:$PATH [root@es-node-1 ~]# . /etc/profile.d/java.sh [root@es-node-1 ~]# java -version #检查版本 java version "1.8.0_181" Java(TM) SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
2.安装及配置elasticsearch
#关闭新邮件提示(重新登录生效),很烦.......... [root@es-node1 ~]# echo "unset MAILCHECK">> /etc/profile #解压elastic到/usr/local下 [root@es-node1 ~]# tar xf elasticsearch-6.3.2.tar.gz -C /usr/local/ [root@es-node1 ~]# cd /usr/local/ [root@es-node1 local]# ln -sv elasticsearch-6.3.2/ elasticsearch "elasticsearch" -> "elasticsearch-6.3.2/" [root@es-node1 local]# cd elasticsearch/config/ #配置JVM参数,最大不要超过32G,并且留一半内存给操作系统 [root@es-node1 config]# vim jvm.options -Xms400m -Xmx400m #配置elastic信息,其他节点需要修改node.name和network.host的值 [root@es-node1 config]# cp elasticsearch.yml elasticsearch.yml-bak [root@es-node1 config]# vim elasticsearch.yml [root@es-node1 config]# grep "^[a-z]" elasticsearch.yml cluster.name: my-app node.name: node-1.107 path.data: /Data/es/data path.logs: /Data/es/logs bootstrap.memory_lock: true network.host: 192.168.1.107 http.port: 9200 discovery.zen.ping.unicast.hosts: ["192.168.1.107", "192.168.1.108","192.168.1.109"] discovery.zen.minimum_master_nodes: 2
设置打开文件描述符、进程数、内存限制
[root@es-node1 config]# vim /etc/security/limits.conf * soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
* soft memlock unlimited * hard memlock unlimited
配置内核参数
[root@es-node1 config]# vim /usr/lib/sysctl.d/50-default.conf vm.max_map_count=362144 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 [root@es-node1 config]# sysctl -p #此命令可能不生效,可以重启使配置生效
创建elastic用户
[root@es-node1 ~]# useradd elastic [root@es-node1 ~]# echo "123456" |passwd --stdin elastic
创建相关目录及授权
[root@es-node1 ~]# mkdir -pv /Data/es/ mkdir: 已创建目录 "/Data" mkdir: 已创建目录 "/Data/es/"
[root@es-node1 ~]# chown -R elastic:elastic /Data/es/ [root@es-node1 ~]# chown -R elastic:elastic /usr/local/elasticsearch-6.3.2/ #退出,重新登录(可以的话最好重启服务器,发现有些参数不重启不生效) [root@es-node1 config]# exit
切换用户并启动服务
[root@es-node1 ~]# su - elastic [elastic@es-node1 ~]$ cd /usr/local/elasticsearch [elastic@es-node1 elasticsearch]$ nohup ./bin/elasticsearch > /tmp/elastic.log & #或者添加 -d/--daemonize 参数后台运行,日志文件在path.logs指定的目录下 [1] 2426 [elastic@es-node1 elasticsearch]$ nohup: 忽略输入重定向错误到标准输出端 [elastic@es-node1 elasticsearch]$ tailf /tmp/elastic.log
通过屏幕输出可以看到服务启动并通过自动发现方式添加集群内其他节点,并且node-1.107被选举为master
检查服务是否正常
[elastic@es-node1 elasticsearch]$ netstat -tnlp Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 192.168.1.107:9200 0.0.0.0:* LISTEN 2072/java #9200是http协议的RESTful接口 tcp 0 0 192.168.1.107:9300 0.0.0.0:* LISTEN 2072/java #9300是tcp通讯端口,集群间和TCPClient都走的它 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN - tcp6 0 0 :::22 :::* LISTEN -
[elastic@es-node1 elasticsearch]$ curl http://192.168.1.107:9200
{ "name" : "node-1.107", "cluster_name" : "my-app", "cluster_uuid" : "Zk1xQhbyRlS6r99uAfk51Q", "version" : { "number" : "6.3.2", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "053779d", "build_date" : "2018-07-20T05:20:23.451332Z", "build_snapshot" : false, "lucene_version" : "7.3.1", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }
三、安装配置kibana
[root@kb-node1 ~]# tar xf kibana-6.3.2-linux-x86_64.tar.gz -C /usr/local/
[root@kb-node1 ~]# cd /usr/local/
[root@kb-node1 local]# ln -sv kibana-6.3.2-linux-x86_64/ kibana
"kibana" -> "kibana-6.3.2-linux-x86_64/"
[root@kb-node1 local]# cd kibana
[root@kb-node1 kibana]# vim config/kibana.yml
[root@kb-node1 kibana]# grep "^[a-z]" config/kibana.yml
server.port: 5601 #监听的端口
server.host: "192.168.1.110" #监听的地址
elasticsearch.url: "http://192.168.1.107:9200" #elasticsearch访问的URL地址
[root@kb-node1 kibana]# ./bin/kibana & #启动服务
我们可以看到启动后服务监听的地址,访问这个URL
kibana主页面,大致意思就是告诉我们kibana可以做哪些事
点击Monitoring标签可以开启监控设置,并且我们的license是basic版本的(即基础版)
四、安装破解版x-pack #本教程只供交流学习使用,切勿运用到商业用途。如有需要请购买官方正版授权
由于在elasticsearch在6.3版本之后x-pack是默认安装好的,所以不再需要用户自己去安装
1.替换x-pack包,并重启elasticsearch服务
[elastic@es-node1 elasticsearch]$ cd modules/x-pack/x-pack-core/
[elastic@es-node1 x-pack-core]$ ll x-pack-core-6.3.2.jar #用我们破解后的包进行替换
-rw-r--r-- 1 elastic elastic 1773114 8月 21 17:48 x-pack-core-6.3.2.jar
[elastic@es-node1 x-pack-core]$cd /usr/local/elasticsearch
[elastic@es-node1 elasticsearch]$ vim config/elasticsearch.yml
[elastic@es-node1 elasticsearch]$ tail -1 config/elasticsearch.yml
xpack.security.enabled: false #关闭x-pack
重启elasticsearch服务,并把license.json上传到服务器
[elastic@es-node1 elasticsearch]$ curl -XPUT -u elastic 'http://192.168.1.107:9200/_xpack/license' -H "Content-Type: application/json" -d @license.json Enter host password for user 'elastic': #密码为:change {"acknowledged":true,"license_status":"valid"}
在kibana上查看license
Platinum表示白金版 过期时间为2099 年12月31日,但是我们暂时还不能使用x-pack,因为白金版的x-pack需要SSL进行数据传输,所以我们需要先配置SSL
五、配置SSL并启用x-apck
1.创建证书
[elastic@es-node1 elasticsearch]$ cd /usr/local/elasticsearch/bin/ [elastic@es-node1 bin]$ ./elasticsearch-certgen
2.解压证书
[elastic@es-node1 bin]$ mkdir /tmp/cert [elastic@es-node1 bin]$ mv cert.zip /tmp/cert/ [elastic@es-node1 bin]$ cd /tmp/cert/ [elastic@es-node1 cert]$ unzip cert.zip Archive: cert.zip creating: ca/ inflating: ca/ca.crt inflating: ca/ca.key creating: elasticsearch/ inflating: elasticsearch/elasticsearch.crt inflating: elasticsearch/elasticsearch.key [elastic@es-node1 cert]$ ll 总用量 8 drwxrwxr-x 2 elastic elastic 34 9月 20 13:47 ca -rw------- 1 elastic elastic 5157 9月 20 13:47 cert.zip drwxrwxr-x 2 elastic elastic 56 9月 20 13:47 elasticsearch [elastic@es-node1 cert]$ mv ca/* /usr/local/elasticsearch/config/ [elastic@es-node1 cert]$ mv elasticsearch/* /usr/local/elasticsearch/config/ [elastic@es-node1 cert]$ cd /usr/local/elasticsearch/config/ [elastic@es-node1 config]$ ll -rct #最后四个 总用量 48 -rw-rw---- 1 elastic elastic 0 9月 19 16:15 users_roles -rw-rw---- 1 elastic elastic 0 9月 19 16:15 users -rw-rw---- 1 elastic elastic 197 9月 19 16:15 roles.yml -rw-rw---- 1 elastic elastic 473 9月 19 16:15 role_mapping.yml -rw-rw---- 1 elastic elastic 6380 9月 19 16:15 log4j2.properties -rw-rw---- 1 elastic elastic 2942 9月 19 16:15 jvm.options -rw-r----- 1 elastic elastic 2853 9月 19 16:15 elasticsearch.yml-bak -rw-rw---- 1 elastic elastic 207 9月 19 16:20 elasticsearch.keystore -rw-rw---- 1 elastic elastic 2905 9月 20 13:27 elasticsearch.yml -rw-rw-r-- 1 elastic elastic 1671 9月 20 13:57 ca.key -rw-rw-r-- 1 elastic elastic 1200 9月 20 13:57 ca.crt -rw-rw-r-- 1 elastic elastic 1675 9月 20 13:57 elasticsearch.key -rw-rw-r-- 1 elastic elastic 1237 9月 20 13:57 elasticsearch.crt
将证书拷贝到其他节点,放入 usr/local/elasticsearch/config/ 目录下
[elastic@es-node1 config]$ scp *.crt *.key 192.168.1.108:/usr/local/elasticsearch/config/ [elastic@es-node1 config]$ scp *.crt *.key 192.168.1.109:/usr/local/elasticsearch/config/
3.配置SSL,其他节点相同配置
[elastic@es-node1 config]$ vim elasticsearch.yml
[elastic@es-node1 config]$ tail elasticsearch.yml
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
xpack.security.enabled: true #之前配置为false注意删除或者修改
xpack.security.transport.ssl.enabled: true
xpack.ssl.key: elasticsearch.key
xpack.ssl.certificate: elasticsearch.crt
xpack.ssl.certificate_authorities: ca.crt
重启elasticsearch服务
打开kibana web界面,发现无法登陆,并且无法使用用户名密码登录,下一步我们需要配置kibana使用用户名密码登录
4.创建elk集群相关用户
[elastic@es-node1 bin]$ ./elasticsearch-setup-passwords -h #查看命令帮助 Sets the passwords for reserved users Commands -------- auto - Uses randomly generated passwords #主要命令选项,表示系统将使用随机字符串设置密码 interactive - Uses passwords entered by a user #主要命令选项,表示使用用户输入的字符串作为密码 Non-option arguments: command Option Description ------ -----------
-h, --help show help -s, --silent show minimal output -v, --verbose show verbose output [elastic@es-node1 bin]$ ./elasticsearch-setup-passwords auto #为了演示效果,这里我们使用系统自动创建 Initiating the setup of passwords for reserved users elastic,kibana,logstash_system,beats_system. The passwords will be randomly generated and printed to the console. Please confirm that you would like to continue [y/N]y #选择y Changed password for user kibana #kibana角色和密码 PASSWORD kibana = 4VXPRYIVibyAbjugK6Ok Changed password for user logstash_system #logstash角色和密码 PASSWORD logstash_system = 2m4uVdSzDzpt9OEmNin5 Changed password for user beats_system #beast角色和密码 PASSWORD beats_system = O8VOzAaD3fO6bstCGDyQ Changed password for user elastic #elasticsearch角色和密码 PASSWORD elastic = 1TWVMeN8tiBy917thUxq
#可以先将以上用户和密码保存下来,具体的用户介绍见最后
配置kibana添加elasticsearch用户认证
[root@kb-node1 ~]# vim /usr/local/kibana/config/kibana.yml [root@kb-node1 ~]# grep "^elastic" /usr/local/kibana/config/kibana.yml elasticsearch.url: "http://192.168.1.107:9200" elasticsearch.username: "elastic" elasticsearch.password: "1TWVMeN8tiBy917thUxq" #就是上一步创建的elastic的账号和密码
重启kibana,重启后打开kibana web页面
可以使用用户名和密码登录了(使用之前创建的用户名和密码登录即可),这里我们选择elastic用户登录
左下角可以看到我们的用户名,到此,我们所有的配置都已经完成了
#注:x-pack的内置用户