原创

Centos安装ElasticSearch

1 下载ElasticSearch 命令如下:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.tar.gz

mv elasticsearch-5.3.0.tar.gz /opt

cd /opt

tar -xzvf elasticsearch-5.3.0.tar.gz

cd elasticsearch-5.3.0/

 

2 启动方法

cd /bin

./elasticsearch

 

可能会出现以下错误:

1 error='Cannot allocate memory' (errno=12):

error='Cannot allocate memory

 

可能的解决方案:

由于elasticsearch5.0默认分配jvm空间大小为2g,需要改小一点

vim config/jvm.options 

-Xms2g    -Xms512m

-Xmx2g    -Xmx512m

更改之后启动报错:

# su elsearch  ./elasticsearch  [ 2a17  [2a17  [2a17  [ 2a17  [ 2a17  [2a17  [2a17  [ 2a17  [ 2a17  [2a17  [2a17  [ 2a17  [ 2a17  [2a17  [2a17  [ 2a17  [ 2a17  -ØS-1STIS:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  -06-13T16:59  : 36,425] [IUFO  : 38, 588] [INFO  : 38,  : 38,  : 38,  : 38, 591] [IUFO  : 38,  : 38,  : 38,  : 38, 593] [ luF0  n . Node  e. ronment  e . UodeEnvi ronment  n. Node  n. Node  e n.Uode  . PluginsService  . PluginsService  . PluginsService  e.p. PluginsService  . PluginsService  . PluginsService  . PluginsService  . PluginsService  . PluginsService  . PluginsService  . PluginsService  C] initializing  Cd_04scI] using [I] data paths, mounts [f/  Cd_04scI] heap size [I. 9gb], compressed ordir  node name [d_NscI] derived from node 10 [d (  version [5.4. I],  pidC586), buildC2cfeødf/2Ø17•  DWI arguments [-Xms2g,  Cd_04scI]  Cd_04scI]  Cd_04scI]  Cd_04scI]  Cd_04scI]  Cd_04scI]  Cd_04scI]  Cd_04scI]  Cd_04scI]  Cd_04scI]  Cd_04scI]  loaded  loaded  loaded  loaded  loaded  loaded  loaded  loaded  loaded  loaded  module  modul e  modul e  module  module  modul e  modul e  module  module  modul e  -Xmx2g, -XX: +1JseConcMi  aggs-matrix-stats)  [ingest-common]  Clang-expression]  lang- groovy)  Clang-mus tache]  Clang-painless]  [percolator]  C reindex]  [transport-netty3]  C transport-netty4]  no plugins loaded  Killed

是因为改了内存之后,ElasticSearch的内存不够,无法启动了,我们使用Swap区域,间接的加大一下内存试试:

参考:https://www.cnblogs.com/zdz8207/p/linux-centos-swap.html

dd if=/dev/zero of=/var/swap bs=1024 count=2048000

mkswap /var/swap

mkswap -f /var/swap

vi /etc/fstab

最后一行添加

/var/swap swap swap defaults 0 0

 

再次启动发现可以启动了。

 

如果启动时候报这个错:can not run elasticsearch as root

can not run elasticsearch as root

 

是因为在LinuxElasticSearch是不允许用ROOT用户启动和运行的,

所以需要创建一个非root用户,以非root用户来起es

groupadd es# 创建用户组elk

useradd es -g es -p ***# 创建新用户es,-g es设置其用户组为 es,-p 密码为***

chown -R es:es /opt  # 更改 /opt 文件夹及内部文件的所属用户及组为 es:es

su es # 切换到非root用户es下来

因为是作为测试用例的机器,我们开放外网端口和IP使所有的IP都可以进行远程连接,修改config/elasticsearch.yml中的network.host为network.host: 0.0.0.0以便让外网任何IP都能来访问

可能会出现错误:

(1) max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

(2) max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

切换到root用户,然后

vim /etc/security/limits.conf

* soft nofile 300000

* hard nofile 300000

* soft nproc 102400

* soft memlock unlimited

* hard memlock unlimited

还有可能的错误:

vm.max_map_count is too low

 

先要切换到root用户;

然后可以执行以下命令,设置 vm.max_map_count ,但是重启后又会恢复为原值。

sysctl -w vm.max_map_count=262144

持久性的做法是在 /etc/sysctl.conf 文件中修改 vm.max_map_count 参数:

echo "vm.max_map_count=262144" > /etc/sysctl.conf

sysctl -p

 

还有可能出现的问题::max number of threads [1024] for user [lish] likely too low, increase to at least[4096]

解决:切换到root用户,进入limits.d目录下修改配置文件。

vi /etc/security/limits.d/90-nproc.conf

修改如下内容:

 

* soft nproc 1024

#修改为

* soft nproc 2048

可以参考:https://www.cnblogs.com/duanxuan/p/6473005.html

3 如何使用:

可以安装ElasticSearch-Head做可视化监控,然后用SpringBoot的方法调用。

正文到此结束
Loading...