elasticsearch安裝教程,集羣搭建及jdbc同步 elasticsearch安裝 elastic-head安裝

elasticsearch安裝教程,集羣搭建及jdbc同步

elasticsearch安裝

下載

安裝之前,請確認已安裝好最新版的JDK版本,下載linux安裝包,我下載的是5.2.2版本

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.tar.gz

解壓 tar -zxvf elasticsearch-5.2.2.tar.gz

啓動

elastaicsearch啓動在bin目錄下執行 sh elasticsearch
如果直接執行會出現如下錯誤

 root@vm-ubuntu-1:/data/app/elasticsearch-5.2.2/bin# sh elasticsearch
[2017-03-20T15:21:08,485][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-5.2.2.jar:5.2.2]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.2.2.jar:5.2.2]
    at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.2.2.jar:5.2.2]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.2.2.jar:5.2.2]
    at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.2.2.jar:5.2.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.2.2.jar:5.2.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.2.2.jar:5.2.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-5.2.2.jar:5.2.2]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:203) ~[elasticsearch-5.2.2.jar:5.2.2]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-5.2.2.jar:5.2.2]
    at org.elasticsearch.

這是ElasticSearch出於系統安全考慮設置的條件。由於ElasticSearch可以接收用戶輸入的腳本並且執行,爲了系統安全考慮,因此可以創建一個單獨的用戶用來運行ElasticSearch。
1)創建單獨的用戶組和elsearch用戶

groupadd elsearch  
useradd elsearch -g elsearch -p elasticsearch

2)更改/home/elasticsearch用戶及組:

chown -R elsearch:elsearch  elasticsearch-5.2.2  

3)允許其他網絡訪問
修改config裏的elasticsearch.yml 添加下面配置

network.host: 0.0.0.0

3)啓動

sh bin/elasticsearch

4)查看節點狀態 查看是否啓動成功
在界面輸入:http://安裝機器ip:9200/,頁面回饋信息如下:
正常的話會返回如下

{
    "name": "JtM9Sdm",
    "cluster_name": "elasticsearch",
    "cluster_uuid": "me8qO0StSi237lWDdy-UMg",
    "version": {
        "number": "5.2.2",
        "build_hash": "f9d9b74",
        "build_date": "2017-02-24T17:26:45.835Z",
        "build_snapshot": false,
        "lucene_version": "6.4.1"
    },
    "tagline": "You Know, for Search"
}

啓動你會遇到如下問題

1、can not run elasticsearch as root

切換到非root用戶

2、main ERROR Could not register mbeans java.security.AccessControlException: access denied (“javax.management.MBeanTrustPermission” “register”)

改變elasticsearch文件夾所有者到當前用戶

sudo chown -R noroot:noroot elasticsearch

3、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

sudo vi /etc/sysctl.conf

添加下面配置:

vm.max_map_count=655360

並執行命令:

sudo sysctl -p

4、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

sudo vi /etc/security/limits.conf

添加如下內容:

  • soft nofile 65536

  • hard nofile 131072

  • soft nproc 2048

  • hard nproc 4096

sudo vi /etc/pam.d/common-session

添加 session required pam_limits.so

sudo vi /etc/pam.d/common-session-noninteractive

添加 session required pam_limits.so

elastaicsearch 集羣搭建 分佈式配置

修改配置文件

注意:如果是在局域網中運行elasticsearch集羣也是很簡單的,只要cluster.name設置一致,並且機器在同一網段下,啓動的es會自動發現對方,組成集羣。
修改config下的elasticsearch.yml文件
修改如下

#集羣的名字
cluster.name: kuaima
#節點名
node.name: node-1
#允許其他機器訪問
network.host: 0.0.0.0
#允許跨域訪問
http.cors.enabled: true
http.cors.allow-origin: "*"
#其他幾點ip
discovery.zen.ping.unicast.hosts: ["192.168.88.116", "192.168.88.149","192.168.88.117"]

只要cluster.name名字一樣,在同一局域網的其他機器會自動加入集羣
查看集羣狀態節點狀態
http://192.168.88.117:9200/_cat/health?v
會看到如下信息

epoch      timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1490089269 17:41:09  kuaima  green           3         3      0   0    0    0        0             0                  -                100.0%
```json






<div class="se-preview-section-delimiter"></div>

##安裝elasticsearch-head插件
elasticsearch-head用於管理集羣節點





<div class="se-preview-section-delimiter"></div>

###安裝nodejs
如果沒有安裝git的話先安裝git




<div class="se-preview-section-delimiter"></div>

yum -y install git

下載安裝包




<div class="se-preview-section-delimiter"></div>

```linux
git clone git://github.com/mobz/elasticsearch-head.git

安裝node和npm
安裝方法參考
http://www.runoob.com/nodejs/nodejs-install-setup.html
1、下載源碼,你需要在https://nodejs.org/en/download/下載最新的Nodejs版本,本文以v0.10.24爲例:

wget https://nodejs.org/dist/v6.10.0/node-v6.10.0.tar.gz

2、解壓源碼

tar -zxvf node-v6.10.0.tar.gz 

因爲現在nodejs依賴gccg++所以要安裝

#Centos2 安裝gcc  
yum install gcc-c++
#Ubuntu 安裝 gcc
apt-get install make gcc g++

3、 編譯安裝

cd node-v6.10.0 
./configure --prefix=/data/app/node-v6.10.0
make
make install

4、 配置NODE_HOME,進入profile編輯環境變量
vim /etc/profile
設置nodejs環境變量,在 export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL 一行的上面添加如下內容:

#set for nodejs
export NODE_HOME=/data/app/node-v6.10.0
export PATH=$NODE_HOME/bin:$PATH

:wq保存並退出,編譯/etc/profile 使配置生效
source /etc/profile
驗證是否安裝配置成功
node -v

修改elasticsearch.yml文件,如果前面配置過請忽略

#允許跨域訪問
http.cors.enabled: true
http.cors.allow-origin: "*"

安裝grunt所需依賴

cd elasticsearch-head
npm install
npm install -g grunt-cli
grunt server

在瀏覽器訪問
http://192.168.88.149:9100/
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章