redhat7安装elasticsearch详解
下载地址,官网https://www.elastic.co/downloads/past-releases,下载自己需要的版本
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.1.tar.gz 我安装的是这个版本的,
首先使用root用户
1)、新建一个es的用户,保证该用户可使用内存在8GB以上
2)、修改 /etc/sysctl.conf 在文件末尾添加
vm.max_map_count=262144
关闭文件后,在控制台输入:
sysctl -p
输出中应该包含vm.max_map_count = 262144
3)、修改 /etc/security/limits.conf,在文件当中修改或在文件末尾添加
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
4)、修改/etc/security/limits.d/90-nproc.conf
修改如下内容: 根据电脑的不同,这个可以不要,
* soft nproc 1024
修改为
* soft nproc 2048
下载,解压 tar -zxvf elasticsearch-5.1.1.tar
创建目录并修改权限
mkdir -vp elasticsearch/backup 递归创建文件夹
chmod 777 /home/elasticsearch/backup
修改配置文件 elasticsearch.yml
将文件中的这行注释解开,ip改成自己本机的ip
#network.host: 192.168.0.1
如
network.host:192.168.1.155
在yml文件末尾添加: /home/elasticsearch/backup是你备份的路径,这个路径需要赋权给其他用户
path.repo: ["/home/elasticsearch/backup"],
进入bin目录启动
[[email protected] bin]# ./elasticsearch
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
因为版本安全问题,不允许采用root帐号启动,所以我们要添加一个用户。
#添加一个用户:elasticsearch
$useradd elasticsearch
#给用户elasticsearch设置密码,连续输入2次
$passwd elasticsearch
#创建一个用户组 es
groupadd es
#分配 elasticsearch 到 es 组
usermod -G elasticsearch es
#这里注意下,如果提示用户“es”不存在,那么是因为服务器版本问题,你可以换成 usermod -G es elasticsearch ,也就是用户和用户组对调一下使用。
#在elasticsearch 根目录下,给定用户权限。-R表示逐级(N层目录) , * 表示 任何文件
chown -R elasticsearch.es *
#切换到elasticsearch用户
su elasticsearch
继续启动
[[email protected] bin]# ./elasticsearch
还是会报错,因为权限问题,没有elasticsearch目录的权限
java.io.FileNotFoundException: /home/es/elasticsearch-2.2.0/logs/elasticsearch.log (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:221)
at java.io.FileOutputStream.(FileOutputStream.java:142)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:223)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:842)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:768)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:648)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:514)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:440)
at org.elasticsearch.common.logging.log4j.LogConfigurator.configure(LogConfigurator.java:128)
at org.elasticsearch.bootstrap.Bootstrap.setupLogging(Bootstrap.java:204)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:258)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
log4j:ERROR Either File or DatePattern options are not set for appender [file].
log4j:ERROR setFile(null,true) call failed.
chmod -R 777 elasticsearch解压目录/
这个是所有人都可以访问,测试环境可以这样玩
上面所有工作做好之后,就可以正常启动elasticsearch了
[[email protected] bin]$ ./elasticsearch
[2019-02-26T16:54:05,081][INFO ][o.e.n.Node ] [] initializing ...
[2019-02-26T16:54:05,169][INFO ][o.e.e.NodeEnvironment ] [YyfBpNP] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [35.7gb], net total_space [49.9gb], spins? [unknown], types [rootfs]
[2019-02-26T16:54:05,170][INFO ][o.e.e.NodeEnvironment ] [YyfBpNP] heap size [1.9gb], compressed ordinary object pointers [unknown]
[2019-02-26T16:54:05,177][INFO ][o.e.n.Node ] node name [YyfBpNP] derived from node ID [YyfBpNPvQ2emrlBvPjQn0Q]; set [node.name] to override
[2019-02-26T16:54:05,179][INFO ][o.e.n.Node ] version[5.1.1], pid[26133], build[5395e21/2016-12-06T12:36:15.409Z], OS[Linux/3.10.0-693.el7.x86_64/i386], JVM[Oracle Corporation/Java HotSpot(TM) Server VM/1.8.0_191/25.191-b12]
[2019-02-26T16:54:05,877][INFO ][c.c.m.Dictionary ] [Dict Loading] chars loaded time=12ms, line=12638, on file=chars.dic
[2019-02-26T16:54:05,878][INFO ][c.c.m.Dictionary ] [Dict Loading] words loaded time=1ms, line=14, on file=words-my.dic
[2019-02-26T16:54:06,038][INFO ][c.c.m.Dictionary ] [Dict Loading] words loaded time=160ms, line=157202, on file=words.dic
[2019-02-26T16:54:06,039][INFO ][c.c.m.Dictionary ] [Dict Loading] unit loaded time=1ms, line=22, on file=units.dic
[2019-02-26T16:54:07,191][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [aggs-matrix-stats]
[2019-02-26T16:54:07,191][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [ingest-common]
[2019-02-26T16:54:07,191][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [lang-expression]
[2019-02-26T16:54:07,192][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [lang-groovy]
[2019-02-26T16:54:07,192][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [lang-mustache]
[2019-02-26T16:54:07,192][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [lang-painless]
[2019-02-26T16:54:07,192][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [percolator]
[2019-02-26T16:54:07,192][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [reindex]
[2019-02-26T16:54:07,192][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [transport-netty3]
[2019-02-26T16:54:07,192][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded module [transport-netty4]
[2019-02-26T16:54:07,192][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-icu]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-ik]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-kuromoji]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-mmseg]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-phonetic]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-pinyin]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-smartcn]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-stconvert]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-stempel]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [analysis-ukrainian]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [discovery-azure-classic]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [discovery-ec2]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [discovery-file]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [discovery-gce]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [ingest-attachment]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [ingest-geoip]
[2019-02-26T16:54:07,193][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [ingest-user-agent]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [lang-javascript]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [lang-python]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [mapper-attachments]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [mapper-murmur3]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [mapper-size]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [repository-azure]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [repository-gcs]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [repository-hdfs]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [repository-s3]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [sql]
[2019-02-26T16:54:07,194][INFO ][o.e.p.PluginsService ] [YyfBpNP] loaded plugin [store-smb]
[2019-02-26T16:54:07,346][WARN ][d.m.attachment ] [mapper-attachments] plugin has been deprecated and will be replaced by [ingest-attachment] plugin.
[2019-02-26T16:54:11,415][INFO ][o.e.n.Node ] initialized
[2019-02-26T16:54:11,415][INFO ][o.e.n.Node ] [YyfBpNP] starting ...
[2019-02-26T16:54:11,516][INFO ][o.e.t.TransportService ] [YyfBpNP] publish_address {192.168.1.155:9300}, bound_addresses {192.168.1.155:9300}
[2019-02-26T16:54:11,520][INFO ][o.e.b.BootstrapCheck ] [YyfBpNP] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2019-02-26T16:54:14,599][INFO ][o.e.c.s.ClusterService ] [YyfBpNP] new_master {YyfBpNP}{YyfBpNPvQ2emrlBvPjQn0Q}{222l-Si-QC-JQYrnrL3h9Q}{192.168.1.155}{192.168.1.155:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2019-02-26T16:54:14,611][INFO ][o.e.h.HttpServer ] [YyfBpNP] publish_address {192.168.1.155:9200}, bound_addresses {192.168.1.155:9200}
[2019-02-26T16:54:14,611][INFO ][o.e.n.Node ] [YyfBpNP] started
[2019-02-26T16:54:14,663][INFO ][o.w.a.d.Monitor ] try load config from /usr/local/elasticsearch-rtf-master/elasticsearch-rtf-master/config/analysis-ik/IKAnalyzer.cfg.xml
[2019-02-26T16:54:14,664][INFO ][o.w.a.d.Monitor ] try load config from /usr/local/elasticsearch-rtf-master/elasticsearch-rtf-master/plugins/analysis-ik/config/IKAnalyzer.cfg.xml
[2019-02-26T16:54:14,891][INFO ][o.w.a.d.Monitor ] [Dict Loading] custom/mydict.dic
[2019-02-26T16:54:14,891][INFO ][o.w.a.d.Monitor ] [Dict Loading] custom/single_word_low_freq.dic
[2019-02-26T16:54:14,894][INFO ][o.w.a.d.Monitor ] [Dict Loading] custom/ext_stopword.dic
[2019-02-26T16:54:15,502][INFO ][o.e.g.GatewayService ] [YyfBpNP] recovered [1] indices into cluster_state
[2019-02-26T16:54:16,044][INFO ][o.e.c.r.a.AllocationService] [YyfBpNP] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[jiangxi][2]] ...]).
在浏览器中访问elasticsearch 其中number就是elasticsearch的版本
在安装目录的lib包中,有elasticsearch的jar包,也可以查看到elasticsearch的版本
elasticsearch常用命令 都是在linux命令行输入的命令
下面有换行的是yaml表达式,前面的空格是俩个空格,不是tab键 千万记得,不然会报错
下面有换行的是yaml表达式,前面的空格是俩个空格,不是tab键 千万记得,不然会报错
创建仓库
在命令行输入命令:
curl -XPUT 'http://192.168.1.155:9200/_snapshot/es_backup' -d '
{
"type": "fs",
"settings":
{
"compress" : "true",
"location": "/home/elasticsearch/backup"
}
}'
//查看仓库 在命令行输入
curl -XGET 'http://192.168.1.155:9200/_snapshot/es_backup?pretty'
//创建索引
curl -XPUT 'http://192.168.1.155:9200/_snapshot/es_backup/snapshot_1' -d '
{
"indices": "hunan",
"ignore_unavailable": "true",
"include_global_state": false,
"partial": "false"
}'
//查看索引
curl '192.168.1.155:9200/_cat/indices?v'
//备份数据查看
curl -XGET 'http://192.168.1.155:9200/_snapshot/es_backup/snapshot_1'
数据恢复
在命令行输入:
curl -XPOST 'http://192.168.1.155:9200/_snapshot/es_backup/snapshot_1/_restore' -d '{
"indices": "hunan",
"ignore_unavailable": "true",
"include_global_state": false
}'
我们通常用用_cat API检测集群是否健康。 确保9200端口号可用:
curl 'localhost:9200/_cat/health?v'