Centos安装Skywalking
本节主要介绍在Centos系统中安装Skywalking
注意:Skywalking默认使用H2内存中进行数据存储,我们可以替换存储源为ElasticSearch保证器查询的高效及可用性。
安装ES是非常的简单,但是在安全之前一定要先搭建好Java环境,这里我将省略掉这步。下面将介绍单个ES的安装:
1、ES官网下载页面
https://www.elastic.co/cn/downloads/elasticsearch
2、下载自己对应系统平台的ES包,这里我使用的Centos系统,所以下载Linux包
[root@localhost ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.0.tar.gz
3、解压到指定目录
[root@localhost ~]# tar -zxf elasticsearch-6.5.0-linux-x86_64.tar.gz -C /home/
[root@localhost ~]# cd /home/elasticsearch-6.5.0/
[root@localhost elasticsearch-6.5.0]# ll
total 436
drwxr-xr-x 3 root root 4096 Jun 7 17:33 bin
drwxr-xr-x 2 root root 148 Nov 10 2018 config
drwxr-xr-x 3 root root 4096 Nov 10 2018 lib
-rw-r--r-- 1 root root 13675 Nov 10 2018 LICENSE.txt
drwxr-xr-x 2 root root 6 Nov 10 2018 logs
drwxr-xr-x 28 root root 4096 Nov 10 2018 modules
-rw-r--r-- 1 root root 403816 Nov 10 2018 NOTICE.txt
drwxr-xr-x 2 root root 6 Nov 10 2018 plugins
-rw-r--r-- 1 root root 8519 Nov 10 2018 README.textile
4、运行ES
[root@localhost elasticsearch-6.5.0]# ./bin/elasticsearch
[2020-06-07T17:34:17,779][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.0.jar:6.5.0]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.0.jar:6.5.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.5.0.jar:6.5.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.5.0.jar:6.5.0]
... 6 more
这里报错,ES不能使用root用户执行,主要出于系统安全考虑。那么要解决遇到的问题,我们需要给ES单独创建用户和用户组来进行运行。
5、创建ES的用户和组
[root@localhost]# groupadd elsearch
[root@localhost]# useradd elsearch -g elsearch -p elasticsearch
6、更改ES的文件夹中所有文件的所属用户和组为上面创建的用户和组
[root@localhost home]# chown -R elsearch:elsearch /home/elasticsearch-6.5.0
7、切换到上面创建的用户去,再启动ES
[root@localhost home]# su elsearch
[elsearch@localhost home]$ cd elasticsearch-6.5.0/
[elsearch@localhost elasticsearch-6.5.0]$ ./bin/elasticsearch
8、测试
[root@localhost ~]# curl http://localhost:9200/
{
"name" : "muQvCUw",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "trfjuqJzSyK_5lrdSTriAw",
"version" : {
"number" : "6.5.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "816e6f6",
"build_date" : "2018-11-09T18:58:36.352602Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[root@localhost ~]# netstat -ntlp #9200 9300都是ES的默认端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 4669/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3671/sshd
tcp6 0 0 ::1:25 :::* LISTEN 4669/master
tcp6 0 0 127.0.0.1:9200 :::* LISTEN 5137/java
tcp6 0 0 ::1:9200 :::* LISTEN 5137/java
tcp6 0 0 127.0.0.1:9300 :::* LISTEN 5137/java
tcp6 0 0 ::1:9300 :::* LISTEN 5137/java
tcp6 0 0 :::22 :::* LISTEN 3671/sshd
9、后台运行ES进程
[elsearch@localhost elasticsearch-6.5.0]$ ./bin/elasticsearch -d
10、必须保证防火墙开启的情况下,才需要添加ES端口,否则不能访问9200端口
#添加开发端口9200
[elsearch@localhost elasticsearch-6.5.0]$ firewall-cmd --zone=public --add-port=9200/tcp --permanent
#重启防火墙
[elsearch@localhost elasticsearch-6.5.0]$ firewall-cmd --reload
11、开机启动一:init.d下配置
在/etc/init.d下创建es文件,并将下面的内容复制进去,一定要注意这里的名字,千万不要命名成elasticsearch,主要脚本中就是通过该名称来管理进程的。脚本的格式一定要注意,最好复制下面的即可,否则会出现某些地方出现格式不对而运行出现问题。
#!/bin/sh
#chkconfig: 2345 80 05
#description: es
export JAVA_HOME=/jdk1.8.0_181 #需要修改成自己JDK路径(一定修改)
export JAVA_BIN=$JAVA_HOME/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export ES_HOME=/home/elasticsearch-6.5.0 #需要修改成自己ES路径(一定修改)
export ES_USER_NAME=elsearch #对应的ES的用户账号(一定修改)
case $1 in
start)
#下面的"<<!"是切换用户后,待执行的命令,执行完后使用"!"来进行结束
su $ES_USER_NAME<<!
cd $ES_HOME
./bin/elasticsearch -d
exit
!
#上面的"!"是以上面的对应起来,并且顶格放置,这是语法
echo "elasticsearch start" #将该行替换成你自己的服务启动命令
;;
stop)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'` #注意这个号"`"
kill -9 $es_pid
echo "elasticsearch stop" #将该行替换成你自己的服务启动命令
;;
restart)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'` #"grep -v"过滤掉本身的执行命令,获取准确的pid
kill -9 $es_pid
echo "elasticsearch stop" #将该行替换成你自己的服务启动命令
su $ES_USER_NAME<<!
cd $ES_HOME
./bin/elasticsearch -d
!
echo "elasticsearch start" #将该行替换成你自己的服务启动命令
;;
*)
echo "start|stop|restart" #将该行替换成你自己的服务启动命令
;;
esac
- 10.2、设置可执行
[root@localhost init.d]# chmod +x es
- 10.3、加到开机启动
[root@localhost init.d]# chkconfig -add es
- 10.4、可以使用如下命令启动、停止和重启
[root@localhost init.d]# service es start elasticsearch start [root@localhost init.d]# service es stop elasticsearch stop [root@localhost init.d]# service es start elasticsearch start [root@localhost init.d]# service es restart
12、开机启动二:/etc/systemd/system下配置
- 12.1、在/etc/systemd/system目录下新建一个elasticsearch.service,将下面的内容复制进去:
[Unit] Description=elasticsearch [Service] User=elsearch #es用户 ExecStart=/home/elasticsearch-6.5.0/bin/elasticsearch #es命令路径 [Install] WantedBy=multi-user.target
- 12.2、添加到开机启动
[root@localhost system]# systemctl enable elasticsearch.service Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /etc/systemd/system/elasticsearch.service.
- 12.3、启动、停止和重启
[root@localhost system]# systemctl start elasticsearch.service [root@localhost system]# systemctl stop elasticsearch.service [root@localhost system]# systemctl restart elasticsearch.service [root@localhost ~]# systemctl status elasticsearch.service ● elasticsearch.service - elasticsearch Loaded: loaded (/etc/systemd/system/elasticsearch.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2019-04-29 13:58:15 EDT; 1min 11s ago Main PID: 3422 (java) CGroup: /system.slice/elasticsearch.service ├─3422 /home/elasticsearch-6.5.0/jdk/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddres... └─4796 /home/elasticsearch-6.5.0/modules/x-pack-ml/platform/linux-x86_64/bin/controller Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,943][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [x-pack-graph] Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,943][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [x-pack-ilm] Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,944][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [x-pack-logstash] Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,944][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [x-pack-ml] Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,944][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [x-pack-monitoring] Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,945][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [x-pack-rollup] Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,945][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [x-pack-security] Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,945][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [x-pack-sql] Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,946][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [x-pack-watcher] Apr 29 13:59:14 localhost.localdomain elasticsearch[3422]: [2019-04-29T13:59:14,946][INFO ][o.e.p.PluginsService ] [localhost.localdomain] no plugins loaded
以上整个安装ES过程完成。下面介绍如何安装SkyWalking
安装Skywalking分为两个步骤:
- 安装Backend后端服务
- 安装UI
在root用户下操作
1、下载
[root@localhost ~]# wget https://www.apache.org/dyn/closer.cgi/skywalking/6.5.0/apache-skywalking-apm-6.5.0.tar.gz
2、解压
[root@localhost ~]# tar -zxf apache-skywalking-apm-6.5.0.tar.gz -C /home/
[root@localhost ~]# cd /home/apache-skywalking-apm-bin/
[root@localhost home]# cd apache-skywalking-apm-bin/
[root@localhost apache-skywalking-apm-bin]# ll
total 88
drwxrwxr-x 8 1001 1002 143 Nov 12 2019 agent
drwxr-xr-x 2 root root 241 Jun 7 15:48 bin
drwxr-xr-x 2 root root 186 Jun 7 15:48 config
-rwxrwxr-x 1 1001 1002 28903 Nov 12 2019 LICENSE
drwxrwxr-x 3 1001 1002 4096 Jun 7 15:48 licenses
-rwxrwxr-x 1 1001 1002 31850 Nov 12 2019 NOTICE
drwxrwxr-x 2 1001 1002 12288 Nov 12 2019 oap-libs
-rw-rw-r-- 1 1001 1002 1978 Nov 12 2019 README.txt
drwxr-xr-x 2 root root 53 Jun 7 15:48 webapp
3、配置后端服务数据源
前面已经安装了ES作为数据源,所以就需要开启ES,关闭H2.
[root@localhost apache-skywalking-apm-bin]# vim config/application.yml #修改storage部分,打开es,注释h2
...
storage:
elasticsearch:
nameSpace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
trustStorePath: ${SW_SW_STORAGE_ES_SSL_JKS_PATH:"../es_keystore.jks"}
trustStorePass: ${SW_SW_STORAGE_ES_SSL_JKS_PASS:""}
user: ${SW_ES_USER:""}
password: ${SW_ES_PASSWORD:""}
indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2}
indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0}
# # Those data TTL settings will override the same settings in core module.
recordDataTTL: ${SW_STORAGE_ES_RECORD_DATA_TTL:7} # Unit is day
otherMetricsDataTTL: ${SW_STORAGE_ES_OTHER_METRIC_DATA_TTL:45} # Unit is day
monthMetricsDataTTL: ${SW_STORAGE_ES_MONTH_METRIC_DATA_TTL:18} # Unit is month
# # 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:1000} # Execute the bulk every 1000 requests
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
resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
# 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}
# metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
...
4、修改webapp的配置
[root@localhost apache-skywalking-apm-bin]# vim webapp/webapp.yml #这里修改下服务的端口,防止冲突,改成9010
...
server:
port: 9010
...
5、启动服务
查看bin下面的文件
[root@localhost apache-skywalking-apm-bin]# ll bin/
total 40
-rwxr-xr-x 1 1001 1002 1352 Nov 12 2019 oapService.bat
-rwxr-xr-x 1 1001 1002 1364 Nov 12 2019 oapServiceInit.bat
-rwxr-xr-x 1 1001 1002 1597 Nov 12 2019 oapServiceInit.sh
-rwxr-xr-x 1 1001 1002 1367 Nov 12 2019 oapServiceNoInit.bat
-rwxr-xr-x 1 1001 1002 1616 Nov 12 2019 oapServiceNoInit.sh
-rwxr-xr-x 1 1001 1002 1599 Nov 12 2019 oapService.sh #这个启动后端服务
-rwxr-xr-x 1 1001 1002 941 Nov 12 2019 startup.bat
-rwxr-xr-x 1 1001 1002 934 Nov 12 2019 startup.sh #这个是对两个服务一起进行启动
-rwxr-xr-x 1 1001 1002 1426 Nov 12 2019 webappService.bat
-rwxr-xr-x 1 1001 1002 1630 Nov 12 2019 webappService.sh #这个是启动webapp
启动:
[root@localhost apache-skywalking-apm-bin]# ./bin/startup.sh
SkyWalking OAP started successfully!
SkyWalking Web Application started successfully!
6、查看端口
[root@localhost ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1275/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1114/sshd
tcp6 0 0 :::11800 :::* LISTEN 15821/java
tcp6 0 0 ::1:25 :::* LISTEN 1275/master
tcp6 0 0 :::12800 :::* LISTEN 15821/java
tcp6 0 0 127.0.0.1:9200 :::* LISTEN 15679/java
tcp6 0 0 ::1:9200 :::* LISTEN 15679/java
tcp6 0 0 :::8080 :::* LISTEN 15336/java
tcp6 0 0 :::9010 :::* LISTEN 15960/java
tcp6 0 0 127.0.0.1:9300 :::* LISTEN 15679/java
tcp6 0 0 ::1:9300 :::* LISTEN 15679/java
tcp6 0 0 :::22 :::* LISTEN 1114/sshd
如果存在11800、12800、9010端口,就启动成功。
7、进行访问
http://192.168.100.111:9010/
如图所示:
到此,我们的安装部分就算完成。