一、首先去elasticsearch官網下載軟件包版本1.7.0版本.html
#wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.0.tar.gz
二、解壓elasticsearch-1.7.0.tar.gz 軟件包.
html5
#tar zxf elasticsearch-1.7.0.tar.gz
三、es配置文件參數解釋(真正配置不全用的到):node
#集羣名稱標識了你的集羣,自動探查會用到它。git
#若是你在同一個網絡中運行多個集羣,那就要確保你的集羣名稱是獨一無二的.github
cluster.name: test-elasticsearch
#節點名稱會在啓動的時候自動生成,因此你能夠不用手動配置。你也能夠給節點指定一個特定的名稱.web
node.name: "elsearch1"
#容許這個節點被選舉爲一個主節點(默認爲容許)apache
#node.master: true
#容許這個節點存儲數據(默認爲容許)bootstrap
# node.data: true
#You can exploit these settings to design advanced cluster topologies.vim
# 你能夠利用這些設置設計高級的集羣拓撲瀏覽器
#
# 1. You want this node to never become a master node, only to hold data.
# This will be the "workhorse" of your cluster.
# 1. 你不想讓這個節點成爲一個主節點,只想用來存儲數據。
# 這個節點會成爲你的集羣的「負載器」
#
# node.master: false # node.data: true
#You want this node to only serve as a master: to not store any data and
# to have free resources. This will be the "coordinator" of your cluster.
# 2. 你想讓這個節點成爲一個主節點,而且不用來存儲任何數據,而且擁有空閒資源。
# 這個節點會成爲你集羣中的「協調器」
# node.master: true # node.data: false
# Use the Cluster Health API [http://localhost:9200/_cluster/health], the
# Node Info API [http://localhost:9200/_nodes] or GUI tools
#使用集羣體檢API[http://localhost:9200/_cluster/health] ,
# 節點信息API[http://localhost:9200/_cluster/nodes] 或者GUI工具例如:
# A node can have generic attributes associated with it, which can later be used
# for customized shard allocation filtering, or allocation awareness. An attribute
# is a simple key value pair, similar to node.key: value, here is an example:
# 一個節點能夠附帶一些普通的屬性,這些屬性能夠在後面的自定義分片分配過濾或者allocation awareness中使用。
# 一個屬性就是一個簡單的鍵值對,相似於node.key: value, 這裏有一個例子:
# node.rack: rack314
# By default, multiple nodes are allowed to start from the same installation location
# to disable it, set the following:
# 默認的,多個節點容許從同一個安裝位置啓動。若想禁止這個特性,按照下面所示配置:
# node.max_local_storage_nodes: 1
# Set the number of shards (splits) of an index (5 by default):
# 設置一個索引的分片數量(默認爲5)
# index.number_of_shards: 5
# Set the number of replicas (additional copies) of an index (1 by default):
# 設置一個索引的副本數量(默認爲1)
# index.number_of_replicas: 1
# Note, that for development on a local machine, with small indices, it usually
# makes sense to "disable" the distributed features:
# 注意,爲了使用小的索引在本地機器上開發,禁用分佈式特性是合理的作法。
# index.number_of_shards: 1 # index.number_of_replicas: 0
# Path to directory containing configuration (this file and logging.yml):
# 包含配置(這個文件和logging.yml)的目錄的路徑
# path.conf: /path/to/conf
# Path to directory where to store index data allocated for this node.
# 存儲這個節點的索引數據的目錄的路徑
# path.data: /path/to/data
# Can optionally include more than one location, causing data to be striped across
# the locations (a la RAID 0) on a file level, favouring locations with most free
# space on creation. For example:
# 能夠隨意的包含不止一個位置,這樣數據會在文件層跨越多個位置(a la RAID 0),建立時會
# 優先選擇大的剩餘空間的位置
# path.data: /path/to/data1,/path/to/data2
# Path to temporary files:
# 臨時文件的路徑
# path.work: /path/to/work
# Path to log files:
# 日誌文件的路徑
# path.logs: /path/to/logs
# Path to where plugins are installed:
# 插件安裝路徑
# path.plugins: /path/to/plugins
# If a plugin listed here is not installed for current node, the node will not start.
# 若是當前結點沒有安裝下面列出的插件,結點不會啓動
# plugin.mandatory: mapper-p_w_uploads,lang-groovy
# ElasticSearch performs poorly when JVM starts swapping: you should ensure that
# it _never_ swaps.
# 當JVM開始swapping(換頁)時ElasticSearch性能會低下,你應該保證它不會換頁
# Set this property to true to lock the memory:
# 設置這個屬性爲true來鎖定內存
# bootstrap.mlockall: true
# Make sure that the ES_MIN_MEM and ES_MAX_MEM environment variables are set
# to the same value, and that the machine has enough memory to allocate
# for ElasticSearch, leaving enough memory for the operating system itself.
# 確保ES_MIN_MEM和ES_MAX_MEM環境變量設置成了同一個值,確保機器有足夠的內存來分配
# 給ElasticSearch,而且保留足夠的內存給操做系統
# You should also make sure that the ElasticSearch process is allowed to lock
# the memory, eg. by using `ulimit -l unlimited`.
# 你應該確保ElasticSearch的進程能夠鎖定內存,例如:使用`ulimit -l unlimited`
# ElasticSearch, by default, binds itself to the 0.0.0.0 address, and listens
# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node
# communication. (the range means that if the port is busy, it will automatically
# try the next port).
# 默認的ElasticSearch把本身和0.0.0.0地址綁定,HTTP傳輸的監聽端口在[9200-9300],節點之間
# 通訊的端口在[9300-9400]。(範圍的意思是說若是一個端口已經被佔用,它將會自動嘗試下一個端口)
# Set the bind address specifically (IPv4 or IPv6):
# 設置一個特定的綁定地址(IPv4 or IPv6):
# network.bind_host: 192.168.0.1
# Set the address other nodes will use to communicate with this node. If not
# set, it is automatically derived. It must point to an actual IP address.
# 設置其餘節點用來與這個節點通訊的地址。若是沒有設定,會自動獲取。
# 必須是一個真實的IP地址。
# network.publish_host: 192.168.0.1
# Set both 'bind_host' and 'publish_host':
# 'bind_host'和'publish_host'都設置
# network.host: 192.168.0.1
# Set a custom port for the node to node communication (9300 by default):
# 爲節點之間的通訊設置一個自定義端口(默認爲9300)
# transport.tcp.port: 9300
# Enable compression for all communication between nodes (disabled by default):
# 爲全部的節點間的通訊啓用壓縮(默認爲禁用)
# transport.tcp.compress: true
# Set a custom port to listen for HTTP traffic:
# 設置一個監聽HTTP傳輸的自定義端口
# http.port: 9200
# Set a custom allowed content length:
# 設置一個自定義的容許的內容長度
# http.max_content_length: 100mb
# Disable HTTP completely:
# 徹底禁用HTTP
# http.enabled: false
三、操做系統配置
1.文件描述符
vim /etc/security/limits.conf添加 * soft nofile 655350 * hard nofile 655350
退出當前用戶從新login就會生效,使用ulimit -n驗證下。
2.最大內存映射區數量,禁用swap交換分區
vim /etc/sysctl.conf增長 vm.max_map_count=262144 vm.swappiness=1 修改完成後sysctl -p
jvm參數配置
ES_HOME的bin目錄下有一個elasticsearch.in.sh文件,修改
ES_MIN_MEM=256m ES_MAX_MEM=1g
爲合適的值
四、es的插件安裝:
Marvel是Elasticsearch的管理和監控工具,對於開發使用免費的。它配備了一個叫作Sense的交互式控制檯,方便經過瀏覽器直接與Elasticsearch交互。
Marvel是一個插件,在Elasticsearch目錄中運行如下代碼來下載和安裝:
./plugin -i elasticsearch/marvel/latest
elasticsearch-head是一個elasticsearch的集羣管理工具,它是徹底由html5編寫的獨立網頁程序,你能夠經過插件把它集成到es。
#./plugin -install mobz/elasticsearch-head
地址:http://172.16.2.24:25556/_plugin/head/
elasticsearch插件bigdesk安裝:
bigdesk是elasticsearch的一個集羣監控工具,能夠經過它來查看es集羣的各類狀態,如:cpu、內存使用狀況,索引數據、搜索狀況,http鏈接數等。
在cmd命令行中進入安裝目錄,再進入 bin目錄,運行如下命令:
#./plugin -install lukas-vlcek/bigdesk
在瀏覽器中輸入:http://172.16.2.24:25556/_plugin/bigdesk能夠看到效果
注意:elasticsearch 分詞ik的安裝,若是不安裝分詞ik插件,根本建不了索引,而且讓訪問http://172.16.2.24:25556/_plugin/head/ 集羣一片空白,點擊web 建立索引頁沒有反應。
注意:github https://github.com/medcl/elasticsearch-analysis-ik 給出了對應的es的ik版本,1.7.0的es對應的1.2.6的版本,開始我這塊裝了1.8的ik,建立索引失敗,後臺也是報ik的錯誤。
ik:1.2.6版本的下載:https://github.com/medcl/elasticsearch-analysis-ik/releases?after=v1.6.1
安裝操做:
下載zip包解壓到一個目錄解壓縮:
#unzip elasticsearch-analysis-ik-master.zip
安裝mavne環境,apache 官網下載軟件包設置環境變量:
#export PATH=$PATH:/usr/local/maven/bin
由於是源代碼,此處須要使用maven打包,進入解壓文件夾中,執行命令:
#cd elasticsearch-analysis-ik-master #mvn clean package
#在es的plugin目錄下建立ik目錄,並將target目錄下的elasticsearch-analysis-ik-1.2.6.jar copy 到ik目錄下。
[root@localhost target]# cd /data/elasticsearch-1.7.0 [root@localhost elasticsearch-1.7.0]# ls bin config data lib LICENSE.txt logs NOTICE.txt plugins README.textile [root@localhost elasticsearch-1.7.0]# cd plugins/ [root@localhost plugins]# ls bigdesk head ik marvel [root@localhost plugins]# cd ik/ [root@localhost ik]# ls elasticsearch-analysis-ik-1.2.6.jar
注意:若是是集羣,能夠將jar分別copy至其餘幾臺機器。
es配置文件須要添加入下行:
index: analysis: analyzer: ik: alias: [ik_analyzer] type: org.elasticsearch.index.analysis.IkAnalyzerProvider ik_max_word: type: ik use_smart: false ik_smart: type: ik use_smart: true marvel.agent.enabled: false
完整的es配置文件以下,三臺一樣的配置,除了hostip和node.name外.
# cat elasticsearch.yml cluster.name: test-es-cluster network.host: 172.16.2.24 node.name: "node24" discovery.zen.ping.unicast.hosts: ["172.16.2.24:25555","172.16.2.21:25555","172.16.2.23:25555"] index.number_of_shards: 5 discovery.zen.minimum_master_nodes: 2 script.groovy.sandbox.enabled: false transport.tcp.port: 25555 http.port: 25556 script.inline: off script.indexed: off script.file: off index: analysis: analyzer: ik: alias: [ik_analyzer] type: org.elasticsearch.index.analysis.IkAnalyzerProvider ik_max_word: type: ik use_smart: false ik_smart: type: ik use_smart: true marvel.agent.enabled: false
後臺啓動es服務:
[root@localhost bin]# pwd /data/elasticsearch-1.7.0/bin [root@localhost bin]# ./elasticsearch -d
三臺集羣的機器中找其中一臺建立索引:
建立索引:
curl -X PUT 'http://172.16.2.24:25556/index' {"acknowledged":true}
注意:返回結果爲acknowledged":true 爲成功.
經過瀏覽器訪問:http://172.16.2.24:25556/_plugin/head/ 測試效果.