在我的实验环境里,由于安装的时候采用了默认的配置方案,所以ES被安装在了根分区,而根分区的数据用量快满了,因此,我有了如题所示的,调整ES的数据目录的需求。

[root@elk software]# df -h
Filesystem                                                     Size  Used Avail Use% Mounted on
/dev/sda3                                                       18G   12G  6.5G  64% /
devtmpfs                                                       1.9G     0  1.9G   0% /dev
tmpfs                                                          1.9G     0  1.9G   0% /dev/shm
tmpfs                                                          1.9G   13M  1.9G   1% /run
tmpfs                                                          1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                                                      297M  133M  165M  45% /boot
tmpfs                                                          378M   12K  378M   1% /run/user/42
tmpfs                                                          378M     0  378M   0% /run/user/0
/dev/mapper/vg_elasticsearch_data_01-lv_elasticsearch_data_01   19G   45M   18G   1% /data_elasticsearch
[root@elk software]# 
[root@elk software]# cat /etc/elasticsearch/elasticsearch.yml | grep "path.data"
path.data: /var/lib/elasticsearch
[root@elk software]# 

如上,可以看到我的根分区目前不具备扩展性(LVM);
并且,用于全新存放ES数据的路径我已经创建好了:
【/data_elasticsearch】
该路径使用了LVM。

下面,开始做ES的数据目录调整的操作。


停服务:ElasticSearch

[root@elk ~]# service elasticsearch status
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-09-25 23:32:11 PDT; 3min 3s ago
     Docs: http://www.elastic.co
 Main PID: 13021 (java)
    Tasks: 60
   CGroup: /system.slice/elasticsearch.service
           ├─13021 /usr/share/elasticsearch/jdk/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCM...
           └─13119 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Sep 25 23:32:11 elk.adamhuan.com systemd[1]: Started Elasticsearch.
Sep 25 23:32:12 elk.adamhuan.com elasticsearch[13021]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in ver...elease.
Hint: Some lines were ellipsized, use -l to show in full.
[root@elk ~]# 
[root@elk ~]# service elasticsearch stop
Stopping elasticsearch (via systemctl):                    [  OK  ]
[root@elk ~]# 
[root@elk ~]# service elasticsearch status
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Wed 2019-09-25 23:35:18 PDT; 6s ago
     Docs: http://www.elastic.co
  Process: 13021 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=143)
 Main PID: 13021 (code=exited, status=143)

Sep 25 23:32:11 elk.adamhuan.com systemd[1]: Started Elasticsearch.
Sep 25 23:32:12 elk.adamhuan.com elasticsearch[13021]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in ver...elease.
Sep 25 23:35:17 elk.adamhuan.com systemd[1]: Stopping Elasticsearch...
Sep 25 23:35:18 elk.adamhuan.com systemd[1]: Stopped Elasticsearch.
Hint: Some lines were ellipsized, use -l to show in full.
[root@elk ~]# 

查看新的地址的权限:

[root@elk ~]# ls -ltrd /data_elasticsearch/
drwxr-xr-x 3 elasticsearch elasticsearch 4096 Sep 25 23:23 /data_elasticsearch/
[root@elk ~]# 

修改配置文件中的路径:

[root@elk ~]# cat /etc/elasticsearch/elasticsearch.yml | grep "path.data"
path.data: /var/lib/elasticsearch
[root@elk ~]# 
[root@elk ~]# sed -i '/path.data/s/\/var\/lib\/elasticsearch/\/data_elasticsearch/g' /etc/elasticsearch/elasticsearch.yml 
[root@elk ~]# 
[root@elk ~]# cat /etc/elasticsearch/elasticsearch.yml | grep "path.data"                                                 
path.data: /data_elasticsearch
[root@elk ~]# 

将旧的ES的数据移动到新的路径中。

先查看下旧的数据:

