1.1 基础环境
OS:Centos7.4
ES: elasticsearch-6.2.4.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz
执行解压命令:
tar -zxvf elasticsearch-6.2.4.tar.gz
解压完成后,会出现elasticsearch-6.2.4目录。
如果你是root用户启动的话,会报"can not run elasticsearch as root"的错误。因为安全问题elasticsearch不让用root用户直接运行,所以要创建新用户。
groupadd uncle
useradd -m -g uncle uncle
-r代码创建系统用户,-m代表创建用户主目录
passwd uncle
WXHWXH
root用户赋权:
mv /root/elasticsearch-6.2.4/ /home/uncle/
chown -R uncle.uncle /home/uncle/elasticsearch-6.2.4
uncle用户:
/home/uncle/elasticsearch-6.2.4/bin/elasticsearch
nohup /home/uncle/elasticsearch-6.2.4/bin/elasticsearch &
[2019-12-31T16:00:47,993][INFO ][o.e.n.Node ] [] initializing ...
[2019-12-31T16:00:48,092][INFO ][o.e.e.NodeEnvironment ] [HCMjxVu] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [25.5gb], net total_space [36.9gb], types [rootfs]
[2019-12-31T16:00:48,092][INFO ][o.e.e.NodeEnvironment ] [HCMjxVu] heap size [990.7mb], compressed ordinary object pointers [true]
[2019-12-31T16:00:48,093][INFO ][o.e.n.Node ] node name [HCMjxVu] derived from node ID [HCMjxVuFTWeojN_O0MKlog]; set [node.name] to override
[2019-12-31T16:00:48,094][INFO ][o.e.n.Node ] version[6.2.4], pid[20253], build[ccec39f/2018-04-12T20:37:28.497551Z], OS[Linux/3.10.0-693.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_131/25.131-b12]
[2019-12-31T16:00:48,094][INFO ][o.e.n.Node ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -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, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.T9V2sUZv, -XX:+HeapDumpOnOutOfMemoryError, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/home/uncle/elasticsearch-6.2.4, -Des.path.conf=/home/uncle/elasticsearch-6.2.4/config]
[2019-12-31T16:00:48,926][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [aggs-matrix-stats]
[2019-12-31T16:00:48,927][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [analysis-common]
[2019-12-31T16:00:48,927][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [ingest-common]
[2019-12-31T16:00:48,927][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [lang-expression]
[2019-12-31T16:00:48,927][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [lang-mustache]
[2019-12-31T16:00:48,927][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [lang-painless]
[2019-12-31T16:00:48,927][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [mapper-extras]
[2019-12-31T16:00:48,927][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [parent-join]
[2019-12-31T16:00:48,927][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [percolator]
[2019-12-31T16:00:48,927][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [rank-eval]
[2019-12-31T16:00:48,928][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [reindex]
[2019-12-31T16:00:48,928][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [repository-url]
[2019-12-31T16:00:48,928][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [transport-netty4]
[2019-12-31T16:00:48,928][INFO ][o.e.p.PluginsService ] [HCMjxVu] loaded module [tribe]
[2019-12-31T16:00:48,928][INFO ][o.e.p.PluginsService ] [HCMjxVu] no plugins loaded
[2019-12-31T16:00:51,685][INFO ][o.e.d.DiscoveryModule ] [HCMjxVu] using discovery type [zen]
[2019-12-31T16:00:52,290][INFO ][o.e.n.Node ] initialized
[2019-12-31T16:00:52,290][INFO ][o.e.n.Node ] [HCMjxVu] starting ...
[2019-12-31T16:00:52,443][INFO ][o.e.t.TransportService ] [HCMjxVu] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2019-12-31T16:00:52,451][WARN ][o.e.b.BootstrapChecks ] [HCMjxVu] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2019-12-31T16:00:52,452][WARN ][o.e.b.BootstrapChecks ] [HCMjxVu] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2019-12-31T16:00:55,595][INFO ][o.e.c.s.MasterService ] [HCMjxVu] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {HCMjxVu}{HCMjxVuFTWeojN_O0MKlog}{eNjvUmmeRU6Jc7-0lcz8rA}{127.0.0.1}{127.0.0.1:9300}
[2019-12-31T16:00:55,601][INFO ][o.e.c.s.ClusterApplierService] [HCMjxVu] new_master {HCMjxVu}{HCMjxVuFTWeojN_O0MKlog}{eNjvUmmeRU6Jc7-0lcz8rA}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {HCMjxVu}{HCMjxVuFTWeojN_O0MKlog}{eNjvUmmeRU6Jc7-0lcz8rA}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2019-12-31T16:00:55,625][INFO ][o.e.h.n.Netty4HttpServerTransport] [HCMjxVu] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2019-12-31T16:00:55,626][INFO ][o.e.n.Node ] [HCMjxVu] started
[2019-12-31T16:00:55,630][INFO ][o.e.g.GatewayService ] [HCMjxVu] recovered [0] indices into cluster_state
如果一切正常,Elasticsearch就会在默认的9200端口运行。这时,打开另一个命令行窗口,请求该端口:
curl localhost:9200
如果得到如下的返回,就说明启动成功了:
[root@pxc1 ~]# curl localhost:9200
{
"name" : "HCMjxVu",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "HLRiDRQzT7KUeVFzoZuyjg",
"version" : {
"number" : "6.2.4",
"build_hash" : "ccec39f",
"build_date" : "2018-04-12T20:37:28.497551Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
默认情况下,Elasticsearch 只允许本机访问,如果需要远程访问,可以修改 Elasticsearch 安装目录中的config/elasticsearch.yml文件,去掉network.host的注释,将它的值改成0.0.0.0,让任何人都可以访问,然后重新启动 Elasticsearch 。
vi /home/uncle/elasticsearch-6.2.4/config/elasticsearch.yml
55 network.host: 0.0.0.0
上面代码中,"network.host:"和"0.0.0.0"中间有个空格,不能忽略,不然启动会报错。线上服务不要这样设置,要设成具体的 IP。
错误一:max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解决:执行下面的命令:
sudo sysctl -w vm.max_map_count=262144
错误二:max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
sudo vim /etc/security/limits.conf
在limits.conf最下方加入下面两行(这里的yjclsx是之前2.4步骤中新建的用户名):
uncle hard nofile 65536
uncle soft nofile 65536