一. 部署集群
user用户下
unzip elasticsearch_bak.zip #解压引擎文件# 批改默认的配置文件cd elasticsearch_bak/configvi elasctsearch.yml cluster.name: es-zl #批改集群名,所有节点配置的该名称必须一样 node.name: es-46 #批改每个节点的名称,必须不同,以辨别每个节点 node.master:true #是否可作为主节点 path.data: /data/es_data #es数据寄存的地位 network.host:127.17.30.46 #每个节点的ip地址 http.port: 9200 #节点的端口,必须雷同,默认9200 bootstrap.memory_lock: true bootstrap.system_call_filter: false #内存锁定,避免swap使es产生内存交互 discovery.zen.ping.unicast.hosts:["127.17.30.44","127.17.30.45",,] #集群master节点的ip,不须要所有节点的ip,其余节点只有能与任意一个master节点通信,即可退出到该集群当中 discovery.zen.minimum_master_nodes:2 #当2个有资格成为主节点的从节点认为主节点挂了,则进行从新选主,个别设置为(n/2)+1,避免es呈现脑裂状况 gateway.recover_after_nodes: 3 #节点数量达到多少之后,进行数据恢复解决 http.cors.enabled: true http.cors.allow-origin: "*" vi yvm.options -Xms16g #默认为2g,可依据服务器内存,自行批改 #通过一下命令查看内存cat /proc/cpuinfo | grep 'cpu cores' | wc -l #查看cpu核数cat /proc/meminfo | grep MemTotal #只查看内存free -h #查看内存的应用df -h #查看硬盘存储
留神:该操作必须在每台服务器上都要部署,并不能在root用户下操作,要在user下操作,如果没有usr用户,则创立。
如果没有操作权限,则执行:
# root下,将文件权限设置为duser用户可操作chown duser *chgrp duser *
当不应用es近程词典时:
批改elasticsearch-5.3.0/plugins/ik/config/IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"><properties> <comment>IK Analyzer 扩大配置</comment> <!--用户能够在这里配置本人的扩大字典 --> <entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic</entry> <!--用户能够在这里配置本人的扩大进行词字典--> <entry key="ext_stopwords">custom/ext_stopword.dic</entry> <!--用户能够在这里配置近程扩大字典 --> <!-- <entry key="remote_ext_dict">http://10.172.80.229:9301/mydict.dic</entry> --> <!--用户能够在这里配置近程扩大进行词字典--> <!-- <entry key="remote_ext_stopwords">http://10.172.80.229:9301/stopword.dic</entry> --></properties>
阐明:正文后两项即可
增加自定义同义词
替换config/synonyms.txt文件
synonyms.txt文件内格局,所有同义词为一行,且用 “, ” 隔开
二、批改集群配置
root用户下
vi /etc/security/limits.conf #增加以下语句 * soft nofile 65536 * hard nofile 65536 * soft nproc 65536 * hard nproc 65536 duser soft memlock unlimited duser hard memlock unlimited vi /etc/sysctl.conf #批改以下语句 vm.max_map_count=655360 sysctl -p
三、启动集群
user用户下
cd elasticsearch_bak/bin./elasticsearch -d #后盾启动集群curl 172.17.30.45:9200/_cat/nodes #查看所有节点,*为主节点# 启动不了时候,查看es-log
四、搜寻部署
user用户下的操作,查看es-log
vi index_search_mapping.sh #批改的ip和端口与集群一样 curl -XPUT "http://10.25.114.90:9200/index" { settings": { "number_of_shards": 6, #主分片数量,个别为 服务器总核数 "number_of_replicas": 2, #正本分片的数量,避免数据失落 }
留神:分词器anslyzer能够依据理论状况进行批改、删除和增加
增加删除字段 当须要增加字段时,只有在以下地位增加即可
"mappings": { "index": { "properties": { "id": { "type": "keyword" }, "": { #须要增加的字段名 "type":"" #增加的字段的约束条件 } } } }
留神:批改某个文件的字段之前,须要先删除该文件的core
重新启动搜寻时,也须要进行以下步骤
curl -XDELETE "http://172.19.30.45:9200/index"#批改完之后,从新运行该文件sh index_search_mapping.sh
五、查问启动后果
curl http://ip:9200/index?pretty#查问字段curl http://ip:9200/_cat/nodes #查问节点curl http://ip:9200/_cat/health #查问集群衰弱,greencurl http://ip:9200/_cat/shards #查问集群分片状态
六、数据量查问
curl http://ip:9200/one_index/_stats #查问某一个index下的数据量curl http://ip:9200/one_index,two_index/_stats #查问多个index的数据量,应用,隔开curl http://ip:9200/_all/_stats #查问所有index下的数据量# 返回search、fetch、get、index、bulk、segment、countscurl http://ip:9200/_cat/count/index #只查问某个index下的文档数,如果不加index,则查问所有的index的文档总数
七、search-guard为es集群配置auth
1、装置search-guard插件和ssl插件
查问es的版本
curl ip:9200# 后果中的number数据即代表版本号
装置search-guard https://repo1.maven.org/maven...
找到对应的版本,下载即可
或者应用命令行下载,es目录下
bin/elasticsearch-plugin install -b com.floragunn:search-guard-5:5.3.0-12
装置search-guard-ssl https://repo1.maven.org/maven...
命令行
bin/elasticsearch-plugin install -b com.floragunn:search-guard-ssl:5.3.0-22
留神:当es版本较高时,可能并不需要这两个都存在,取search-guard即可
2、生成es证书文件
下载search-guard源码工具,生成证书的工具
git clone https://github.com/floragunncom/search-guard-ssl.git
批改ca配置
cd search-guard-ssl/example-pki-scripts/etc/vi root-ca.conf # 根证书配置 0.domainComponent = "www.test.com” # 域名 1.domainComponent = "www.test.com" # 域名 organizationName = "Test" # 组织名称 organizationalUnitName = "Test Root CA" # 组织单位名称 commonName = "Test Root CA" # 通用名称 vi signing-ca.conf # 签名证书配置 0.domainComponent = "www.test.com” # 域名 1.domainComponent = "www.test.com" # 域名 organizationName = "Test" # 组织名称 organizationalUnitName = "Test Signing CA" # 组织单位名称 commonName = "Test Signing CA" # 通用名称
留神:
以上信息填写,必须保障和生成证书时信息统一
批改sh文件 返回example-pki-scripts目录下,批改example.sh文件:
#!/bin/bashset -e./clean.sh./gen_root_ca.sh 12345678 12345678./gen_node_cert.sh 0 12345678 12345678&& ./gen_node_cert.sh 1 12345678 12345678 && ./gen_node_cert.sh 2 12345678 12345678./gen_client_node_cert.sh test 12345678 12345678./gen_client_node_cert.sh test 12345678 12345678
参数阐明:
./gen_root_ca.sh 12345678 12345678
第一个参数为CA_PASS,即CA明码(根证书明码)
第二个参数为TS_PASS,即TS明码(truststore,信赖证书明码)
./gen_node_cert.sh 0 12345678 12345678
第一个参数为node编号,生成证书后的文件名为node-0*
第二个参数为KS_PASS(keystore文件明码)
第三个参数为CA_PASS
./gen_client_node_cert.sh test 12345678
第一个参数为客户端节点名称,生成证书后的文件名为test*
第二个参数为KS_PASS
第三个参数为CA_PASS
生成证书,运行example.sh
sh example.sh# 在当前目录下会生成证书文件
3、配置es,启动search-guard
将生成的各个节点的证书,别离copy到各个节点上
# 将node-0-keystore.jks和truststore.jks复制到es的config目录下cp node-0-keystore.jks ~/elasticsearch/config/cp truststore.jks ~/elasticsearch/config/# 将test-keystore.jks和truststore.jks复制到es的plugins/search-guard-2/sgconfig目录下cp test-keystore.jks ~/elasticsearch/plugins/search-guard-2/sgconfig/cp truststore.jks ~/elasticsearch/plugins/search-guard-2/sgconfig/
留神:
放弃证书的一致性,因而只须要在一台机器上生成CA证书即可
批改es的配置文件config/elaticsearch.yml
在之前批改的根底上,减少如下配置
配置sslsearchguard.ssl.transport.enabled: truesearchguard.ssl.transport.keystore_filepath: node-0-keystore.jkssearchguard.ssl.transport.keystore_password: 12345678searchguard.ssl.transport.truststore_filepath: truststore.jkssearchguard.ssl.transport.truststore_password: 12345678searchguard.ssl.transport.enforce_hostname_verification: falsesearchguard.ssl.transport.resolve_hostname: false# 配置https# http配置,这里我只是为了测试不便,配置完,应该设置为truesearchguard.ssl.http.enabled: falsesearchguard.ssl.http.keystore_filepath: node-0-keystore.jkssearchguard.ssl.http.keystore_password: 12345678searchguard.ssl.http.truststore_filepath: truststore.jkssearchguard.ssl.http.truststore_password: 12345678# CN为生成CA证书时填写的信息,即./gen_client_node_cert.sh test 12345678 命令的第一个参数searchguard.authcz.admin_dn:- CN=test, OU=client, O=client, L=Test, C=DE
启动es
4、将search-guard的配置写入es中
增加权限
chmod -R 777 plugins/search-guard-5/tools/sgadmin.sh
配置格局
./plugins/search-guard-5/tools/sgadmin.sh -cn clustername -h hostname -cd plugins/search-guard-5/sgconfig -ks plugins/search-guard-5/sgconfig/admin-keystore.jks -kspass password -ts plugins/search-guard-5/sgconfig/truststore.jks -tspass password -nhnv
留神:
clustername为集群的名称
hostname为elasticsearch.yml 文件中 network.host 的值
password生成证书设置的明码
以上配置生成的命令为
./plugins/search-guard-5/tools/sgadmin.sh -cn es-nlp -h 192.168.124.18 -cd plugins/search-guard-5/sgconfig -ks plugins/search-guard-5/sgconfig/test-keystore.jks -kspass 12345678 -ts plugins/search-guard-5/sgconfig/truststore.jks -tspass 12345678 -nhnv
5、增加es用户及明码
生成md5加密明码
chmod -R 777 plugins/search-guard-2/tools/hash.shcd plugins/search-guard-2/tools/plugins/search-guard-2/tools/hash.sh -p 123456# 保留生成的hash明码
增加用户及明码
vim plugins/search-guard-5/sgconfig/sg_internal_users.ymlsunww: hash: 加密后的字符串 # password: 123456 # 最初一行时password提醒,避免遗记
增加用户的权限
vim plugins/search-guard-5/sgconfig/sg_roles_mapping.ymlag_all_access: users: - admin - sunww# 增加所有权限给sunww用户
从新将配置写入es中失效
./plugins/search-guard-5/tools/sgadmin.sh -cn es-nlp -h 192.168.124.18 -cd plugins/search-guard-5/sgconfig -ks plugins/search-guard-5/sgconfig/test-keystore.jks -kspass 12345678 -ts plugins/search-guard-5/sgconfig/truststore.jks -tspass 12345678 -nhnv
6、测试
curl http://sunww:123456@127.0.0.1:9200curl -u sunww:123456 http://127.0.0.1:9200curl --user sunww:123456 http://127.0.0.1:9200
过儿,你学废了吗?