[root@elk ~]# du -sh /var/lib/elasticsearch/
1.4G    /var/lib/elasticsearch/
[root@elk ~]# 
[root@elk ~]# ls -ltr /var/lib/elasticsearch/
total 0
drwxr-sr-x 3 elasticsearch elasticsearch 15 Aug 29 19:56 nodes
[root@elk ~]# 
[root@elk ~]# ls -ltr /var/lib/elasticsearch/nodes/
total 0
drwxr-sr-x 4 elasticsearch elasticsearch 52 Sep 25 23:32 0
[root@elk ~]# 
[root@elk ~]# ls -ltr /var/lib/elasticsearch/nodes/0/
total 4
-rw-r--r--  1 elasticsearch elasticsearch    0 Aug 29 19:56 node.lock
drwxr-sr-x 18 elasticsearch elasticsearch 4096 Sep 25 21:43 indices
drwxr-sr-x  2 elasticsearch elasticsearch   66 Sep 25 23:34 _state
[root@elk ~]# 

然后,执行移动:

[root@elk ~]# cp -rf /var/lib/elasticsearch/* /data_elasticsearch/
[root@elk ~]# 
[root@elk ~]# ls -ltr /data_elasticsearch/
total 20
drwx------ 2 elasticsearch elasticsearch 16384 Sep 25 23:23 lost+found
drwxr-xr-x 3 root          root           4096 Sep 25 23:46 nodes
[root@elk ~]# 
[root@elk ~]# ls -ltr /data_elasticsearch/nodes/
total 4
drwxr-xr-x 4 root root 4096 Sep 25 23:46 0
[root@elk ~]# 
[root@elk ~]# du -sh /data_elasticsearch/
1.4G    /data_elasticsearch/
[root@elk ~]# 

修改新路径的权限:

[root@elk ~]# chown -R elasticsearch.elasticsearch /data_elasticsearch/
[root@elk ~]# 
[root@elk ~]# ls -ltr /data_elasticsearch/
total 20
drwx------ 2 elasticsearch elasticsearch 16384 Sep 25 23:23 lost+found
drwxr-xr-x 3 elasticsearch elasticsearch  4096 Sep 25 23:46 nodes
[root@elk ~]# 

重启服务:ElasticSearch

[root@elk ~]# service elasticsearch start
Starting elasticsearch (via systemctl):                    [  OK  ]
[root@elk ~]# 
[root@elk ~]# service elasticsearch status
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-09-25 23:49:12 PDT; 57s ago
     Docs: http://www.elastic.co
 Main PID: 14452 (java)
    Tasks: 62
   CGroup: /system.slice/elasticsearch.service
           ├─14452 /usr/share/elasticsearch/jdk/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCM...
           └─14550 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Sep 25 23:49:12 elk.adamhuan.com systemd[1]: Started Elasticsearch.
Sep 25 23:49:13 elk.adamhuan.com elasticsearch[14452]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in ver...elease.
Hint: Some lines were ellipsized, use -l to show in full.
[root@elk ~]# 
[root@elk ~]# ps -ef | grep elasticsearch
root      14407  14201  0 23:48 pts/2    00:00:00 tail -f /var/log/elasticsearch/elasticsearch.log
elastic+  14452      1 98 23:49 ?        00:01:07 /usr/share/elasticsearch/jdk/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -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-9588371653914362242 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/lib/elasticsearch -XX:ErrorFile=/var/log/elasticsearch/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=/var/log/elasticsearch/gc.log:utctime,pid,tags:filecount=32,filesize=64m -Djava.locale.providers=COMPAT -Dio.netty.allocator.type=unpooled -XX:MaxDirectMemorySize=536870912 -Des.path.home=/usr/share/elasticsearch -Des.path.conf=/etc/elasticsearch -Des.distribution.flavor=default -Des.distribution.type=rpm -Des.bundled_jdk=true -cp /usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch -p /var/run/elasticsearch/elasticsearch.pid --quiet
elastic+  14550  14452  0 23:49 ?        00:00:00 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
root      14691  12273  0 23:50 pts/1    00:00:00 grep --color=auto elasticsearch
[root@elk ~]# 

这样,就好了。


说点什么

avatar

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

  Subscribe  
提醒
隐藏
变装