es-安装部署
1、下载安装包
我下载的是7.16.2的版本,jdk需要11版本
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-16-2
2、上传到服务器并解压
tar -zxvf elasticsearch-7.16.2-linux-x86_64.tar.gz
3、创建用户
Elasticsearch不允许root用户直接运行,可以直接试试,会报错can not run elasticsearch as root,所以要创建新用户,在root用户下创建新用户esuser
useradd esuser #创建一个esuser的用户chown -R esuser /opt/elasticsearch/elasticsearch-7.16.2/ #将这个文件夹权限赋给esuser
4、创建data和logs文件夹
mkdir /home/elasticsearch/data mkdir /home/elasticsearch/logs chown -R esuser /home/elasticsearch/data chown -R esuser /home/elasticsearch/logs
5、修改elasticsearch.yml文件
cluster.name: cluster001 ---集群名称,单机的也可以配个名字
node.name: node01 ---节点名
path.data: /home/elasticsearch/data ---data文件的存储位置
path.logs: /home/elasticsearch/logs ---log文件的存储位置
network.host: 0.0.0.0 ----设置成这个表示所有ip都可以访问
http.port: 9200 ----http端口,区别于transport端口9300
http.cors.enabled: true ----设置允许外部浏览器访问,下面的设置也是为了这个
http.cors.allow-origin: "*"
cluster.initial_master_nodes: ["node01"] -----集群初始化时的可作为master节点的节点列表
bootstrap.memory_lock: true ---启动时锁定内存,运行中就会禁用交换区
6、修改jvm.options文件
初始内存和最大内存大小设置,官网强烈建议设置成一样大小的
-Xms32g
-Xmx32g
7、配置 /etc/sysctl.conf
# vim /etc/sysctl.conf
vm.max_map_count=655360
修改后执行 sysctl -p 使之生效
8、启动
su esuser bin/elasticsearch -d 后台启动
安装ik分词器
下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
版本选择:一定要选择和安装的es同版本的ik分词器版本,比如我需要下载elasticsearch-analysis-ik-7.16.2.zip
找到安装后的plugins文件夹,在下面创建一个ik文件夹(因为这个zip解压后没有一个父文件夹),然后将zip包放在ik下,unzip解压,启动es即可
部署中可能出现的问题
1、jdk8不支持7.16.2的es版本
这个是jdk版本需要使用11的,我下载的安装包是有捆绑jdk的,那么就用自带的捆绑的,因为bin/elasticsearch 这个脚本启动时会调用 bin/elasticsearch-env这个脚本,打开后者,修改如下
# now set the path to java if [ ! -z "$ES_JAVA_HOME" ]; then ------意思是如果存在ES_JAVA_HOME环境变量 JAVA="$ES_JAVA_HOME/bin/java" JAVA_TYPE="ES_JAVA_HOME" elif [ ! -z "$JAVA_HOME" ]; then ------如果存在JAVA_HOME环境变量,下面改为还是用ES_JAVA_HOME(es安装包boundled的JDK) # fallback to JAVA_HOME echo "warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME" >&2 JAVA="$ES_JAVA_HOME/bin/java" -------JAVA_HOME改为ES_JAVA_HOME JAVA_TYPE="ES_JAVA_HOME" -------JAVA_HOME改为ES_JAVA_HOME else # use the bundled JDK (default) if [ "$(uname -s)" = "Darwin" ]; then # macOS has a different structure JAVA="$ES_HOME/jdk.app/Contents/Home/bin/java" else JAVA="$ES_HOME/jdk/bin/java" fi JAVA_TYPE="bundled JDK" fi
2、esuser权限不足
2022-03-09 16:07:29,043 main ERROR Null object returned for RollingFile in Appenders. 2022-03-09 16:07:29,043 main ERROR Null object returned for RollingFile in Appenders. 2022-03-09 16:07:29,043 main ERROR Unable to locate appender "rolling" for logger config "root" 2022-03-09 16:07:29,044 main ERROR Unable to locate appender "rolling_old" for logger config "root" 2022-03-09 16:07:29,044 main ERROR Unable to locate appender "index_indexing_slowlog_rolling_old" for logger config "index.indexing.slowlog.index" 2022-03-09 16:07:29,044 main ERROR Unable to locate appender "index_indexing_slowlog_rolling" for logger config "index.indexing.slowlog.index" 2022-03-09 16:07:29,045 main ERROR Unable to locate appender "audit_rolling" for logger config "org.elasticsearch.xpack.security.audit.logfile.LoggingAuditTrail" 2022-03-09 16:07:29,045 main ERROR Unable to locate appender "index_search_slowlog_rolling_old" for logger config "index.search.slowlog" 2022-03-09 16:07:29,045 main ERROR Unable to locate appender "index_search_slowlog_rolling" for logger config "index.search.slowlog" 2022-03-09 16:07:29,046 main ERROR Unable to locate appender "deprecation_rolling_old" for logger config "org.elasticsearch.deprecation" 2022-03-09 16:07:29,046 main ERROR Unable to locate appender "deprecation_rolling" for logger config "org.elasticsearch.deprecation" uncaught exception in thread [main] ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/home/elasticsearch/data/nodes]; Likely root cause: java.nio.file.AccessDeniedException: /home/elasticsearch/data/nodes at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384) at java.nio.file.Files.createDirectory(Files.java:674) at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781) at java.nio.file.Files.createDirectories(Files.java:767) at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:300) at org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:224) at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:298) at org.elasticsearch.node.Node.<init>(Node.java:427) at org.elasticsearch.node.Node.<init>(Node.java:309) at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:234) at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:234) at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434) at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166) at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:157) at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77) at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112) at org.elasticsearch.cli.Command.main(Command.java:77) at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:122) at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) For complete error details, refer to the log at /home/elasticsearch/logs/node152.log
这个是因为第四步创建了data和logs文件夹后,没有chown给esuser赋权限的原因
3、没有配置discovery
[2022-03-09T16:41:37,002][ERROR][o.e.b.Bootstrap ] [node152] node validation exception [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch. bootstrap check failure [1] of [1]: 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
配置这个:cluster.initial_master_nodes: ["node01"] ,node01是配置的node.name值
4、geoip报错,不影响启动和使用
[2022-03-11T10:33:04,296][ERROR][o.e.i.g.GeoIpDownloader ] [node152] exception during geoip databases update java.net.UnknownHostException: geoip.elastic.co at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) ~[?:1.8.0_181] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_181] at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_181] at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673) ~[?:?] at sun.net.NetworkClient.doConnect(NetworkClient.java:175) ~[?:?] at sun.net.www.http.HttpClient.openServer(HttpClient.java:463) ~[?:?] at sun.net.www.http.HttpClient.openServer(HttpClient.java:558) ~[?:?] at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264) ~[?:?] at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367) ~[?:?] at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) ~[?:?] at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156) ~[?:?] at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050) ~[?:?] at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) ~[?:?] at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564) ~[?:?] at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492) ~[?:?] at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) ~[?:1.8.0_181] at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347) ~[?:?] at org.elasticsearch.ingest.geoip.HttpClient.lambda$get$0(HttpClient.java:55) ~[ingest-geoip-7.16.2.jar:7.16.2] at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_181] at org.elasticsearch.ingest.geoip.HttpClient.doPrivileged(HttpClient.java:97) ~[ingest-geoip-7.16.2.jar:7.16.2] at org.elasticsearch.ingest.geoip.HttpClient.get(HttpClient.java:49) ~[ingest-geoip-7.16.2.jar:7.16.2] at org.elasticsearch.ingest.geoip.HttpClient.getBytes(HttpClient.java:40) ~[ingest-geoip-7.16.2.jar:7.16.2] at org.elasticsearch.ingest.geoip.GeoIpDownloader.fetchDatabasesOverview(GeoIpDownloader.java:135) ~[ingest-geoip-7.16.2.jar:7.16.2] at org.elasticsearch.ingest.geoip.GeoIpDownloader.updateDatabases(GeoIpDownloader.java:123) ~[ingest-geoip-7.16.2.jar:7.16.2] at org.elasticsearch.ingest.geoip.GeoIpDownloader.runDownloader(GeoIpDownloader.java:260) [ingest-geoip-7.16.2.jar:7.16.2] at org.elasticsearch.ingest.geoip.GeoIpDownloaderTaskExecutor.nodeOperation(GeoIpDownloaderTaskExecutor.java:97) [ingest-geoip-7.16.2.jar:7.16.2] at org.elasticsearch.ingest.geoip.GeoIpDownloaderTaskExecutor.nodeOperation(GeoIpDownloaderTaskExecutor.java:43) [ingest-geoip-7.16.2.jar:7.16.2] at org.elasticsearch.persistent.NodePersistentTasksExecutor$1.doRun(NodePersistentTasksExecutor.java:42) [elasticsearch-7.16.2.jar:7.16.2] at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:777) [elasticsearch-7.16.2.jar:7.16.2] at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26) [elasticsearch-7.16.2.jar:7.16.2] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
原因:此版本默认开启了GeoIp功能,默认启动下会去官网默认地址下获取最新Ip的GEO信息
增加配置 ingest.geoip.downloader.enabled: false即可
5、host无法识别
[2022-03-11T10:30:25,370][WARN ][o.e.d.SeedHostsResolver ] [node152] failed to resolve host [node152:9300]
我的其中一个配置是:discovery.zen.ping.unicast.hosts: ["node152:9300"]
这是因为node152没有配置到host里,无法识别,改成ip或者修改hosts文件添加进去