注意: 1. 需要安装jdk11 2.Elasticsearch不能用root账号启动
-
安装JDK11
-
创建elasitcsearch的用户和组:esuser/esuser
#创建组 groupadd esuser #创建用户 useradd -r -g esuser esuser #设置密码 passwd esuser
-
安装
#下载 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.9-linux-x86_64.tar.gz #解压 tar -vxf elasticsearch-7.17.9-linux-x86_64.tar.gz #授权给esuser chown -R esuser:esuser elasticsearch-7.17.9 #切换到esuser用户 su - esuser #启动服务 cd /sino/elasticsearch-7.17.9/bin ./elasticsearch & # 查看服务 ps -ef|grep elasticsearch -bash-4.2$ ps -ef|grep elasticsearch esuser 38211 38117 45 14:09 pts/2 00:00:54 /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-1.el7_9.x86_64/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j2.formatMsgNoLookups=true -Djava.locale.providers=SPI,COMPAT --add-opens=java.base/java.io=ALL-UNNAMED -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=/tmp/elasticsearch-17699362327497274207 -XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -Xms1024m -Xmx1024m -XX:MaxDirectMemorySize=536870912 -Des.path.home=/sino/elasticsearch-7.17.9 -Des.path.conf=/sino/elasticsearch-7.17.9/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /sino/elasticsearch-7.17.9/lib/* org.elasticsearch.bootstrap.Elasticsearch esuser 38384 38211 0 14:09 pts/2 00:00:00 /sino/elasticsearch-7.17.9/modules/x-pack-ml/platform/linux-x86_64/bin/controller esuser 38738 38117 0 14:11 pts/2 00:00:00 grep --color=auto elasticsearch #查看端口 netstat -an|grep 9200 -bash-4.2$ netstat -an|grep 9200 tcp6 0 0 127.0.0.1:9200 :::* LISTEN tcp6 0 0 ::1:9200 :::* LISTEN #使用curl打开本地9200端口 curl http://127.0.0.1:9200 -bash-4.2$ curl http://127.0.0.1:9200 { "name" : "localhost.localdomain", "cluster_name" : "elasticsearch", "cluster_uuid" : "YQ12G4DoTUKAaGkPwMe7Gw", "version" : { "number" : "7.17.9", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "ef48222227ee6b9e70e502f0f0daa52435ee634d", "build_date" : "2023-01-31T05:34:43.305517834Z", "build_snapshot" : false, "lucene_version" : "8.11.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } #浏览器无法访问9200端口 http://172.16.103.27:9200 #修改配置 config/elasticsearch.yml cd /sino/elasticsearch-7.17.9/config vi elasticsearch.yml #找到 #network.host: 192.168.0.1, 删除前面 # ip改为 0.0.0.0 #重启ES:(先pkill掉ES,然后再启动ES,下同) pkill -f elasticsearch cd /sino/elasticsearch-7.17.9/bin ./elasticsearch & #提示启动失败,原因是系统参数过小需要修改参数 ERROR: [3] bootstrap checks failed. You must address the points described in the following [3] lines before starting Elasticsearch. bootstrap check failure [1] of [3]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] bootstrap check failure [2] of [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] bootstrap check failure [3] of [3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured ERROR: Elasticsearch did not exit normally - check the logs at /sino/elasticsearch-7.17.9/logs/elasticsearch.log [2023-03-23T14:18:41,574][INFO ][o.e.n.Node ] [localhost.localdomain] stopping ... [2023-03-23T14:18:41,599][INFO ][o.e.n.Node ] [localhost.localdomain] stopped [2023-03-23T14:18:41,599][INFO ][o.e.n.Node ] [localhost.localdomain] closing ... [2023-03-23T14:18:41,624][INFO ][o.e.n.Node ] [localhost.localdomain] closed #切换到root账号 sudo su root #修改虚拟内存 vi /etc/sysctl.conf #在最后添加 vm.max_map_count=262144 sysctl -p #修改打开文件最大数量;此文件修改后 需要重新登录用户,才会生效。 vi /etc/security/limits.conf #添加如下内容, 注意*号不要去掉 * soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096 #修改普通用户启动线程数限制 vi /etc/security/limits.d/20-nproc.conf * soft nproc 1024 #修改为 * soft nproc 4096 #切换到esuser账户 sudo su esuser vi /sino/elasticsearch-7.17.9/config/elasticsearch.yml #添加参数 #集群名称 cluster.name: sino-es-cluster #节点名称 node.name: node-1 #集群发现 discovery.seed_hosts: ["127.0.0.1"] #主节点 cluster.initial_master_nodes: ["node-1"] #关闭地图服务,否则启动会报错,但不影响使用 ingest.geoip.downloader.enabled: false #启动服务 cd /sino/elasticsearch-7.17.9/bin ./elasticsearch & #浏览器访问 http://172.16.103.27:9200/ 可正常打开 { "name" : "node-1", "cluster_name" : "sino-es-cluster", "cluster_uuid" : "YQ12G4DoTUKAaGkPwMe7Gw", "version" : { "number" : "7.17.9", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "ef48222227ee6b9e70e502f0f0daa52435ee634d", "build_date" : "2023-01-31T05:34:43.305517834Z", "build_snapshot" : false, "lucene_version" : "8.11.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
-
安装IK分词器插件(中文分词器)
#github地址 https://github.com/medcl/elasticsearch-analysis-ik #下载 wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.6/elasticsearch-analysis-ik-7.17.6.zip #将其拷贝到/plugin/ik 目录下,解压并删掉zip文件 #由于没有对应的7.17.9的版本,所以启动之前需要修改 plugin-descriptor.properties 中配置 elasticsearch.version=7.17.6 改为 elasticsearch.version=7.17.9 #最后重启服务即可,日志中可以看出已经加载插件 2023-03-23T19:19:18,150][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-voting-only-node] [2023-03-23T19:19:18,150][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-watcher] [2023-03-23T19:19:18,151][INFO ][o.e.p.PluginsService ] [node-1] loaded plugin [analysis-ik] [2023-03-23T19:19:18,151][INFO ][o.e.p.PluginsService ] [node-1] loaded plugin [analysis-pinyin] [2023-03-23T19:19:18,152][INFO ][o.e.p.PluginsService ] [node-1] loaded plugin [ingest-attachment]
-
安装pinyin插件(ES的pinyin插件,可以让ES具备通过汉字、拼音或者汉字拼音混合搜索的能力)
#github地址 https://github.com/medcl/elasticsearch-analysis-pinyin #下载 wget https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.17.5/elasticsearch-analysis-pinyin-7.17.5.zip #将其拷贝到/plugin/pinyin 目录下,解压并删掉zip文件 #由于没有对应的7.17.9的版本,所以启动之前需要修改 plugin-descriptor.properties 中配置 elasticsearch.version=7.17.6 改为 elasticsearch.version=7.17.9 #最后重启服务即可,日志中可以看出已经加载插件 2023-03-23T19:19:18,150][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-voting-only-node] [2023-03-23T19:19:18,150][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-watcher] [2023-03-23T19:19:18,151][INFO ][o.e.p.PluginsService ] [node-1] loaded plugin [analysis-ik] [2023-03-23T19:19:18,151][INFO ][o.e.p.PluginsService ] [node-1] loaded plugin [analysis-pinyin] [2023-03-23T19:19:18,152][INFO ][o.e.p.PluginsService ] [node-1] loaded plugin [ingest-attachment]
-
安装ingest-attachment(处理文档)
#下载 wget https://artifacts.elastic.co/downloads/elasticsearch-plugins/ingest-attachment/ingest-attachment-7.17.9.zip #将其拷贝到/plugin/ingest-attachment 目录下,解压并删掉zip文件 #最后重启服务即可,日志中可以看出已经加载插件 2023-03-23T19:19:18,150][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-voting-only-node] [2023-03-23T19:19:18,150][INFO ][o.e.p.PluginsService ] [node-1] loaded module [x-pack-watcher] [2023-03-23T19:19:18,151][INFO ][o.e.p.PluginsService ] [node-1] loaded plugin [analysis-ik] [2023-03-23T19:19:18,151][INFO ][o.e.p.PluginsService ] [node-1] loaded plugin [analysis-pinyin] [2023-03-23T19:19:18,152][INFO ][o.e.p.PluginsService ] [node-1] loaded plugin [ingest-attachment]
-
安装kibana(可视化的ES工具,通过kibana可以对ES进行很好的管理和操作)
#注意 kibana版本需要与elasticsearch对应 https://www.elastic.co/cn/support/matrix#matrix_compatibility #下载kibana wget https://artifacts.elastic.co/downloads/kibana/kibana-7.17.9-linux-x86_64.tar.gz #解压 tar -zxvf kibana-7.17.9-linux-x86_64.tar.gz cd /sino/kibana-7.17.9-linux-x86_64/config vi kibana.yml #修改如下 server.host: "172.16.103.27" elasticsearch.hosts: ["http://127.0.0.1:9200"] i18n.locale: "zh-CN" #修改目录权限 chown -R esuser:esuser kibana-7.17.9-linux-x86_64 #切换到esuser用户启动kubana服务 sudo su esuser cd /sino/kibana-7.17.9-linux-x86_64/bin ./kibana & #浏览器访问 http://172.16.103.27:5601/