@zhangyy
2021-10-22T08:38:00.000000Z
字数 7004
阅读 738
ElasticSearch系列
系统:rhel8.3x64cat /etc/hosts----192.168.100.41 rhel01.flyfish.cn192.168.100.42 rhel02.flyfish.cn192.168.100.43 rhel03.flyfish.cn192.168.100.44 rhel04.flyfish.cn192.168.100.45 rhel05.flyfish.cn192.168.100.46 rhel06.flyfish.cn192.168.100.47 rhel07.flyfish.cn192.168.100.48 rhel08.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 /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.targetcat >> /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
做esadmin 的无密码登录/esdb/soft/fgssh/fgssh -user esadmin -hosts "rhel01.flyfish.cn rhel02.flyfish.cn rhel03.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 rhel02.flyfish.cn:/esdb/scp -r /esdb/jdk-14.0.2 rhel03.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/soft/elasticsearch-7.9.0/* /esdb/esapp/esapp9200/vim /esdb/esapp/esapp9200/config/elasticsearch.yml---cluster.name: flyfishescluster1node.name: 192.168.100.41path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: truenode.data: truebootstrap.memory_lock: truebootstrap.system_call_filter: falsenetwork.host: 192.168.100.41http.port: 9200transport.tcp.port: 9300http.cors.enabled: truehttp.cors.allow-origin: "*"discovery.seed_hosts: ["192.168.100.41:9300","192.168.100.42:9300","192.168.100.43:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5cluster.initial_master_nodes:["192.168.100.41:9300","192.168.100.42:9300","192.168.100.43:9300"]---
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/jvm.options----Xms256m-Xmx256m-Xmn100m-Xss228K-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
cd /esdb/esapp/esapp9200scp -r * esadmin@rhel02.flyfish.cn:/esdb/esapp/esapp9200/scp -r * esadmin@rhel03.flyfish.cn:/esdb/esapp/esapp9200/
rhel02.flyfish.cn 主机:vi /esdb/esapp/esapp9200/config/elasticsearch.yml---cluster.name: flyfishescluster1node.name: 192.168.100.42path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: truenode.data: truebootstrap.memory_lock: truebootstrap.system_call_filter: falsenetwork.host: 192.168.100.42http.port: 9200transport.tcp.port: 9300http.cors.enabled: truehttp.cors.allow-origin: "*"discovery.seed_hosts: ["192.168.100.41:9300","192.168.100.42:9300","192.168.100.43:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5cluster.initial_master_nodes: ["192.168.100.41:9300","192.168.100.42:9300","192.168.100.43:9300"]---
rhel03.flyfish.cn 主机:vi /esdb/esapp/esapp9200/config/elasticsearch.yml----cluster.name: flyfishescluster1node.name: 192.168.100.43path.data: /esdb/esdata/esdata9200path.logs: /esdb/eslog/eslog9200node.master: truenode.data: truebootstrap.memory_lock: truebootstrap.system_call_filter: falsenetwork.host: 192.168.100.43http.port: 9200transport.tcp.port: 9300http.cors.enabled: truehttp.cors.allow-origin: "*"discovery.seed_hosts: ["192.168.100.41:9300","192.168.100.42:9300","192.168.100.43:9300"]discovery.zen.fd.ping_timeout: 60sdiscovery.zen.fd.ping_retries: 5cluster.initial_master_nodes: ["192.168.100.41:9300","192.168.100.42:9300","192.168.100.43:9300"]----
启动es (全部机器执行)/esdb/esapp/esapp9200/bin/elasticsearch

测试:curl http://192.168.100.41:9200/_cat/nodes

curl http://192.168.100.41:9200/_cat/health?pretty -H 'Content-Type: application/json'

启动脚本:mkdir -p /esdb/scripts/vi /esdb/scripts/es_start.sh----#!/bin/bashecho "es cluster all node start..."for 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 $host "/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/bash----ps -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 fgesdb01 fgesdb02 fgesdb03#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_*.shscp -r /esdb/scripts rhel02.flyfish.cn:/esdb/scp -r /esdb/scripts rhel03.flyfish.cn:/esdb/ssh rhel02.flyfish.cn "chmod -R 755 /esdb/scripts"ssh rhel03.flyfish.cn "chmod -R 755 /esdb/scripts"/esdb/scripts/es_stop.sh/esdb/scripts/es_start.sh
设置集群分片与副本: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
