@zhangyy
2021-10-22T05:36:54.000000Z
字数 12942
阅读 359
ElasticSearch系列
系统:rhel8.3x64-1cat /etc/hosts----192.168.100.41 rhel01.flyfish.cn 协调节点192.168.100.42 rhel02.flyfish.cn 协调节点192.168.100.43 rhel03.flyfish.cn 协调节点192.168.100.44 rhel04.flyfish.cn 主节点192.168.100.45 rhel05.flyfish.cn 主机点192.168.100.46 rhel06.flyfish.cn 主节点192.168.100.47 rhel07.flyfish.cn 数据节点192.168.100.48 rhel08.flyfish.cn 数据节点192.168.100.49 rhel09.flyfish.cn 数据节点192.168.100.50 rhel10.flyfish.cn 扩容数据节点192.168.100.51 rhel11.flyfish.cn 扩容数据节点----先部署前面九台机器,后面 两台作为 扩容节点
全部系统配置:系统语言:echo "export LANG=en_US.UTF8" >> ~/.bash_profilecat ~/.bash_profile---分区:pvcreate /dev/sdbvgcreate esdatavg /dev/sdblvcreate -n esdatalv -L 100000M esdatavgmkfs.xfs /dev/esdatavg/esdatalv---vi /etc/fstab---/dev/esdatavg/esdatalv /esdb xfs defaults 0 0---mkdir /esdbmount /esdb
mkdir -p /esdb/softgroupadd -g 60001 esadminuseradd -u 61001 -g esadmin esadminchown -R esadmin:esadmin /esdbchmod -R 775 /esdbecho "esadmin" | passwd --stdin esadminsystemctl set-default multi-user.targetchown esadmin:esadmin -R /esdbcat >> /etc/security/limits.conf << EOFroot soft nofile 1048576root hard nofile 1048576esadmin soft nproc 1048576esadmin hard nproc 1048576esadmin soft nofile 1048576esadmin hard nofile 1048576esadmin soft stack 10240esadmin hard stack 32768esadmin hard memlock unlimitedesadmin soft memlock unlimitedEOF------cat >> /etc/sysctl.conf << EOFfs.aio-max-nr = 1048576fs.file-max = 6815744net.ipv4.ip_local_port_range = 1024 65535net.ipv4.tcp_mem = 786432 2097152 3145728net.ipv4.tcp_rmem = 4096 4096 16777216net.ipv4.tcp_wmem = 4096 4096 16777216net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1vm.swappiness=1vm.min_free_kbytes=204800vm.max_map_count=2048000kernel.pid_max=819200vm.zone_reclaim_mode=0#vm.nr_hugepages = 0EOFsysctl -p
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimehwclockecho "SELINUX=disabled" > /etc/selinux/configecho "#SELINUXTYPE=targeted " >> /etc/selinux/configcat /etc/selinux/configsetenforce 0systemctl stop firewalld.servicesystemctl disable firewalld.servicecat >> /home/esadmin/.vimrc << EOFmap <F10>:set paste<CR>map <F11>:set nopaste<CR>EOFshutdown -r now
做9台机器的esadmin 无密码登录做esadmin 的无密码登录/root/fgssh -user esadmin -hosts "rhel01.flyfish.cn rhel02.flyfish.cn rhel03.flyfish.cn rhel04.flyfish.cn rhel05.flyfish.cn rhel06.flyfish.cn rhel07.flyfish.cn rhel08.flyfish.cn rhel09.flyfish.cn" -advanced -exverify -confirmchmod 600 /home/esadmin/.ssh/config
su - esadmincd /esdb/tar zxvf /esdb/soft/jdk-14.0.2_linux-x64_bin.tar.gzscp -r /esdb/jdk-14.0.2 esadmin@rhel02.flyfish.cn:/esdb/scp -r /esdb/jdk-14.0.2 esadmin@rhel03.flyfish.cn:/esdb/scp -r /esdb/jdk-14.0.2 esadmin@rhel04.flyfish.cn:/esdb/scp -r /esdb/jdk-14.0.2 esadmin@rhel05.flyfish.cn:/esdb/scp -r /esdb/jdk-14.0.2 esadmin@rhel06.flyfish.cn:/esdb/scp -r /esdb/jdk-14.0.2 esadmin@rhel07.flyfish.cn:/esdb/scp -r /esdb/jdk-14.0.2 esadmin@rhel08.flyfish.cn:/esdb/scp -r /esdb/jdk-14.0.2 esadmin@rhel09.flyfish.cn:/esdb/
全部主机:su - esadmincat >> ~/.bash_profile << EOFexport JAVA_HOME=/esdb/jdk-14.0.2export PATH=/esdb/jdk-14.0.2/bin:$PATHexport LANG=en_US.UTF8EOFsource ~/.bash_profilejava -version


