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服務

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

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


/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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM