elasticsearch5.0集羣+kibana5.0+head插件插件的安裝

elasticsearch5.0集羣+kibana5.0+head插件插件的安裝


es集羣的規劃:
兩臺16核64G內存的服務器:


yunva_etl_es1  ip:1.1.1.1 u04es01.chinasoft.com
yunva_etl_es2  ip:2.2.2.2


操做系統:centos7.2 x86_64


1.安裝jdk1.8和elasticsearch5.0.1
rpm -ivh jdk-8u111-linux-x64.rpm
rpm -ivh elasticsearch-5.0.1.rpm


對es的配置進行優化
vim /etc/sysctl.conf
# 增長下面的內容
fs.file-max = 1000000
vm.max_map_count=262144


使配置生效
sysctl -p


vi /etc/security/limits.conf
# 修改
* soft nofile 655350
* hard nofile 655350


內存調整配置文件(建議配置爲物理內存的一半或者更多):
vim /etc/elasticsearch/jvm.options
-Xms32g
-Xmx32g


2.集羣的配置


修改elasticsearch的參數
vim /etc/elasticsearch/elasticsearch.yml


yunva_etl_es1配置
cluster.name: yunva_es_cluster
# 集羣的關鍵配置
discovery.zen.ping.unicast.hosts: ["yunva_etl_es1", "yunva_etl_es2"]
node.name: yunva_etl_es1
node.master: true
# 關閉自動索引
action.auto_create_index: false
node.data: true
path.data: /data/es/data
path.logs: /data/es/logs
bootstrap.memory_lock: false
network.host: 0.0.0.0
http.port: 9200
# 增長新的參數,這樣head插件能夠訪問es
http.cors.enabled: true
http.cors.allow-origin: "*"




yunva_etl_es2的配置
# cat /etc/elasticsearch/elasticsearch.yml
cluster.name: yunva_es_cluster
# 集羣的關鍵配置
discovery.zen.ping.unicast.hosts: ["yunva_etl_es1", "yunva_etl_es2"]
node.name: yunva_etl_es2
node.master: true
# 關閉自動索引
action.auto_create_index: false
path.data: /data/es/data
path.logs: /data/es/logs
bootstrap.memory_lock: false
network.host: 0.0.0.0
http.port: 9200
# 增長新的參數,這樣head插件能夠訪問es
http.cors.enabled: true
http.cors.allow-origin: "*"


建立日誌和數據存放目錄
mkdir -p /data/es/data
mkdir /data/es/logs
chown -R elasticsearch.elasticsearch /data/es

服務啓動:
systemctl start elasticsearch.service

3.head插件的安裝
使用ES的基本都會使用過head,可是版本升級到5.0後,head插件就很差使了,由於這個head插件如今成了一個獨立的組件
在5.0版本中不支持直接安裝head插件,須要啓動一個服務


安裝依賴包:
yum install gcc openssl-devel gcc-c++ compat-gcc-34 compat-gcc-34-c++ bzip2


第一步,安裝git須要從github上面下載代碼,所以先要安裝git
yum -y install git


第二步,安裝node(head安裝依賴npm 須要node4.2.2以上版本)