全部主机:mkdir -p /esdb/soft/mkdir -p /esdb/esapp/esapp9200mkdir -p /esdb/esdata/esdata9200mkdir -p /esdb/eslog/eslog9200chown esadmin:esadmin -R /esdb/


rhel01.flyfish.cn: 操作cd /esdb/softtar zxvf /esdb/soft/elasticsearch-7.9.0-linux-x86_64.tar.gzcp -r /esdb/elasticsearch-7.9.0/* /esdb/esapp/esapp9200

vi /esdb/esapp/esapp9200/bin/elasticsearch-env----export JAVA_HOME=/esdb/jdk-14.0.2export PATH=$JAVA_HOME/bin:$PATH----
vi /esdb/esapp/esapp9200/config/elasticsearch.yml----cluster.name: flyfishescluster1node.name: 192.168.100.41network.host: 192.168.100.41http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: falsenode.data: falsecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes:["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5----
vim /esdb/esapp/esapp9200/config/jvm.options-----Xms1g-Xmx1g-XX:+DisableExplicitGC-XX:HeapDumpPath=/esdb/eslog/eslog9200-XX:ErrorFile=/esdb/eslog/eslog9200/hs_err_pid%p.log9-:-Xlog:gc*,gc+age=trace,safepoint:file=/esdb/eslog/eslog9200/gc.log:utctime,pid,tags:filecount=32,filesize=64m----
同步所有主机:(所有节点都执行)scp -r rhel01.flyfish.cn:/esdb/esapp/esapp9200 /esdb/esapp/
rhel0(1-3).flyfish.cn 前三台做协调节点:rhel01.flyfish.cn:vi /esdb/esapp/esapp9200/config/elasticsearch.yml----cluster.name: flyfishescluster1node.name: 192.168.100.41network.host: 192.168.100.41http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: falsenode.data: falsecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes:["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5-----rhel02.flyfish.cn:vi /esdb/esapp/esapp9200/config/elasticsearch.yml----cluster.name: flyfishescluster1node.name: 192.168.100.42network.host: 192.168.100.42http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: falsenode.data: falsecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes:["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5----rhel03.flyfish.cn:vi /esdb/esapp/esapp9200/config/elasticsearch.yml---cluster.name: flyfishescluster1node.name: 192.168.100.43network.host: 192.168.100.43http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: falsenode.data: falsecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes:["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5---
rhel0(4-6).flyfish.cn做 主节点:rhel04.flyfish.cn:vi /esdb/esapp/esapp9200/config/elasticsearch.yml----cluster.name: flyfishescluster1node.name: 192.168.100.44network.host: 192.168.100.44http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: truenode.data: falsecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes:["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5-----rhel05.flyfish.cn:vi /esdb/esapp/esapp9200/config/elasticsearch.yml----cluster.name: flyfishescluster1node.name: 192.168.100.45network.host: 192.168.100.45http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: truenode.data: falsecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes:["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5----rhel06.flyfish.cn:vi /esdb/esapp/esapp9200/config/elasticsearch.yml---cluster.name: flyfishescluster1node.name: 192.168.100.46network.host: 192.168.100.46http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: truenode.data: falsecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes:["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5----
rhel0(7-9).flyfish.cn 做数据节点:rhel07.flyfish.cnvi /esdb/esapp/esapp9200/config/elasticsearch.yml---cluster.name: flyfishescluster1node.name: 192.168.100.47network.host: 192.168.100.47http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: falsenode.data: truecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes:["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5---rhel08.flyfish.cn:vi /esdb/esapp/esapp9200/config/elasticsearch.yml----cluster.name: flyfishescluster1node.name: 192.168.100.48network.host: 192.168.100.48http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: falsenode.data: truecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes: ["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5----rhel09.flyfish.cn:vi /esdb/esapp/esapp9200/config/elasticsearch.yml----cluster.name: flyfishescluster1node.name: 192.168.100.49network.host: 192.168.100.49http.port: 9200transport.tcp.port: 9300path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: falsenode.data: truecluster.remote.connect: falsehttp.cors.enabled: truehttp.cors.allow-origin: "*"bootstrap.memory_lock: truebootstrap.system_call_filter: falsecluster.initial_master_nodes: ["192.168.100.44:9300","192.168.100.45:9300","192.168.100.46:9300"]discovery.seed_hosts: ["192.168.100.44:9300", "192.168.100.45:9300", "192.168.100.46:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5----
mkdir -p /esdb/scriptsvim /esdb/script/es_start.sh----#!/bin/bashecho "es cluster all node start..."for hostm in rhel04.flyfish.cn rhel05.flyfish.cn rhel06.flyfish.cn#for host in `cat /esdb/scripts/es_host.sh | awk '{print $1}'`doecho "--------------------------------"echo $hostm "node es start..."ssh -n -T $hostm "/esdb/esapp/esapp9200/bin/elasticsearch -d >/dev/null 2>&1 &"echo $hostm "node es start cancel..."donesleep 120for hostd in rhel07.flyfish.cn rhel08.flyfish.cn rhel09.flyfish.cn#for host in `cat /esdb/scripts/es_host.sh | awk '{print $1}'`doecho "--------------------------------"echo $hostd "node es start..."ssh -n -T $hostd "/esdb/esapp/esapp9200/bin/elasticsearch -d >/dev/null 2>&1 &"echo $hostd "node es start cancel..."donesleep 120for host in rhel01.flyfish.cn rhel02.flyfish.cn rhel03.flyfish.cn#for host in `cat /esdb/scripts/es_host.sh | awk '{print $1}'`doecho "--------------------------------"echo $host "node es start..."ssh -n -T $h0st "/esdb/esapp/esapp9200/bin/elasticsearch -d >/dev/null 2>&1 &"echo $host "node es start cancel..."doneecho "es cluster all node start OK!"----
vi /esdb/scripts/es_kill.sh---#!/bin/bashps -ef|grep java|grep esapp|awk '{print $2}'|xargs kill -9vi /esdb/scripts/es_stop.sh#!/bin/bashecho "es cluster all node stop..."for host in rhel01.flyfish.cn rhel02.flyfish.cn rhel03.flyfish.cn rhel04.flyfish.cn rhel05.flyfish.cn rhel06.flyfish.cn rhel07.flyfish.cn rhel08.flyfish.cn rhel09.flyfish.cn#for host in `cat /esdb/scripts/host.sh | awk '{print $1}'`doecho "--------------------------------"echo $host "node es stop..."ssh -n -T $host "/esdb/scripts/es_kill.sh"echo $host "node es stop cancel..."doneecho "es cluster all node stop OK!"---chmod 755 /esdb/scripts/es_*.sh/esdb/scripts/es_stop.sh/esdb/scripts/es_start.sh
curl '192.168.100.44:9200/_cat/nodes?v'

curl -XPUT 192.168.100.41:9200/_template/all_index_shards -H 'Content-Type:application/json' -d '{"template": "*","settings": {"number_of_shards": 6,"number_of_replicas": "1"}}'

设置路由分片防止堆积在一台上面:curl -XPUT '192.168.100.41:9200/_cluster/settings' -H 'Content-Type: application/json' -d '{"transient": {"cluster.routing.allocation.same_shard.host": true}}'

插入数据:curl -XPOST http://192.168.100.41:9200/itpuxdb/_doc/?pretty -H 'Content-Type:application/json' -d '{"id" : "1","name" : "itpux001","city" : "上海","course" : "bigdata","teacher" : "flyfish","pxdate": "20200829"}'

查看数据:curl -XPOST 'http://192.168.100.41:9200/itpuxdb/_search?pretty' -H 'Content-Type:application/json'

curl http://192.168.100.41:9200/_cat/shards?v
