1、首先安裝jdk1.8以上的環境,這裏不再贅述,自行百度
2、安裝 elasticsearch6.4.0,es的啓動環境不能是root超級管理員賬戶,所以我們需要創建一個普通用戶
centos7創建普通用戶流程:
[root@mysql ~]# adduser cloudes
[root@mysql ~]# passwd cloudes
輸入兩次密碼驗證即可
用戶密碼創建完成後,對創建的賬戶進行授權,爲什麼要授權呢
答:由於新創建的用戶並不能使用sudo命令,需要給他添加授權。
1)添加sudoers文件可寫權限
chmod -v u+w /etc/sudoers
2)修改sudoers文件
用vim命令打開sudoers文件,在sudoers文件中找到如下位置並添加如下內容:
cloudes ALL=(ALL) ALL(如需新用戶使用sudo時不用輸密碼,把最後一個ALL改爲NOPASSWD:ALL即可)
3)收回sudoers文件可寫權限
chmod -v u-w /etc/sudoers
以上完成後我們進行elasticsearch6.4.0的安裝正式開始:
# 官網下載壓縮包
[root@localhost /home]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.tar.gz
# 解壓
[root@localhost /home]# tar -zxvf elasticsearch-6.4.0.tar.gz
#修改配置文件
[root@localhost home]# cd cloudes
[root@localhostcloudes]# ls
elasticsearch-6.4.0 elasticsearch-6.4.0.tar.gz logs
[root@localhost cloudes]# cd elasticsearch-6.4.0
[root@localhost elasticsearch-6.4.0]# ls
bin config elasticsearch-analysis-ik-6.4.0.zip elasticsearch-analysis-ik-6.4.0.zip.1 lib LICENSE.txt logs modules NOTICE.txt plugins README.textile
[root@localhost elasticsearch-6.4.0]# cd config/
[root@localhost config]# ls
elasticsearch.keystore elasticsearch.yml jvm.options log4j2.properties role_mapping.yml roles.yml users users_roles
編輯elasticsearch.yml中的配置
[root@mysql config]#vi elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
# es 集羣服務名稱
cluster.name: cloud-service
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#配置節點名稱
node.name: esnode-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#配置 es的數據保存路徑
path.data: /home/elasticsearch/data
#
# Path to log files:
#配置 es的日誌保存路徑
path.logs: /home/elasticsearch/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#配置 es的啓動時內存鎖定,官方建議線上生產環境設置爲true,我這裏沒有啓用
bootstrap.memory_lock: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 修改網絡監聽地址 也可以是默認的 0.0.0.0 ,我這裏是我的主機ip
network.host: 192.168.1.20
#
# Set a custom port for HTTP:
#本機的es環境啓動端口
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 可以不用配置如果單機版的可以默認,也可以配置如下,如果是集羣模式,可以配置多個主機ip["192.168.1.20:9300,192.168.1.21:9300"]
discovery.zen.ping.unicast.hosts: ["192.168.1.20:9300"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
gateway.recover_after_nodes: 1
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
action.destructive_requires_name: true
# 開啓插件訪問權限
http.cors.enabled: true
http.cors.allow-origin: "*"
修改完成進行esc 退出wq!保存
3、接下來切換到創建的普通用戶下進行啓動我們進行es的啓動
[root@mysql elasticsearch-6.4.0]# cd bin/
[root@mysql bin]# ls
elasticsearch elasticsearch-cli elasticsearch-keystore elasticsearch-saml-metadata elasticsearch-setup-passwords.bat elasticsearch-translog x-pack-env.bat
elasticsearch.bat elasticsearch-cli.bat elasticsearch-keystore.bat elasticsearch-saml-metadata.bat elasticsearch-sql-cli elasticsearch-translog.bat x-pack-security-env
elasticsearch-certgen elasticsearch-croneval elasticsearch-migrate elasticsearch-service.bat elasticsearch-sql-cli-6.4.0.jar elasticsearch-users x-pack-security-env.bat
elasticsearch-certgen.bat elasticsearch-croneval.bat elasticsearch-migrate.bat elasticsearch-service-mgr.exe elasticsearch-sql-cli.bat elasticsearch-users.bat x-pack-watcher-env
elasticsearch-certutil elasticsearch-env elasticsearch-plugin elasticsearch-service-x64.exe elasticsearch-syskeygen x-pack x-pack-watcher-env.bat
elasticsearch-certutil.bat elasticsearch-env.bat elasticsearch-plugin.bat elasticsearch-setup-passwords elasticsearch-syskeygen.bat x-pack-env
[root@mysql bin]# ./elasticsearch
執行./elasticsearch
如果後臺進程模式運行執行 ./elasticsearch -d
啓動後我們發現有報錯,這時不要慌
[2019-10-09T10:35:29,459][INFO ][o.e.t.TransportService ] [wVDAxQP] publish_address {192.168.1.20:9300}, bound_addresses {0.0.0.0:9300}
[2019-10-09T10:35:29,493][INFO ][o.e.b.BootstrapChecks ] [wVDAxQP] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2019-10-09T10:35:29,617][INFO ][o.e.n.Node ] [wVDAxQP] stopping ...
[2019-10-09T10:35:29,693][INFO ][o.e.n.Node ] [wVDAxQP] stopped
[2019-10-09T10:35:29,693][INFO ][o.e.n.Node ] [wVDAxQP] closing ...
[2019-10-09T10:35:29,719][INFO ][o.e.n.Node ] [wVDAxQP] closed
主要有兩處報錯:
1、elasticsearch可以創建的文件描述(file descriptors)太少
2、虛擬內存太小
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決辦法
1)elasticsearch用戶擁有的可創建文件描述的權限太低,至少需要65536
處理辦法: #切換到root用戶修改
vim /etc/security/limits.conf # 在最後面追加下面內容
*** hard nofile 65536
*** soft nofile 65536 #*** 是啓動ES的用戶名
2)修改配置sysctl.conf 增加配置值: vm.max_map_count=262144
vi /etc/sysctl.conf 增加
vm.max_map_count=262144
執行 sysctl -p讓文件生效,重新啓動環境,即可啓動成功
4、安裝ik分詞器
進入es目錄下的plugins目錄下,該目錄是存放es插件的地方
[root@mysql cloudes]# cd elasticsearch-6.4.0
[root@mysql elasticsearch-6.4.0]# ls
bin config elasticsearch-analysis-ik-6.4.0.zip elasticsearch-analysis-ik-6.4.0.zip.1 lib LICENSE.txt logs modules NOTICE.txt plugins README.textile
[root@mysql elasticsearch-6.4.0]# cd plugins/
[root@mysql plugins]# ls
ik sql
[root@mysql plugins]#
執行 wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip
[root@mysql plugins]# wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip
這樣也可以下載,如果速度太慢的話,crt+c鍵中斷多次重試的話,可以遇到比較快的鏡像ip,下載速度秒下
也可以到git上下載離線包上傳到服務器上
git上面下載ik分詞器的壓縮包,地址:
https://github.com/medcl/elasticsearch-analysis-ik/releases
與ES版本匹配的6.4.0版本:
下載完成後解壓
[root@mysql plugins]# ls
elasticsearch-analysis-ik-6.4.0.zip sql
[root@mysql plugins]# unzip elasticsearch-analysis-ik-6.4.0.zip
Archive: elasticsearch-analysis-ik-6.4.0.zip
inflating: elasticsearch-analysis-ik-6.4.0.jar
inflating: httpclient-4.5.2.jar
inflating: httpcore-4.4.4.jar
inflating: commons-logging-1.2.jar
inflating: commons-codec-1.9.jar
creating: config/
inflating: config/quantifier.dic
inflating: config/preposition.dic
inflating: config/extra_single_word_low_freq.dic
inflating: config/stopword.dic
inflating: config/suffix.dic
inflating: config/extra_main.dic
inflating: config/IKAnalyzer.cfg.xml
inflating: config/main.dic
inflating: config/extra_stopword.dic
inflating: config/extra_single_word_full.dic
inflating: config/surname.dic
inflating: config/extra_single_word.dic
inflating: plugin-descriptor.properties
inflating: plugin-security.policy
我是直接將名稱改成了ik
[root@mysql plugins]# ls
ik sql
[root@mysql plugins]# ls
ik sql
[root@mysql plugins]# cd ik
[root@mysql ik]# ls
commons-codec-1.9.jar commons-logging-1.2.jar config elasticsearch-analysis-ik-6.4.0.jar httpclient-4.5.2.jar httpcore-4.4.4.jar plugin-descriptor.properties plugin-security.policy
[root@mysql ik]#
然後重啓es服務,大功告成