因爲head插件本質上仍是一個nodejs的工程,所以須要安裝node,使用npm來安裝依賴的包。(npm能夠理解爲maven)
wget https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz
tar -zxvf node-v4.2.2-linux-x64.tar.gz -C /usr/local/
cd /usr/local
ln -sv node-v4.2.2-linux-x64/ node
ln -sv /usr/local/node/bin/* /usr/sbin/


cd /usr/local/node-v4.2.2-linux-x64/
npm install grunt-cli


# ln -sv /usr/local/node-v4.2.2-linux-x64/node_modules/grunt-cli/bin/grunt /usr/sbin/


第三步,安裝並修改head源碼
git clone git://github.com/mobz/elasticsearch-head.git


因爲head的代碼仍是2.6版本的,直接執行有不少限制,好比沒法跨機器訪問。所以須要用戶修改兩個地方:


修改服務器監聽地址


目錄:cd elasticsearch-head/
vim Gruntfile.js


connect: {
    server: {
        options: {
            port: 9100,
            hostname: '*',
            base: '.',
            keepalive: true
        }
    }
}


增長hostname屬性,設置爲*


修改鏈接地址:


目錄:elasticsearch-head/_site/app.js


修改head的鏈接地址:


this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
把localhost修改爲你es的服務器地址,如:
# 通過測試須要配置爲服務器的外網IP地址
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://1.1.1.1:9200";


第四步,運行head 首先開啓ES


而後在head目錄中,執行npm install 下載以來的包:


npm install 
最後,啓動nodejs
在elasticsearch-head目錄下node_modules/grunt下若是沒有grunt二進制程序,須要執行
npm install grunt


# 而後啓動nodejs
grunt server


集羣健康檢測:
http://1.1.1.1:9200/_cluster/health?pretty


{
  "cluster_name" : "yunva_es_cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}


4.安裝kibana
rpm -ivh kibana-5.0.1-x86_64.rpm


編輯配置文件
vim /etc/kibana/kibana.yml
修改這兩項,其餘默認不用動
server.host: "0.0.0.0"
elasticsearch.url: "http://localhost:9200"


啓動命令:
systemctl start kibana
systemctl enable kibana


kibana訪問地址:
http://1.1.1.1


爲了安全將kibana 5601和head插件的9100端口經過nginx的密碼驗證方式訪問:


server {  
  listen       80;  
  server_name 1.1.1.1 u04kaf01.chinasoft.com;  
  location / {  
     auth_basic "secret";  
     auth_basic_user_file /data/nginx/db/passwd.db;  
     proxy_pass http://localhost:5601;
     proxy_set_header Host $host:5601;  
     proxy_set_header X-Real-IP $remote_addr;  
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
     proxy_set_header Via "nginx";  
  }  
  
  location /head/{
     auth_basic "secret";
     auth_basic_user_file /data/nginx/db/passwd.db;
     proxy_pass http://u04es01.chinasoft.com:9100/;
     proxy_set_header Host $host:9100;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Via "nginx";
  }
  access_log off;
}


---------------------------------------------------------------------

配置zabbix檢測若9200端口或者5601端口掛掉則自動拉起elasticsearch和kibana服務java

具體參考:zabbix系列(九)zabbix3.0實現自動觸發zabbix-agent端shell腳本任務node

http://blog.csdn.net/reblue520/article/details/52315154
linux

/usr/local/zabbix-agent/scripts/start_es.sh #!/bin/bash # if elasticsearch exists kill it source /etc/profile count_es=`ps -ef|grep elasticsearch|grep -v grep|wc -l` if [ $count_es -gt 1 ];then     ps -ef|grep elasticsearch|grep -v grep|/bin/kill `awk '{print $2}'` fi # start it su yunva -c "cd /data/elasticsearch-5.0.1/bin && /bin/bash elasticsearch &" 執行: sudo /bin/bash /usr/local/zabbix-agent/scripts/start_es.sh 報錯: which: no java in (/sbin:/bin:/usr/sbin:/usr/bin) Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME 解決辦法: 在腳本中添加 source /etc/profile --------------------------------------------------------------------- 以root用戶運行elasticsearch 報錯: can not run elasticsearch as root 網上的方法,針對elasticsearch5.1不起做用 解決方法1: 在執行elasticSearch時加上參數-Des.insecure.allow.root=true,完整命令以下 ./elasticsearch -Des.insecure.allow.root=true   解決辦法2: 用vi打開elasicsearch執行文件,在變量ES_JAVA_OPTS使用前添加如下命令 ES_JAVA_OPTS="-Des.insecure.allow.root=true"   解決辦法: su yunva -c "cd /data/elasticsearch-5.0.1/bin && /bin/bash elasticsearch &" 自動拉起kibana服務的腳本: cat /usr/local/zabbix/scripts/restart_kibana.sh #!/bin/bash # if kibana exists kill it count_kibana=`ps -ef|grep kibana|grep -v grep|wc -ll` if [ $count_kibana -eq 1 ];then     ps -ef|grep kibana|grep -v grep|/bin/kill `awk '{print $2}'` fi # start it /etc/init.d/kibana start
相關文章
相關標籤/搜索