Centos 7.6搭建Skywalking6.5+es6.2.4
原文连接:https://www.cnblogs.com/duanxz/p/11904391.html
软件包版本
1、elasticsearch-6.2.4.tar.gz,下载地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz
2、kibana-6.2.4-linux-x86_64.tar.gz,下载地址:https://artifacts.elastic.co/downloads/kibana/kibana-6.2.4-linux-x86_64.tar.gz
3、apache-skywalking-apm-6.5.0.tar.gz,下载地址:http://mirrors.tuna.tsinghua.edu.cn/apache/skywalking/6.5.0/apache-skywalking-apm-6.5.0.tar.gz
将以上三个软件包上传至服务器/home/skywalking/路径下
注:skywalking6.0开始,最低要求elasticseach6.3.x及以上版本(之前安装上面的版本后,启动发现服务项及JVM等信息不能展示),我重新下了个https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz
一、安装ES
1、创建安装路径
mkdir /usr/local/es
2、解压软件包
tar -zxvf /usr/local/src/elasticsearch-6.3.2.tar.gz -C /usr/local/es
3、创建独立用户与组(root用户下创建设定)
(1)创建用户组
groupadd es
(2)创建用户es,并添加至用户组es
useradd -g es es
(3)设置密码
passwd es
New password:duanxz123
Retype new password:duanxz123
(4)使es用户拥有执行权限
visudo
root ALL=(ALL) ALL
es ALL=(ALL) ALL # 这个新增行
4、更改软件包属主属组
[root@localhost elasticsearch-6.2.4]# chown -R es:es /home/skywalking/es/elasticsearch-6.2.4/ [root@localhost elasticsearch-6.2.4]# ls -l /home/skywalking/elasticsearch-6.2.4.tar.gz bin/ config/ es-data/ es-logs/ lib/ LICENSE.txt logs/ modules/ NOTICE.txt plugins/ README.textile [root@localhost elasticsearch-6.2.4]# ls -l /home/skywalking/es/elasticsearch-6.2.4/ 总用量 224 drwxr-xr-x. 2 es es 4096 11月 21 19:36 bin drwxr-xr-x. 2 es es 75 11月 21 19:42 config drwxr-xr-x. 2 es es 6 11月 21 19:42 es-data drwxr-xr-x. 2 es es 174 11月 21 19:56 es-logs drwxr-xr-x. 2 es es 4096 4月 13 2018 lib -rw-r--r--. 1 es es 11358 4月 13 2018 LICENSE.txt drwxr-xr-x. 2 es es 30 11月 21 19:56 logs drwxr-xr-x. 16 es es 4096 4月 13 2018 modules -rw-r--r--. 1 es es 191887 4月 13 2018 NOTICE.txt drwxr-xr-x. 2 es es 6 4月 13 2018 plugins -rw-r--r--. 1 es es 9268 4月 13 2018 README.textile [root@localhost elasticsearch-6.2.4]#
5、切换到es用户,编辑配置文件,准备启动es
# 设定es群集名称 cluster.name: my-es-skywalking # es当前节点名称,用于区分不同节点 node.name: node-1 # 修改数据目录,此目录为自定义,需要在root用户下创建,且属主属组更改为es path.data: /home/skywalking/es/elasticsearch-6.2.4/es-data # 日志目录位置,需自己创建,方式同上 # yum安装则系统自定义,在软件版本或者系统升级时会被删除,所以建议修改 path.logs: /home/skywalking/es/elasticsearch-6.2.4/es-logs # elasticsearch官网建议生产环境需要设置bootstrap.memory_lock: true bootstrap.memory_lock: true # 监听访问地址为任意网段 network.host: 0.0.0.0 # 服务监听端口 http.port: 9200
6、编辑完成配置文件后,数据目录以及日志文件目录需要创建
sudo mkdir -p /home/skywalking/es/elasticsearch-6.2.4/es-data sudo mkdir -p /home/skywalking/es/elasticsearch-6.2.4/es-logs sudo chown -R es:es /data/ sudo chown -R es:es /var/log/es
7、准备工作完成,启动es
[es@root bin] cd /usr/local/es/elasticsearch-6.3.2/bin/
[es@root bin] ./elasticsearch # 加上 -d 参数,后台运行
需要jdk环境,配置jdk: vi /etc/profile #set java environment JAVA_HOME=/home/skywalking/jdk1.8 JRE_HOME=$JAVA_HOME/jre PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export JAVA_HOME JRE_HOME PATH CLASSPATH source /etc/profilejava -version
8、启动异常及解决之道
1)Caused by: java.lang.RuntimeException: can not run elasticsearch as root 解决之道: su es 然后,再./elasticsearch -d
2)Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file logs/gc.log due to Permission denied Exception in thread "main" org.elasticsearch.bootstrap.BootstrapException: java.nio.file.AccessDeniedException: /usr/local/es/elasticsearch-6.3.2/config/elasticsearch.keystore Likely root cause: java.nio.file.AccessDeniedException: /usr/local/es/elasticsearch-6.3.2/config/elasticsearch.keystore 因为第一次启动不小心用了root启动,导致用root生成了对应的文件。切换es账号之后,没有对应文件的权限导致,删除相关的东西即可。 解决之道: su root rm -rf /usr/local/es/elasticsearch-6.3.2/config/elasticsearch.keystore su es cd /usr/local/es/elasticsearch-6.3.2/bin/ ./elasticsearch
3)2019-05-30 23:17:54,794 main ERROR Unable to locate appender "deprecation_rolling" for logger config "org.elasticsearch.deprecation" [2019-05-30T23:17:54,954][WARN ][o.e.b.JNANatives ] Unable to lock JVM Memory: error=12, reason=Cannot allocate memory [2019-05-30T23:17:54,955][WARN ][o.e.b.JNANatives ] This can result in part of the JVM being swapped out. [2019-05-30T23:17:54,955][WARN ][o.e.b.JNANatives ] Increase RLIMIT_MEMLOCK, soft limit: 65536, hard limit: 65536 [2019-05-30T23:17:54,956][WARN ][o.e.b.JNANatives ] These can be adjusted by modifying /etc/security/limits.conf, for example: # allow user 'es' mlockall es soft memlock unlimited es hard memlock unlimited 解决之道: vim /etc/security/limits.conf # 在末尾添加如下内容: * soft nofile 65536 * hard nofile 131072 es soft memlock unlimited es hard memlock unlimited
4)ERROR: [1] bootstrap checks failed [1]: memory locking requested for elasticsearch process but memory is not locked 5) [es@localhost bin]$ ./elasticsearch 已杀死 原因:内存太小,将虚拟机的内存调到10G 6)max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 切换到root用户 执行命令: sysctl -w vm.max_map_count=262144 查看结果: sysctl -a|grep vm.max_map_count 显示: vm.max_map_count = 262144 或者 在 /etc/sysctl.conf文件最后添加一行 vm.max_map_count=262144 #并执行命令: sysctl -p 即可永久修改
(7)ERROR: [1] bootstrap checks failed [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured 修改 elasticsearch.yml 取消注释保留一个节点 cluster.initial_master_nodes: ["node-1"] su es cd /usr/local/es/elasticsearch-6.3.2/bin/ ./elasticsearch 启动成功!!!
9、检查9200端口是否对外开放
(1)检查9200端口是否开放:netstat -ntap | grep 9200 (2)按照进程号杀掉:kill -9 pid (3)查看已经开放的端口:firewall-cmd --list-ports (4)开启端口:firewall-cmd --zone=public --add-port=9200/tcp --permanent (5)重新载入防火墙的配置:firewall-cmd --reload (6)重启: su es cd /usr/local/es/elasticsearch-6.3.2/bin/ ./elasticsearch -d
另一台电脑浏览器访问http://10.200.110.116:9200/,成功,如下所示:
{ "name" : "node-1", "cluster_name" : "my-es-skywalking", "cluster_uuid" : "ILucpOH_SKGBnFs3Jg9KPg", "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" }
二、安装Kibana
1、创建安装路径
mkdir /home/skywalking/es
2、解压软件包
/home/skywalking [root@localhost skywalking]# tar -zxvf kibana-7.0.0-linux-x86_64.tar.gz -C /home/skywalking/es/
3、修改配置文件
(1)vim /home/skywalking/es/kibana-6.2.4-linux-x86_64/config/kibana.yml
# 服务端口号:
server.port: 5601
# 服务IP地址:
#server.host: "localhost"
server.host: "10.200.110.116"
# ES链接地址:
#elasticsearch.url: "localhost"
elasticsearch.url: "http://10.200.110.116:9200"
# 配置pid文件存储运行Kibana时的进程号,便于用kill -9 `cat /var/run/kibana.pid`来杀进程。
pid_file: /home/skywalking/es/kibana-6.2.4-linux-x86_64/run/kibana.pid
# 配置Kibana的日志输出位置:
logging.dest: /home/skywalking/es/kibana-6.2.4-linux-x86_64/kibana-log/kibana.log
(2)创建日志文件夹:mkdir /kibana-log和run
3、开放端口:
firewall-cmd --list-ports
firewall-cmd --zone=public --add-port=5601/tcp --permanent
firewall-cmd --reload
4、目录赋权限 [root@localhost kibana-6.2.4-linux-x86_64]# chown -R es:es /home/skywalking/es/kibana-6.2.4-linux-x86_64/
5、启动
cd /home/skywalking/es/kibana-6.2.4-linux-x86_64/bin
./kibana
# 在后台不输出日志的方式运行
cd /home/skywalking/es/kibana-6.2.4-linux-x86_64/bin
nohup ./kibana > /dev/null 2>&1 &
6、访问
http://10.200.110.116:5601
三、安装Skywalking服务
1安装
cd /usr/local/src
tar -zxvf apache-skywalking-apm-incubating-6.0.0-GA.tar.gz
mv apache-skywalking-apm-incubating skywalking
mv skywalking/ /usr/local/
2配置
vim /usr/local/skywalking/config/application.yml
修改配置如下:
storage:
#h2记得都要注释了
# h2:
# driver: ${SW_STORAGE_H2_DRIVER:org.h2.jdbcx.JdbcDataSource}
# url: ${SW_STORAGE_H2_URL:jdbc:h2:mem:skywalking-oap-db}
# user: ${SW_STORAGE_H2_USER:sa}
elasticsearch:
# nameSpace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:10.200.110.116:9200}
indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2}
indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
# Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:2000} # Execute the bulk every 2000 requests
bulkSize: ${SW_STORAGE_ES_BULK_SIZE:20} # flush the bulk every 20mb
flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10} # flush the bulk every 10 seconds whatever the number of requests
concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} # the number of concurrent requests
vim /usr/local/skywalking/webapp/webapp.yml
修改配置如下:
server:
port: 18080
collector:
path: /graphql
ribbon:
ReadTimeout: 10000
# Point to all backend's restHost:restPort, split by ,
listOfServers: 10.200.110.116:12800
3、开放端口:
firewall-cmd --list-ports
firewall-cmd --zone=public --add-port=18080/tcp --permanent
firewall-cmd --zone=public --add-port=11800/tcp --permanent
firewall-cmd --zone=public --add-port=12800/tcp --permanent
firewall-cmd --reload
启动:
[root@localhost bin]# sh startup.sh
SkyWalking OAP started successfully!
SkyWalking Web Application started successfully!
[root@localhost bin]#
四、客户端代理:agent
实际开发时候,每一个jar包获取应用都应该单独使用一个agent,
所以将agent这个目录拷贝到各自对应的jar包路径下。
核心部分的目录信息如下:
├── activations
├── config
│ └── agent.config
├── logs
│ └── skywalking-api.log
├── optional-plugins
├── plugins
└── skywalking-agent.jar
其中,config/agent.config是最重要的,需要修改的核心参数如下所示
# 应用名称,当前代理的应用名称,用于UI界面分类和展示
agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
# 收集器的地址,这个根据实际情况设置,上述`Collector`在哪台服务器启动,ip就设置为多少。
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:10.200.110.116:11800}
开发11800、12800端口:
firewall-cmd --list-ports
firewall-cmd --zone=public --add-port=11800/tcp --permanent
firewall-cmd --reload
设置好参数后,对于 Java 应用,添加核心的-javaagent进行启动
java -javaagent:agent/skywalking-agent.jar -jar xxx.jar
java -javaagent:E:\work\skywalking\agent\skywalking-agent.jar -jar appsflyer-reflux-201905241004.jar
idea里启动,添加VM启动参数,例如:
-javaagent:.../agent/skywalking-agent.jar
-Dskywalking.agent.service_name=test_etl-local
-Dskywalking.collector.backend_service=172.16.254.131:11800
五、附:启动/关闭命令:
# 启动ES
su es
cd /usr/local/es/elasticsearch-6.3.2/bin/
./elasticsearch -d
# 关闭ES
netstat -ntap | grep 9200
kill -9 pid
ps -ef | grep elasticsearch
# 启动kibana
su root
cd /usr/local/kibana/kibana-6.3.2-linux-x86_64/bin/
nohup ./kibana > /dev/null 2>&1 &
# 关闭kinana
kill -9 `cat /var/run/kibana.pid`
# 启动skywalking
cd /usr/local/skywalking/bin/
sh startup.sh
# 关闭skywalking
netstat -ntap | grep 8081
kill -9 pid
五、docker 部署
1 :将 apache-skywalking-apm-6.6.0.tar.gz 包中的 agent文件夹全部复制到项目,修改 config/agent.config 按照四步配置
2: 修改 Dockerfile 文件
FROM java:8 ADD agent /agent ADD target/com-test-1.0-SNAPSHOT.jar /com-test-service.jar #ENV JAVA_OPTS="\ #-server \ #-Xmx4g \ #-Xms2g" ENTRYPOINT ["java","-Xmx4g","-Xms2g","-javaagent:agent/skywalking-agent.jar","-jar","-Duser.timezone=GMT","com-test-service.jar"]
3:重新打包按照 docker 部署方式部署到服务器