arthas监控elasticsearch(7.x)

arthas介绍

准备

  • 准备docker环境
name port
centos_arthas 3658:3658
docker run -tid --name centos_arthas -p 3658:3658 --privileged=true centos:latest /sbin/init
docker exec -it centos_arthas /bin/bash

配置修改

  • 此处的配置修改按照本站之前博客路径进行修改
  • 创建,修改java.policy文件
touch /opt/es/config/java.policy
vi /opt/es/config/java.policy
#修改如下
grant codeBase "file:${user.home}/.arthas/lib/-" {
    permission java.io.FilePermission "${user.home}/.arthas/-", "read,write";
    permission java.io.FilePermission "${user.home}/logs/arthas/-", "read,write,delete";
    permission java.lang.RuntimePermission "createClassLoader";
    permission java.lang.RuntimePermission "getClassLoader";
    permission java.lang.RuntimePermission "modifyThreadGroup";
    permission java.lang.RuntimePermission "modifyThread";
    permission java.lang.RuntimePermission "shutdownHooks";
    permission java.lang.RuntimePermission "accessClassInPackage.sun.reflect";
    permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.protocol.http";
    permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
    permission java.net.SocketPermission "127.0.0.1:3658", "listen,resolve";
    permission java.net.SocketPermission "127.0.0.1:8563", "listen,resolve";
    permission java.net.SocketPermission "*", "accept";
};
#增加jvm启动参数
echo "-Djava.security.policy=file:///opt/es/config/java.policy" >> /opt/es/config/jvm.options
  • 修改/opt/es/jdk/conf/security/java.policy配置
vi /opt/es/jdk/conf/security/java.policy
#增加如下配置
grant {
    permission org.elasticsearch.ThreadPermission "modifyArbitraryThreadGroup";
    permission org.elasticsearch.ThreadPermission "modifyArbitraryThread";
};


grant {
    permission java.io.FilePermission "<<ALL FILES>>", "read,write";
    permission java.util.PropertyPermission "JM.LOG.PATH", "write";
    permission java.lang.RuntimePermission "*";
    permission java.lang.reflect.ReflectPermission "*";
    permission java.net.SocketPermission "*", "connect,listen,resolve,accept";
    permission ognl.OgnlInvokePermission "*";
};

  • 启动elasticsearch
/opt/es/bin/elasticsearch -d

安装arthas

  • 配置环境变量(这里使用es自带的jdk)
echo 'export JAVA_HOME=/opt/es/jdk' >>  ~/.bashrc
echo 'export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' >> ~/.bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
chmod +x ~/.bashrc
source ~/.bashrc
  • 安装arthas
[elastic@3f24eb371050 opt]$ curl -O https://arthas.aliyun.com/arthas-boot.jar
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  135k  100  135k    0     0   217k      0 --:--:-- --:--:-- --:--:--  217k
[elastic@3f24eb371050 opt]$ java -jar arthas-boot.jar --repo-mirror aliyun --use-http
[INFO] arthas-boot version: 3.4.4
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 513 org.elasticsearch.bootstrap.Elasticsearch
1
[INFO] Start download arthas from remote server: http://arthas.aliyun.com/download/3.4.4?mirror=aliyun
[INFO] File size: 11.94 MB, downloaded size: 4.32 MB, downloading ...
[INFO] File size: 11.94 MB, downloaded size: 7.45 MB, downloading ...
[INFO] File size: 11.94 MB, downloaded size: 9.85 MB, downloading ...
[INFO] Download arthas success.
[INFO] arthas home: /home/elastic/.arthas/lib/3.4.4/arthas
[INFO] Try to attach process 513
[INFO] Attach process 513 success.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
 /  O   |  .--. ''--.  .--'|  '--'  | /  O   '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |      |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'


wiki      https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
version   3.4.4
pid       513
time      2020-11-30 05:37:25

[arthas@513]$ shutdown        ##安装完成后先退出增加--target-ip参数启动
  • 启动
[elastic@3f24eb371050 opt]$ java -jar arthas-boot.jar  --target-ip 0.0.0.0
[INFO] arthas-boot version: 3.4.4
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 513 org.elasticsearch.bootstrap.Elasticsearch
1
[INFO] arthas home: /home/elastic/.arthas/lib/3.4.4/arthas
[INFO] Try to attach process 513
[INFO] Attach process 513 success.
[INFO] arthas-client connect 0.0.0.0 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
 /  O   |  .--. ''--.  .--'|  '--'  | /  O   '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |      |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'


wiki      https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
version   3.4.4
pid       513
time      2020-11-30 05:39:45

[arthas@513]$ dashboard
  • 监控数据,成功启动
ID   NAME                          GROUP          PRIORITY  STATE     %CPU      DELTA_TIM TIME      INTERRUPT DAEMON
-1   C1 CompilerThread0            -              -1        -         0.23      0.011     0:2.577   false     true
-1   C2 CompilerThread0            -              -1        -         0.13      0.006     0:9.784   false     true
153  Timer-for-arthas-dashboard-02 system         5         RUNNABLE  0.08      0.004     0:0.055   false     true
151  arthas-NettyHttpTelnetBootstr system         5         RUNNABLE  0.06      0.003     0:0.086   false     true
19   elasticsearch[3f24eb371050][s main           5         TIMED_WAI 0.06      0.003     0:0.599   false     true
43   elasticsearch[3f24eb371050][m main           5         TIMED_WAI 0.05      0.002     0:0.032   false     true
45   elasticsearch[3f24eb371050][m main           5         TIMED_WAI 0.04      0.002     0:0.023   false     true
-1   VM Periodic Task Thread       -              -1        -         0.04      0.002     0:0.391   false     true
-1   VM Thread                     -              -1        -         0.01      0.000     0:0.225   false     true
18   elasticsearch[3f24eb371050][[ main           5         TIMED_WAI 0.01      0.000     0:0.101   false     true
-1   Sweeper thread                -              -1        -         0.0       0.000     0:0.159   false     true
Memory                    used    total    max     usage    GC
heap                      264M    989M     989M    26.73%   gc.parnew.count               8
par_eden_space            190M    273M     273M    69.70%   gc.parnew.time(ms)            138
par_survivor_space        26M     34M      34M     77.56%   gc.concurrentmarksweep.count  2
cms_old_gen               47M     682M     682M    7.00%    gc.concurrentmarksweep.time(m 39
nonheap                   126M    137M     -1      92.30%   s)
codeheap_'non-nmethods'   1M      2M       5M      27.30%
metaspace                 97M     104M     -1      93.26%

Runtime
os.name                                                     Linux
os.version                                                  4.19.76-linuxkit
java.version                                                13.0.2
java.home                                                   /opt/es/jdk
systemload.average                                          0.00
processors                                                  6
uptime

通过web访问arthas

  • 增加--target-ip参数(上面的操作步骤中已经加过了)
  • 通过宿主机浏览器进行访问(http://localhost:3658
原文地址:https://www.cnblogs.com/liwangcai/p/14060875.html