3

全链路监控pinpoint安装部署

 2 years ago
source link: https://blog.51cto.com/u_14033037/5381608
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

全链路监控pinpoint安装部署

推荐 原创

凌__晨 2022-06-14 14:57:56 博主文章分类:运维 ©著作权

文章标签 tomcat java zookeeper 文章分类 Linux 系统/运维 阅读数307

1、安装包准备

pinpoint-web-2.3.3.war(下载地址:https://github.com/naver/pinpoint)
pinpoint-collector-boot-2.3.3.jar(下载地址:https://github.com/naver/pinpoint)
pinpoint-agent-2.3.3.tar.gz(下载地址:https://github.com/naver/pinpoint)
hbase-1.4.9-bin.tar.gz(下载地址:http://archive.apache.org/dist/hbase/1.4.9/)
hbase-create.hbase(下载地址:https://github.com/pinpoint-apm/pinpoint/tree/master/hbase/scripts)
zookeeper-3.4.14.tar.gz(下载地址: https://archive.apache.org/dist/zookeeper/)
jdk-7u79-linux-x64.tar.gz(下载地址:https://www.oracle.com/java/technologies/javase/javase7-archive-downloads.html#jdk-7u80-oth-JPR)
apache-tomcat-8.0.36.tar.gz

2、配置jdk环境

tar -zxvf jdk-7u79-linux-x64.tar.gz
mkdir /usr/java
mv jdk1.7.0_79/ /usr/java/jdk17

# 配置java环境变量
vi /etc/profile

# 将下列复制到profile的最后一行中
export JAVA_HOME=/usr/java/jdk17
export PATH=$PATH:$JAVA_HOME/bin

# 让环境变量生效
source /etc/profile

# 测试java的环境变量是否配置好了
[root@localhost pp_res]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

3、部署zookeeper服务

tar zxvf /usr/local/src/zookeeper-3.4.14.tar.gz -C /opt/
ln -s /opt/zookeeper-3.4.14/ /opt/zookeeper
mkdir -pv /data/zookeeper/data /data/zookeeper/logs

配置文件修改:
cat /opt/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/logs
clientPort=2181

启动服务:
/opt/zookeeper/bin/zkServer.sh start

netstat -lntp| grep 2181
tcp6 0 0 :::2181 :::* LISTEN 108043/java

4、部署hbase

pinpoint收集来的数据,主要是存在Hbase数据库的。所以它可以收集大量的数据,可以进行更加详细的分析。

tar -zxvf hbase-1.4.9-bin.tar.gz
mkdir -p /data/service
mv hbase-1.4.9/ /data/service/hbase

cd /data/service/hbase/conf/
vi hbase-env.sh
# 在27行左右的位置,修改如下
export JAVA_HOME=/usr/java/jdk17/
# 在125行左右的位置,添加如下配置,意思是hbase启动不使用自带的zookeeper
export HBASE_MANAGES_ZK=false

vi hbase-site.xml 修改hbase文件配置
<configuration>
<!--
hbase.rootdir
file:///data/hbase

-->
<property>
<name>hbase.rootdir</name>
<value>file:///data/service/hbase/data</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.regionserver.handler.count</name>
<value>20</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>10.0.16.229</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<property>
<name>zookeeper.session.timeout</name>
<value>200000</value>
</property>
<property>
<name>hbase.master.info.port</name>
<value>16010</value>
</property>
</configuration>

#启动服务
cd /data/service/hbase/bin
./start-hbase.sh
# 查看Hbase是否启动成功,如果启动成功的会看到"HMaster"的进程
[root@localhost bin]# jps
12075 Jps
11784 HMaster

#初始化Hbase的pinpoint库
# 执行pinpoint提供的Hbase初始化语句,这时会初始化一会。
./hbase shell /home/hbase-create.hbase

# 执行完了以后,进入Hbase
./hbase shell

# 输入"status 'detailed'"可以查看刚才初始化的表,是否存在
hbase(main):001:0> status 'detailed'

也可以登录web,来查看HBase的数据是否初始化成功

HbaseWeb : ​ ​http://ip:16010/master-status​

5、安装pinpoint-collector

# 解压Tomcat,将Tomcat重命名移动到指定位置
tar -zxvf apache-tomcat-8.0.36.tar.gz
mv apache-tomcat-8.0.36/ /data/service/pp-col


# 修改pp-col的Tomcat的配置,主要修改端口,避免与pp-web的Tomcat的端口冲突。我在原本默认的端口前都加了1,下面是替换的shell命令。
#【注意】最后一条是将tomcat的私有ip开放,需要将localhost替换成本机的ip,我本机的网卡是默认的,如果你本机的网卡不是eth0,需要进行相关的修改。或者直接用"vi"进去,修改localhost
cd /data/service/pp-col/conf/
sed -i 's/port="8005"/port="18005"/g' server.xml
sed -i 's/port="8080"/port="18080"/g' server.xml
sed -i 's/port="8443"/port="18443"/g' server.xml
sed -i 's/port="8009"/port="18009"/g' server.xml
sed -i 's/redirectPort="8443"/redirectPort="18443"/g' server.xml
sed -i "s/localhost/服务器的ip/g" server.xml


# 部署pinpoint-collector.war包
#【注意:如果没有unzip命令,可以 "yum install unzip" 】
cd /home/pp_res/
rm -rf /data/service/pp-col/webapps/*
unzip pinpoint-collector-boot-2.3.3.jar -d /data/service/pp-col/webapps/ROOT


# 启动Tomcat
cd /data/service/pp-col/bin/
./startup.sh


# 查看日志,是否成功启动
tail -f ../logs/catalina.out

5.1、配置快速启动脚本,启动命令:/etc/init.d/pp-col start

ll /etc/init.d/pp-col
-rwx--x--x. 1 webadmin webadmin 3064 Jun 6 15:09 /etc/init.d/pp-col

cat /etc/init.d/pp-col
#!/bin/bash
#
# chkconfig: 345 99 28
# description: Starts/Stops Apache Tomcat
#
# Tomcat 7 start/stop/status script
# Forked from: https://gist.github.com/valotas/1000094
# @author: Miglen Evlogiev <[email protected]>
#
# Release updates:
# Updated method for gathering pid of the current proccess
# Added usage of CATALINA_BASE
# Added coloring and additional status
# Added check for existence of the tomcat user
#

#Location of JAVA_HOME (bin files)
export JAVA_HOME=/usr/java/jdk1.7.0_75/

#Add Java binary files to PATH
export PATH=$JAVA_HOME/bin:$PATH

#CATALINA_HOME is the location of the bin files of Tomcat
export CATALINA_HOME=/data/service/pp-col/

#CATALINA_BASE is the location of the configuration files of this instance of Tomcat
export CATALINA_BASE=/data/service/pp-col/

#TOMCAT_USER is the default user of tomcat
export TOMCAT_USER=root

#TOMCAT_USAGE is the message if this script is called without any options
TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"

#SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
SHUTDOWN_WAIT=3

tomcat_pid() {
echo `ps -fe | grep $CATALINA_BASE | grep -v grep | tr -s " "|cut -d" " -f2`
}

start() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m"
else
# Start tomcat
echo -e "\e[00;32mStarting tomcat\e[00m"
#ulimit -n 100000
#umask 007
#/bin/su -p -s /bin/sh tomcat
if [ `user_exists $TOMCAT_USER` = "1" ]
then
su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
else
sh $CATALINA_HOME/bin/startup.sh
fi
status
fi
return 0
}

status(){
pid=$(tomcat_pid)
if [ -n "$pid" ]; then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
else echo -e "\e[00;31mTomcat is not running\e[00m"
fi
}

stop() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo -e "\e[00;31mStoping Tomcat\e[00m"
#/bin/su -p -s /bin/sh tomcat
sh $CATALINA_HOME/bin/shutdown.sh

let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m";
sleep 1
let count=$count+1;
done

if [ $count -gt $kwait ]; then
echo -n -e "\n\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
kill -9 $pid
fi
else
echo -e "\e[00;31mTomcat is not running\e[00m"
fi

return 0
}

user_exists(){
if id -u $1 >/dev/null 2>&1; then
echo "1"
else
echo "0"
fi
}

case $1 in

start)
start
;;

stop)
stop
;;

restart)
stop
start
;;

status)
status

;;

*)
echo -e $TOMCAT_USAGE
;;
esac
exit 0

6、安装pinpoint-web

# 解压Tomcat,将Tomcat重命名移动到指定位置
tar -zxvf apache-tomcat-8.0.36.tar.gz
mv apache-tomcat-8.0.36/ /data/service/pp-web


# 修改pp-web的Tomcat的配置,主要修改端口,避免与pp-col的Tomcat的端口冲突。我在原本默认的端口前都加了2,下面是替换的shell命令
#【注意】最后一条是将tomcat的私有ip开放,需要将localhost替换成本机的ip,我本机的网卡是默认的,如果你本机的网卡不是eth0,需要进行相关的修改。或者直接用"vi"进去,修改localhost
cd /data/service/pp-web/conf/
sed -i 's/port="8005"/port="28005"/g' server.xml
sed -i 's/port="8080"/port="28080"/g' server.xml
sed -i 's/port="8443"/port="28443"/g' server.xml
sed -i 's/port="8009"/port="28009"/g' server.xml
sed -i 's/redirectPort="8443"/redirectPort="28443"/g' server.xml
sed -i "s/localhost/服务器ip/g" server.xml


# 部署pinpoint-collector.war包
#【注意:如果没有unzip命令,可以 "yum install unzip" 】
cd /home/pp_res/
rm -rf /data/service/pp-web/webapps/*
unzip pinpoint-web-2.3.3.war -d /data/service/pp-web/webapps/ROOT

# 启动Tomcat
cd /data/service/pp-web/bin/
./startup.sh


# 查看日志,Tocmat是否启动成功
tail -f ../logs/catalina.out

6.1、配置快速启动脚本,启动命令:/etc/init.d/pp-web start

ll /etc/init.d/pp-web
-rwx--x--x. 1 root root 3064 Jun 6 15:23 /etc/init.d/pp-web

cat /etc/init.d/pp-web
#!/bin/bash
#
# chkconfig: 345 99 28
# description: Starts/Stops Apache Tomcat
#
# Tomcat 7 start/stop/status script
# Forked from: https://gist.github.com/valotas/1000094
# @author: Miglen Evlogiev <[email protected]>
#
# Release updates:
# Updated method for gathering pid of the current proccess
# Added usage of CATALINA_BASE
# Added coloring and additional status
# Added check for existence of the tomcat user
#

#Location of JAVA_HOME (bin files)
export JAVA_HOME=/usr/java/jdk1.7.0_75/

#Add Java binary files to PATH
export PATH=$JAVA_HOME/bin:$PATH

#CATALINA_HOME is the location of the bin files of Tomcat
export CATALINA_HOME=/data/service/pp-web/

#CATALINA_BASE is the location of the configuration files of this instance of Tomcat
export CATALINA_BASE=/data/service/pp-web/

#TOMCAT_USER is the default user of tomcat
export TOMCAT_USER=root

#TOMCAT_USAGE is the message if this script is called without any options
TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"

#SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
SHUTDOWN_WAIT=3

tomcat_pid() {
echo `ps -fe | grep $CATALINA_BASE | grep -v grep | tr -s " "|cut -d" " -f2`
}

start() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m"
else
# Start tomcat
echo -e "\e[00;32mStarting tomcat\e[00m"
#ulimit -n 100000
#umask 007
#/bin/su -p -s /bin/sh tomcat
if [ `user_exists $TOMCAT_USER` = "1" ]
then
su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
else
sh $CATALINA_HOME/bin/startup.sh
fi
status
fi
return 0
}

status(){
pid=$(tomcat_pid)
if [ -n "$pid" ]; then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
else echo -e "\e[00;31mTomcat is not running\e[00m"
fi
}

stop() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo -e "\e[00;31mStoping Tomcat\e[00m"
#/bin/su -p -s /bin/sh tomcat
sh $CATALINA_HOME/bin/shutdown.sh

let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m";
sleep 1
let count=$count+1;
done

if [ $count -gt $kwait ]; then
echo -n -e "\n\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
kill -9 $pid
fi
else
echo -e "\e[00;31mTomcat is not running\e[00m"
fi

return 0
}

user_exists(){
if id -u $1 >/dev/null 2>&1; then
echo "1"
else
echo "0"
fi
}

case $1 in

start)
start
;;

stop)
stop
;;

restart)
stop
start
;;

status)
status

;;

*)
echo -e $TOMCAT_USAGE
;;
esac
exit 0

7、部署pp-agent采集监控数据

# 解压pp-agent
tar -zxvf pinpoint-agent-2.3.3.tar.gz
mv pinpoint-agent-2.3.3 /data/pp-agent


# 编辑配置文件
cd /data/pp-agent/
vi pinpoint.config


# 主要修改IP,只需要指定到安装pp-col的IP就行了,安装pp-col启动后,自动就开启了9994,9995,9996的端口了。这里就不需要操心了,如果有端口需求,要去pp-col的配置文件("pp-col/webapps/ROOT/WEB-INF/classes/pinpoint-collector.properties")中,修改这些端口
profiler.collector.ip=服务端ip


# 修改测试项目下的tomcat启动文件"catalina.sh",修改这个只要是为了监控测试环境的Tomcat,增加探针
cd /data/pp-test/bin
vi catalina.sh


# 在20行增加如下字段
# 第一行是pp-agent的jar包位置
# 第二行是agent的ID,这个ID是唯一的,我是用pp + 今天的日期命名的,只要与其他的项目的ID不重复就好了
# 第三行是采集项目的名字,这个名字可以随便取,只要各个项目不重复就好了
CATALINA_OPTS="$CATALINA_OPTS -javaagent:/data/pp-agent/pinpoint-bootstrap-2.3.3.jar"
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.agentId=pp20220522"
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.applicationName=MyTestPP

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK