安装集群es和head,kinaba以及测试

2018-08-23  本文已影响0人  龟龟51

1安装elasticsearch集群

1.1三台机器都统一用户为es

172.31.100.114

172.31.100.113

172.31.100.112

114已经创建好

以下是112和113的情况

1.2  112和113都下载Elasticsearch并解压Elasticsearch到/opt/elasticsearch/

tar -zxf elasticsearch-6.2.4.tar.gz -C /opt/elasticsearch/

并且进到elasticsearch-6.2.4下更改用户权限

chown -R es:bigdata .

1.3三台机器都修改配置

vim /elasticsearch-6.2.4/config/elasticsearch.yml

1.4三台机器都修改 Linux下/etc/security/limits.conf文件设置

vim /etc/security/limits.conf

* soft nofile 262144

* hard nofile 262144

es soft memlock unlimited

es hard memlock unlimited

1.5  112和113修改 Linux下/etc/sysctl.conf文件设置

1.6启动三台机器的elasticsearch

一定要在es用户下且在elasticsearch的按照目录下

后台启动

bin/elasticsearch  -d

2.elasticsearch-head安装

elasticsearch-head要更新数据,只要在114那台机器下的elasticsearch-head目录下重新npm install即可

3.完成的head界面

在安装目录启动grunt server,不要在root用户启动

在浏览器输入网址http://172.31.100.114:9100/

4.kibana安装

4.1下载https://www.elastic.co/cn/downloads/kibana 版本要和es版本相同 

4.2解压到114的/opt/modules中

4.3配置

# vim config/kibana.yml

elasticsearch.url: "http://192.168.10.173:9200" # kibana监控哪台es机器

server.host: "192.168.10.173" # kibana运行在哪台机器

4.4运行

bin/kibana

浏览器输入http://172.31.100.114:5601进入界面

5.测试工具esrally

在172.31.100.111上安装

参考:https://segmentfault.com/a/1190000011174694

5.1安装环境要求

•Python 3.4+ 和 pip3

5.1.1安装python3

安装目录在/opt/esrally/python

1.安装bzip2-1.0.6.tar.gz

下载bzip2-1.0.6.tar.gz

tar -xf bzip2-1.0.6.tar.gz

cd bzip2-1.0.6

64位系统需要加上-fPIC编译选项

vi Makefile

CFLAGS=-fPIC -Wall -Winline -O2 -g $(BIGFILES)

make 

sudo make install

2安装Python-3.4.1

(1)下载解压。

$ wget https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz

$ tar zxvf Python-3.4.1.tgz

(2)进入解压后的目录,执行安装配置

$ ./configure

或指定安装目录

$ ./configure --prefix=/opt/python3

(3)Build

$ make

(4)Install

$ make install

(5)安装后建立一个链接,这样我们可以用python3直接运行程序,和python2区别开来。

$ ln -s /opt/python3/bin/python3 /usr/bin/python3

•JDK 8

配置cdh时已经安装

•git 1.9+

5.1.2安装git 1.9

安装目录在/opt/esrally/git

第一步,安装依赖包。

在开始编译安装git之前,首先应该安装好必要的依赖包,省得在安装过程中出现各种问题。

#yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

第二步,下载并编译git。

你可以从kernel.org上下载自己需要的版本,或者直接像我这样下载1.9.0版本。

切换到src目录,下载并解压git源码。

wget https://www.kernel.org/pub/software/scm/git/git-1.9.0.tar.gz

tar xzf git-1.9.0.tar.gz

进入到解压出的git目录,执行编译。

#cd git-1.9.0

# make prefix=/usr/local/git all

# make prefix=/usr/local/git install

# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc

# source /etc/bashrc

第三步,完成。

# git --version

5.2esrally安装

pip3 install esrally

5.3设置esrally环境

esrally configure

6.测试

esrally --track=geonames --target-hosts=172.31.100.112:9200,172.31.100.113:9200,172.31.100.114:9200 --pipeline=benchmark-only

说明:track是测试数据包,--target-hosts是测试主机,pipeline=benchmark-only是加压测试

8基于libcurl的与es进行通信(C++代码)

Elasticsearch可以通过http报文和json语句来进行增删查改,可以通过libcurl构造语句,去发送到es集群进行操作。参考

https://blog.csdn.net/xsdxs/article/details/72849796

https://stackoverflow.com/questions/25887453/how-to-use-libcurl-in-c-to-send-post-to-elasticsearch

实现一个简便的esclient()函数,方便读写

#include

#include

#include

#include

#include

using namespace std;

/*

说明

对es进行增删查改,主要是通过构建http报文去实现的,libcurl可以实现这些功能。

函数esclient(const string &_http, const string &_json, const string &_command)说明:

_http:你要操作的位置,

如果需要更新数据,在位置之后加_updata;例:esclient("http://172.31.100.114:9200/customer/external/2/_updata/"," {\"doc\": { \"name\": \"eee\" }}","updata");

如果需要匹配查询或批量查询批量删除,在位置之后加_search;例:esclient("http://172.31.100.114:9200/bank/_search","","search");

_json:要操作的json语句,要插入数据,查询数据,更新数据,匹配删除数据等操作需要加json语句

_command:要删除到id的数据,或者索引必须交delete关键字,要查询到id的数据必须加get关键字

使用环境:必须安装libcurl,编译需要加-lcurl

*/

size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)

{

    strncat((char *)stream, (char *)ptr, size*nmemb);

    return size * nmemb;

}

int esclient(const string &_http, const string &_json, const string &_command)

{

CURL *curl;

CURLcode res;

struct curl_slist* headers = NULL;

curl = curl_easy_init();

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

curl_easy_setopt(curl, CURLOPT_URL, _http.c_str());

headers=curl_slist_append(headers, "Content-Type:application/json");

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

char out[40960]={0};

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);

curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);

if(_command=="delete")

{

curl_easy_setopt(curl,  CURLOPT_CUSTOMREQUEST, "DELETE");

}

else if(_command=="get")

{

curl_easy_setopt(curl,  CURLOPT_CUSTOMREQUEST, "GET");

}

else

{

curl_easy_setopt(curl,  CURLOPT_CUSTOMREQUEST, "POST");

}

if(!_json.empty())

{

curl_easy_setopt(curl,CURLOPT_POSTFIELDS,_json.c_str());

curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,_json.length());

}

res = curl_easy_perform(curl);

printf("%s\n",out);

curl_easy_cleanup(curl);

return res;

}

int main(void)

{

esclient("http://172.31.100.114:9200/customer/external/1","","get"); //查询单条数据

esclient("http://172.31.100.114:9200/bank/_search","","search"); //批量查询数据,但是只返回10条,如需其他要求,加json语句

esclient("http://172.31.100.114:9200/customer/external/3/"," { \"name\": \"hhh\" }","add"); //增加一条数据

esclient("http://172.31.100.114:9200/customer/external/2/_updata/"," {\"doc\": { \"name\": \"eee\" }}","updata"); //更新某条数据

esclient("http://172.31.100.114:9200/ccc","","delete"); //删除索引

esclient("http://172.31.100.114:9200/customer/external/_delete_by_query"," {\"query\":{ \"match\":{\"name\": \"hhh\" }}}",""); //匹配删除数据

}

运行结果:

图1是查询单条语句的结果

图2是批量查询的结果

图3是以上程序运行前的图

图4是以上程序运行后的图

上一篇 下一篇

猜你喜欢

热点阅读