Centos 6.7安裝Elasticsearch2.3.3
閑來無事,就來學習下被稱為新全文的Elasticsearch。新手第一次裝新全文,問題還是挺多的。
1.關於Elasticsearch
Elasticsearch是一個基於Lucene的搜尋工具,它使用Java開發並且使用Lucene作為核心來實現索引和搜尋的功能。但是它的目的是通過簡單的Restful API來隱藏Lucene的複雜性,從而讓全文檢索搜尋變得簡單。
但是,Elasticsearch不僅僅是Lucene和全文檢索搜尋,我們還能這樣去描述它:
1)分布式的即時檔案儲存體,每個欄位都被索引並可被搜尋
2)分布式的即時分析搜尋引擎
3)可以擴充到上百台伺服器,處理PB級結構化或非結構化資料
而且,所有的這些功能被整合到一個服務裡面,你的應用可以通過簡單的RestfulAPI、各種語言的用戶端甚至命令列與之互動。
2. 下載最新版的Elasticsearch的安裝包,該版本可直接部署到Linux系統上
安裝之前,請確認已安裝好最新版的JDK版本,安裝步驟請參照其他網友文章。最好把安裝的工具包放在/opt目錄,本人安裝在centos 6.7下的/home目錄下使用,wget命令得到該zip安裝包。
[plain]view plaincopy
- Elasticsearch2.3.3
- ZIPhttps://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch/2.3.3/elasticsearch-2.3.3.zip</span>
- Woohoo!Yourdownloadisalmostcomplete!It'sclearyou'reabouttodogreatthingswithdata.Whetherthisisyourfirst,tenth,orumpteenthdownloadofanopensourceElasticproject,there'salwayssomethingnewtolearn.
- So,beforeyoudiveintothedocumentation,haveaganderatthegoodnessbelow.Trysomethingnew,expandtoanewusecase,thinkupsomethingtotallynovel,and,aboveall,staycurious.
3. 正式安裝Elasticsearch
在root使用者,/home目錄下解壓zip包,建立軟串連In -s Elasticsearch2.3.3 elasticsearch,cd /elasticsearch後,執行 ./bin/elasticsearch,會出現如下的錯誤:
[plain]view plaincopy
- [root@xxxxbin]#./elasticsearch
- Exceptioninthread"main"java.lang.RuntimeException:don'trunelasticsearchasroot.</span>
- atorg.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
- atorg.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
- atorg.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
- atorg.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
- Refertothelogforcompleteerrordetails.
這是Elasticsearch出於系統安全考慮設定的條件。由於Elasticsearch可以接收使用者輸入的指令碼並且執行,為了系統安全考慮,因此可以建立一個單獨的使用者用來運行Elasticsearch。
1) 建立單獨的使用者組和elsearch使用者:
[plain]view plaincopy
- groupaddelsearch
- useraddelsearch-gelsearch-pelasticsearch
2) 更改/home/elasticsearch使用者及組:
[plain]view plaincopy
- <spanstyle="white-space:pre"></span></span>cd/home
- <spanstyle="white-space:pre"></span></span>chown-Relsearch:elsearchelasticsearch
3) 使用elsearch使用者執行安裝命令
[plain]view plaincopy
- <spanstyle="white-space:pre"></span></span>suelsearch
- <spanstyle="white-space:pre"></span></span>cdelasticsearch/bin執行./elasticsearch
4. 關於安裝plugins(外掛程式管理)
[plain]view plaincopy
- Exceptioninthread"main"java.lang.IllegalStateException:Unabletoaccess'path.plugins'(/home/hye/elasticsearch/plugins)
- Likelyrootcause:java.nio.file.AccessDeniedException:/home/hye/elasticsearch/plugins
- atsun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
- atsun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
- atsun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
- atsun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384)
- atjava.nio.file.Files.createDirectory(Files.java:674)
- atjava.nio.file.Files.createAndCheckIsDirectory(Files.java:781)
- atjava.nio.file.Files.createDirectories(Files.java:767)
- atorg.elasticsearch.bootstrap.Security.ensureDirectoryExists(Security.java:337)
- atorg.elasticsearch.bootstrap.Security.addPath(Security.java:314)
- atorg.elasticsearch.bootstrap.Security.addFilePermissions(Security.java:246)
- atorg.elasticsearch.bootstrap.Security.createPermissions(Security.java:212)
- atorg.elasticsearch.bootstrap.Security.configure(Security.java:118)
- atorg.elasticsearch.bootstrap.Bootstrap.setupSecurity(Bootstrap.java:196)
- atorg.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:167)
- atorg.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
- atorg.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
- Refertothelogforcompleteerrordetails.
請按照官網的plguins Managerment的介紹和安裝方法進行安裝:
4.1安裝前的準備
[plain]view plaincopy
- Runningasroot
- IfElasticsearchwasinstalledusingthedeborrpmpackagethenrunbin/pluginasrootsoitcanwritetotheappropriatefilesondisk.Otherwiserunbin/pluginastheuserthatownsalloftheElasticsearchfiles.
4.2 正式安裝plugins外掛程式
本人安裝的是Core Elasticsearch plugins,按照圖中的安裝步驟,完成安裝。
[plain]view plaincopy
- PluginManagement
- CoreElasticsearchpluginsedit
- CoreElasticsearchpluginscanbeinstalledasfollows:
- sudobin/plugininstall[plugin_name]
- Forinstance,toinstallthecoreICUplugin,justrunthefollowingcommand:
- sudobin/plugininstallanalysis-icu
- ThiscommandwillinstalltheversionofthepluginthatmatchesyourElasticsearchversion.
- Communityandnon-corepluginsedit
- Non-corepluginsprovidedbyElasticsearch,orpluginsprovidedbythecommunity,canbeinstalledfromdownload.elastic.co,fromMaven(CentralandSonatype),orfromGitHub.Inthiscase,thecommandisasfollows:
- sudobin/plugininstall[org]/[user|component]/[version]</span><spanstyle="font-size:14px;">
5. 啟動Elasticsearch
使用非root使用者進行安裝:
[plain]view plaincopy
- <spanstyle="white-space:pre"></span>suelsearch
- <spanstyle="white-space:pre"></span>cdelasticsearch/bin
- <spanstyle="white-space:pre"></span>./elasticsearch
[plain]view plaincopy
- 如果想要Elasticsearch在後端運行:
- <spanstyle="white-space:pre"></span>./elasticsearch-d
控制台顯示:(啟動Elasticsearch成功)
[plain]view plaincopy
- [elsearch@xhyu-100elasticsearch]$./bin/elasticsearch
- [2016-06-1900:27:24,188][WARN][bootstrap]unabletoinstallsyscallfilter:seccompunavailable:CONFIG_SECCOMPnotcompiledintokernel,CONFIG_SECCOMPandCONFIG_SECCOMP_FILTERareneeded
- [2016-06-1900:27:24,417][INFO][node][Mad-Dog]version[2.3.3],pid[4260],build[218bdf1/2016-05-17T15:40:04Z]
- [2016-06-1900:27:24,417][INFO][node][Mad-Dog]initializing...
- [2016-06-1900:27:25,040][INFO][plugins][Mad-Dog]modules[reindex,lang-expression,lang-groovy],plugins[analysis-icu],sites[]
- [2016-06-1900:27:25,066][INFO][env][Mad-Dog]using[1]datapaths,mounts[[/(/dev/sda3)]],netusable_space[33.4gb],nettotal_space[45.6gb],spins?[possibly],types[ext4]
- [2016-06-1900:27:25,066][INFO][env][Mad-Dog]heapsize[1015.6mb],compressedordinaryobjectpointers[true]
- [2016-06-1900:27:25,066][WARN][env][Mad-Dog]maxfiledescriptors[4096]forelasticsearchprocesslikelytoolow,considerincreasingtoatleast[65536]
- [2016-06-1900:27:27,264][INFO][node][Mad-Dog]initialized
- [2016-06-1900:27:27,264][INFO][node][Mad-Dog]starting...
- [2016-06-1900:27:27,330][INFO][transport][Mad-Dog]publish_address{192.168.31.200:9300},bound_addresses{192.168.31.200:9300}
- [2016-06-1900:27:27,333][INFO][discovery][Mad-Dog]elasticsearch/-H0Z_q6iRsuYDXd1b1jCAg
- [2016-06-1900:27:30,390][INFO][cluster.service][Mad-Dog]new_master{Mad-Dog}{-H0Z_q6iRsuYDXd1b1jCAg}{192.168.31.200}{192.168.31.200:9300},reason:zen-disco-join(elected_as_master,[0]joinsreceived)
- [2016-06-1900:27:30,420][INFO][http][Mad-Dog]publish_address{192.168.31.200:9200},bound_addresses{192.168.31.200:9200}
- [2016-06-1900:27:30,420][INFO][node][Mad-Dog]started
- [2016-06-1900:27:30,441][INFO][gateway][Mad-Dog]recovered[0]indicesintocluster_state
6. Elasticsearch介面驗證失敗,修改Elasticsearch設定檔
未修改設定檔前,使用非root使用者進行elasticsearch安裝。
[plain]view plaincopy
- [root@xxxxelasticsearch]#curl-XGEThttp://機器ip:9200/
- curl:(7)couldn'tconnecttohost
按照網上的文章和官網安裝說明,並沒有修改預設設定檔的說法。
[plain]view plaincopy
- /home/hye/elasticsearch/config
修改完後,開啟驗證介面,最好找個好點瀏覽器,QQ瀏覽器就別用了。可以用Chrome瀏覽器。
在介面輸入:http://安裝機器ip:9200/,頁面回饋資訊如下:
[plain]view plaincopy
- {
- "name":"Mad-Dog",
- "cluster_name":"elasticsearch",
- "version":{
- "number":"2.3.3",
- "build_hash":"218bdf10790eef486ff2c41a3df5cfa32dadcfde",
- "build_timestamp":"2016-05-17T15:40:04Z",
- "build_snapshot":false,
- "lucene_version":"5.5.0"
- },
- "tagline":"YouKnow,forSearch"
- }
至此,安裝結束。。。