本文共 8368 字,大约阅读时间需要 27 分钟。
操作系统: centos7
elasticsearch:5.2.2我采用的是下载压缩包的方式安装,也可以利用rpm
来安装,但是,这样会把配置文件和数据文件,弄到各个不同的目录,这我很不喜欢。我喜欢像window
目录一样,都在一起。
由于elasticsearch
是用Java
写的,所以需要安装至少Java8
以上版本。
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.tar.gzsha1sum elasticsearch-5.2.2.tar.gz tar -xzf elasticsearch-5.2.2.tar.gz
其中sha1sum
是用校验文件大小的。过程是:
sha1sum elasticsearch-5.2.2.tar.gz
显示出来的值与下载文件的值进行比对。
命令tar -xzf elasticsearch-5.2.2.tar.gz
是解压缩包。
参考网上大神的个人习惯:
1、在/opt
中创建setups
文件夹,专门用来存放下载的第三方安装包。 我目前是放在centos7
中home
中的下载
目录中。 2、在/usr
中创建programe_files
文件夹,类似于window
中的Programe Files
文件夹。
所以我把解压好的elasticsearch-5.2.2
文件夹剪切到/usr/programe_files/
中。
1、用命令行启动
我们先进入到/usr/programe_files/elasticsearch-5.2.2
./bin/elasticsearch
启动后可以在命令行中看到:
[2017-03-12T16:46:42,692][INFO ][o.e.n.Node ] [] initializing ...[2017-03-12T16:46:43,427][INFO ][o.e.e.NodeEnvironment ] [XGt4N_o] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [12.8gb], net total_space [16.9gb], spins? [unknown], types [rootfs][2017-03-12T16:46:43,428][INFO ][o.e.e.NodeEnvironment ] [XGt4N_o] heap size [1.9gb], compressed ordinary object pointers [true][2017-03-12T16:46:43,429][INFO ][o.e.n.Node ] node name [XGt4N_o] derived from node ID [XGt4N_oLREa1KnaK-rm_8A]; set [node.name] to override[2017-03-12T16:46:43,517][INFO ][o.e.n.Node ] version[5.2.2], pid[4179], build[f9d9b74/2017-02-24T17:26:45.835Z], OS[Linux/3.10.0-514.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_102/25.102-b14][2017-03-12T16:46:48,699][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [aggs-matrix-stats][2017-03-12T16:46:48,699][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [ingest-common][2017-03-12T16:46:48,699][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [lang-expression][2017-03-12T16:46:48,699][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [lang-groovy][2017-03-12T16:46:48,700][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [lang-mustache][2017-03-12T16:46:48,700][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [lang-painless][2017-03-12T16:46:48,700][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [percolator][2017-03-12T16:46:48,700][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [reindex][2017-03-12T16:46:48,700][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [transport-netty3][2017-03-12T16:46:48,700][INFO ][o.e.p.PluginsService ] [XGt4N_o] loaded module [transport-netty4][2017-03-12T16:46:48,701][INFO ][o.e.p.PluginsService ] [XGt4N_o] no plugins loaded[2017-03-12T16:46:58,283][INFO ][o.e.n.Node ] initialized[2017-03-12T16:46:58,296][INFO ][o.e.n.Node ] [XGt4N_o] starting ...[2017-03-12T16:46:59,502][INFO ][o.e.t.TransportService ] [XGt4N_o] publish_address {192.168.116.128:9300}, bound_addresses {192.168.116.128:9300}[2017-03-12T16:46:59,566][INFO ][o.e.b.BootstrapChecks ] [XGt4N_o] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks[2017-03-12T16:47:00,959][INFO ][o.e.m.j.JvmGcMonitorService] [XGt4N_o] [gc][young][2][7] duration [863ms], collections [1]/[1.3s], total [863ms]/[4.7s], memory [83.7mb]->[29.8mb]/[1.9gb], all_pools {[young] [60.1mb]->[1022.5kb]/[66.5mb]}{[survivor] [8.3mb]->[8.3mb]/[8.3mb]}{[old] [15.2mb]->[20.8mb]/[1.9gb]}[2017-03-12T16:47:00,960][WARN ][o.e.m.j.JvmGcMonitorService] [XGt4N_o] [gc][2] overhead, spent [863ms] collecting in the last [1.3s][2017-03-12T16:47:02,906][INFO ][o.e.c.s.ClusterService ] [XGt4N_o] new_master {XGt4N_o}{XGt4N_oLREa1KnaK-rm_8A}{7juSSOMuRDmD0-2EZTpfwQ}{192.168.116.128}{192.168.116.128:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)[2017-03-12T16:47:03,565][INFO ][o.e.g.GatewayService ] [XGt4N_o] recovered [0] indices into cluster_state[2017-03-12T16:47:03,770][INFO ][o.e.h.HttpServer ] [XGt4N_o] publish_address {192.168.116.128:9200}, bound_addresses {192.168.116.128:9200}[2017-03-12T16:47:03,770][INFO ][o.e.n.Node ] [XGt4N_o] started
其中192.168.116.128
是我自己配的,后面讲,你们应该显示的是localhost
这时它会占用命令行窗口,ctrl+c
即可关闭elasticsearch
。
我们在另开一个命令行窗口执行:
curl http://localhost:9200
返回的结果类似于:
{ "name" : "XGt4N_o", "cluster_name" : "elasticsearch", "cluster_uuid" : "qhA446xpR5WYwcVa5gTz7Q", "version" : { "number" : "5.2.2", "build_hash" : "f9d9b74", "build_date" : "2017-02-24T17:26:45.835Z", "build_snapshot" : false, "lucene_version" : "6.4.1" }, "tagline" : "You Know, for Search"}
由于上面的启动方式会占用命令行,所以可以作为守护进程来启动,这样就不会占用命令行窗口啦。
要作为守护进程: ① 添加-d
参数即可。 ./bin/elasticsearch -d -p pid
后面的-p pid
会在当前目录中生成pid
文件,里面记录了进程的IP。
要关闭elasticsearch
我们在当前目录执行:
kill `cat pid`
注意:
假设我们不小心把pid
文件删除啦,执行上面的语句是有问题的。 这时我们需要手动这么做: ①执行ps -ef | grep elasticsearch
找到进程id
②执行kill 找的的进程id
。 但是呢?我觉得这样启动记得命令太多了,所以我写成了一个shell
脚本。
#!/bin/bashif [ $1 == "start" ];then./bin/elasticsearch -d -p pidelif [ $1 == "stop" ];thenkill `cat pid`elseecho "Please make sure the position variable is start or stop."fi
这样我就可以这样来执行:
(elasticsearch.sh
脚本是保存在elasticsearch
的安装目录中。) 启动命令:
[yutao@localhost elasticsearch-5.2.2]$ ./elasticsearch.sh start
关闭命令
[yutao@localhost elasticsearch-5.2.2]$ ./elasticsearch.sh stop
我这种方式还有一个弊端就是每次都要进入安装目录才可以执行命令,要是能像Linux
命令那样到哪里都能执行就好了。
解决办法:
①把脚本放到usr/bin
的目录中 ②调整好脚本 我调整后的脚本:
#!/bin/bash# 先进入相关目录cd /usr/programe_files/elasticsearch-5.2.2/if [ $1 == "start" ];then./bin/elasticsearch -d -p pidelif [ $1 == "stop" ];thenkill `cat pid`elseecho "Please make sure the position variable is start or stop."fi
这里对系统几个bin
目录进行讲解:
bin: bin为binary的简写,主要放置系统的必备执行文件,例如: cat、cp、chmod df、dmesg、gzip、kill、ls、mkdir、more、mount、rm、su、tar等。 /usr/bin: 主要放置应用程序工具的必备执行文件,例如: c++、g++、gcc、chdrv、diff、dig、du、eject、elm、free、gnome*、 gzip、htpasswd、kfm、ktop、last、less、locale、m4、make、man、mcopy、ncftp、 newaliases、nslookup passwd、quota、smb*、wget等。 /sbin: 主要放置系统管理的必备程序,例如: cfdisk、dhcpcd、dump、e2fsck、fdisk、halt、ifconfig、ifup、 ifdown、init、insmod、lilo、lsmod、mke2fs、modprobe、quotacheck、reboot、rmmod、 runlevel、shutdown等。 /usr/sbin: 主要放置网路管理的必备程序,例如: dhcpd、httpd、imap、in.*d、inetd、lpd、named、netconfig、nmbd、samba、sendmail、squid、swap、tcpd、tcpdump等
因此可以任意在/usr/bin目录下建脚本就会形成新的系统命令。
虽然就此安装好了,但是我的centos7
是安装在VMware workspace12
虚拟机中的。但是我想在我的本机window
的浏览器中也能通过192.168.116.128:9200
来访问。
进入到config
中
vim elasticsearch.yml
找到:
# Set the bind address to a specific IP (IPv4 or IPv6):##network.host: 192.168.0.1
将其修改为:
# Set the bind address to a specific IP (IPv4 or IPv6):##network.host: 192.168.0.1network.host: 192.168.116.128 #这里ip地址随便填,我是填写虚拟机的IP地址
保存后,再次启动elasticsearch
。
错误两个:
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
大概的意思就是:
①系统的vm.max_map_count
设置过小,至少需要262144
才行。 ②elasticsearch
的进程描述文件过小至少需要65536
,而现在只有4096
。 ①解决办法:
修改配置文件:
sudo vim /etc/sysctl.conf
在文件最后添加:
vm.max_map_count=262144
查看是否添加成功:
sudo sysctl -p
显示:
vm.max_map_count = 262144
②解决办法
执行
sudo vim /etc/security/limits.conf
在文件最后添加:
yutao soft nofile 65536yutao hard nofile 65536
其中yutao
为登陆centos7
的用户名。
这里需要注意一定要重启系统否则不会生效。
再次启动elasticsearch
就不会保错啦。
关闭centos7
的防火墙。(最笨的方法)
service firewall status
如果是启动的,可以执行关闭操作:
service firewall stop
我关闭后的状态为:
Redirecting to /bin/systemctl status firewalld.service● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead) since 日 2017-03-12 16:13:15 CST; 1h 43min ago Docs: man:firewalld(1) Process: 850 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS) Main PID: 850 (code=exited, status=0/SUCCESS)
如果你选择关闭防火墙这将是因小失大,而且你重启虚拟机后,防火墙还是会重新开启。
我们要知道,linux
默认开启的是22端口,其他端口并没有开启,所以我们需要给elasticsearch
开个后门,也就是开放端口。
# centos7 默认是安装了firewalld防火墙的# 永久开放端口firewall-cmd --permanent --add-port={ 9200/tcp,9100/tcp,5601/tcp}# 重启防火墙firewall-cmd --reload# 查看防火墙状态firewall-cmd --state# 显示目前的设定firewall-cmd --list-all
上面我是开放了elasticsearch--9200
,elasticsearch-head --9100
,kibana --5601
端口。
再在window
的浏览器中输入http://192.168.116.128:9200/
参考链接: