主機角色(內存不要小於1G):java
軟件及版本(百度網盤連接地址和密碼:連接: https://pan.baidu.com/s/17bYc8MRw54GWCQCXR6pKjg 提取碼: f6w8) #若是失效能夠發送郵件到13693200275@163.comnode
部署前操做:linux
關閉防火牆,關閉selinux(生產環境按需關閉或打開)
同步服務器時間,選擇公網ntpd服務器或者自建ntpd服務器
[root@es-node1 ~]# rpm -ivh jdk-8u25-x64.rpm Preparing... ########################################### [100%] 1:jdk1.8.0_181 ########################################### [100%]
設置Java環境web
[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)
#關閉新郵件提示(從新登陸生效),很煩.......... [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
設置打開文件描述符、進程數、內存限制json
[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
配置內核參數bootstrap
[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用戶vim
[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
切換用戶並啓動服務app
[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被選舉爲masterdom
檢查服務是否正常
[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" }
[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版本的(即基礎版)
因爲在elasticsearch在6.3版本以後x-pack是默認安裝好的,因此再也不須要用戶本身去安裝
[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
[elastic@es-node1 elasticsearch]$ cd /usr/local/elasticsearch/bin/ [elastic@es-node1 bin]$ ./elasticsearch-certgen
[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/
[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使用用戶名密碼登陸
[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用戶登陸
左下角能夠看到咱們的用戶名,到此,咱們全部的配置都已經完成了