Centos6.8 下 从零开始 部署 Java Web 应用

一、硬件信息

CPU:

[[email protected] ~]# grep ‘physical id‘ /proc/cpuinfo | sort -u | wc -l
2
[[email protected] ~]# grep ‘core id‘ /proc/cpuinfo | sort -u | wc -l
4
[[email protected] ~]# grep ‘processor‘ /proc/cpuinfo | sort -u | wc -l
16
[[email protected] ~]# dmidecode -s processor-version
Intel(R) Xeon(R) CPU           L5520  @ 2.27GHz
Intel(R) Xeon(R) CPU           L5520  @ 2.27GHz     

系统:

[[email protected] ~]# cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m

内存:

[[email protected] ~]# free -h
             total       used       free     shared    buffers     cached
Mem:           15G        12G       3.1G         4K       185M       2.6G
-/+ buffers/cache:       9.7G       5.9G
Swap:         7.9G        51M       7.8G

硬盘:

[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  8.7G   38G  19% /
tmpfs                 7.8G     0  7.8G   0% /dev/shm
/dev/sda1             477M   39M  414M   9% /boot
/dev/mapper/VolGroup-lv_home
                      860G  3.8G  812G   1% /home

software:

[[email protected] tomcat8.35]# sh bin/version.sh
Using CATALINA_BASE:   /home/server/tomcat8.35/
Using CATALINA_HOME:   /home/server/tomcat8.35/
Using CATALINA_TMPDIR: /home/server/tomcat8.35/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /home/server/tomcat8.35/bin/bootstrap.jar:/home/server/tomcat8.35/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.5.35
Server built:   Nov 3 2018 17:39:20 UTC
Server number:  8.5.35.0
OS Name:        Linux
OS Version:     2.6.32-642.el6.x86_64
Architecture:   amd64
JVM Version:    1.8.0_191-b12
JVM Vendor:     Oracle Corporation

[[email protected] ~]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

CPU:2核4核心16线程

系统:Centos6.8

内存:16G

硬盘:50G + 860G + 477M

软件:Tomcat8.35 \ JDK1.8.0_191-b12

二、调整Linux设置

2.1、调整DNS

1)编辑DNS

[[email protected] ~]# vi /etc/resolv.conf
[[email protected] ~]# cat /etc/resolv.conf
#阿里云 DNS
nameserver 223.5.5.5
nameserver 223.6.6.6

#Google DNS
nameserver 8.8.8.8 

2)重启网络服务

[[email protected] ~]# service network restart
正在关闭接口 em2:                                         [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 em2: Determining if ip address 221.235.184.199 is already in use for device em2...
                                                           [确定]

2.2、调整软件源

[[email protected] ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup[[email protected] ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-6.repo[[email protected] ~]# yum makecache

如果无wget命令,则手动编辑。

2.3、安装ntp ,用于同步系统时间

1)安装并启动

[[email protected] ~]# yum -y install ntp

2)同步时间

[[email protected]t ~]# ntpdate time.nuri.net
23 Dec 21:13:45 ntpdate[30444]: adjust time server 211.115.194.21 offset -0.020057 sec

3)增加时间服务器, time.nuri.net

[[email protected] ~]# vi /etc/ntp.conf
[[email protected] ~]# cat /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
server time.nuri.net iburst

#broadcast 192.168.1.255 autokey    # broadcast server
#broadcastclient            # broadcast client
#broadcast 224.0.1.1 autokey        # multicast server
#multicastclient 224.0.1.1        # multicast client
#manycastserver 239.255.254.254        # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

4)设置当前时区为上海

[[email protected] ~]# rm -rf /etc/localtime
[[email protected] ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

5)启动ntpd服务

[[email protected] ~]# service ntpd status
ntpd 已停
[[email protected] ~]# service ntpd start
正在启动 ntpd: [确定]
[[email protected] ~]# service ntpd status
ntpd (pid 30317) 正在运行...[[email protected] ~]# chkconfig --level 2345 ntpd on

参考:linux下使用ntpdate进行时间同步

https://www.cnblogs.com/kerrycode/archive/2015/08/20/4744804.html

https://www.cnblogs.com/flytogalaxy/p/8471675.html

2.4、关闭selinux

1)临时关闭:

[[email protected] ~]# getenforce
Enforcing
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce
Permissive

2)永久关闭:

[[email protected] ~]# vim /etc/sysconfig/selinux

SELINUX=enforcing 改为 SELINUX=disabled

[[email protected] ~]# cat /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

2.5、调整ulimit

1)查看当前限制

[[email protected] ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 63653
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 63653
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

2)临时增加系统对当前用户每个进程可以同时打开的最大文件数,可以运行的最大并发进程数( ulimit设置参考 )

[[email protected] ~]# ulimit -n 65535
[[email protected] ~]# ulimit -u 65535

3)永久修改

[[email protected] ~]# vi /etc/security/limits.conf

在文件末尾添加以下内容:

* soft noproc 65535* hard noproc 65535
* soft nofile 65535
* hard nofile 65535

[[email protected] ~]# cat /etc/security/limits.conf
# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
* soft noproc 65535* hard noproc 65535
* soft nofile 65535
* hard nofile 65535

# End of file

4)再次查看当前限制信息

[[email protected] ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 63653
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 63653
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

参考:使用ulimit设置文件最大打开数

https://blog.csdn.net/noizz/article/details/2486339

2.6、调整SSH,保持长连接

[[email protected] ~]# vi /etc/ssh/sshd_config

ClientAliveInterval 60   #server每隔60秒发送一次请求给client,然后client响应,从而保持连接

ClientAliveCountMax 3  #server发出请求后,客户端没有响应得次数达到3,就自动断开连接,正常情况下,client不会不响应

[[email protected] ~]# service sshd restart
停止 sshd:                                                [确定]
正在启动 sshd:                                            [确定]

2.7、 安装crontab

[[email protected] ~]# yum install vixie-cron crontab[[email protected] ~]# chkconfig --level 2345 crond on

2.8、安装辅助命令

[[email protected] ~]# yum install wget zip unzip lrzsz telnet

三、安装执行环境

3.1、下载JAVA JDK

[[email protected] ~]# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm"

#安装JAVA JDK

[[email protected] ~]# yum install jdk-8u191-linux-x64.rpm

3.2、安装MySQL

1)下载MySQL

[[email protected] ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar
[[email protected] ~]# tar xvf mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar
[[email protected] ~]# yum install mysql-*.rpm
[[email protected] ~]# vi /etc/my.cnf

2)编辑mysql配置,在[mysqld]下面添加配置

max_connections=1000

wait_timeout=50

sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

[[email protected] ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

#最大链接数max_connections=1000wait_timeout=50
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

#MySQL在完成某些join(连接)需求的时候,为了减少参与join的“被驱动表”的读取次数以提高性能,
#需要使用到join buffer来协助完成join操作,当join buffer 太小,
#MySQL不会将该buffer存入磁盘文件而是先将join buffer中的结果与需求join的表进行操作,
#然后清空join buffer中的数据,继续将剩余的结果集写入次buffer中
join_buffer_size = 512M
tmp_table_size = 128M
tmpdir = /tmp

#该值设置过小将导致单个记录超过限制后写入数据库失败,且后续记录写入也将失败
max_allowed_packet = 100M

innodb_buffer_pool_size=4096M
innodb_log_file_size = 512M
#MySQL读入缓冲区的大小
read_buffer_size = 64M
#MySQL的随机读缓冲区大小
read_rnd_buffer_size = 16M
#MySQL的顺序读缓冲区大小
sort_buffer_size = 16M

#查询缓存
query_cache_size=100M
key_buffer_size=64m
thread_cache_size=64

#开启慢查询日志
slow_query_log = 1
#超出次设定值的SQL即被记录到慢查询日志
long_query_time = 6
slow_query_log_file = /var/log/mysql/slow.log
#表示记录下没有使用索引的查询
log_queries_not_using_indexes = 1

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysql/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

3)启动msyql

[[email protected] ~]# service mysqld start[[email protected] ~]# chkconfig --level 2345 mysqld on

4)查看msyql root密码

[[email protected] ~]# grep ‘temporary password‘ /var/log/mysqld.log

5)登录mysql

[[email protected] ~]# mysql -uroot -p密码

6)修改密码

mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘新密码‘;

7)编辑防火墙,开放端口3306

[[email protected] ~]# vi /etc/sysconfig/iptables

添加一条命令:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

[[email protected] ~]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

8)重启防火墙

[[email protected] ~]# service iptables restart

3.3、安装redis

[[email protected] ~]# yum install epel-release   #添加epel源
[[email protected] ~]# yum install redis
[[email protected] ~]# service redis start[[email protected] ~]# chkconfig --level 2345 redis on

3.4、下载Tomcat ( 官网下载地址 )

[[email protected] ~]# wget -P /home/server/tomcat8 http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz[[email protected] ~]# cd /home/server/tomcat8 [[email protected] ~]# tar zxvf apache-tomcat-8.5.35.tar.gz

3.5、上传Web应用代码

上传至 /home/server/tomcat8.35/webapps/

?  ~ rsync webApllication.war [email protected]:/home/server/tomcat8.35/webapps/[[email protected] ~]# jar xvf webApllication.war

3.6、jvisualvm远程监控tomcat

1)添加如下配置:

[[email protected] ~]# vi /home/server/tomcat8/venus_server/bin/startup.sh

SERVER_ROOT_DIR=`pwd`

export CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=服务器外网ip
-Dcom.sun.management.jmxremote.port=端口
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.password.file=SERVERROOTDIR/conf/jmxremote.password−Dcom.sun.management.jmxremote.access.file=SERVERROOTDIR/conf/jmxremote.password−Dcom.sun.management.jmxremote.access.file=SERVER_ROOT_DIR/conf/jmxremote.access"

[[email protected] ~]# cat /home/server/tomcat8/venus_server/bin/startup.sh
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------

# Better OS/400 detection: see Bugzilla 31132
os400=false
case "`uname`" in
OS400*) os400=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : ‘.*-> \(.*\)$‘`
  if expr "$link" : ‘/.*‘ > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

PRGDIR=`dirname "$PRG"`
EXECUTABLE=catalina.sh

# Check that target executable exists
if $os400; then
  # -x will Only work on the os400 if the files are:
  # 1. owned by the user
  # 2. owned by the PRIMARY group of the user
  # this will not work if the user belongs in secondary groups
  eval
else
  if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
    echo "Cannot find $PRGDIR/$EXECUTABLE"
    echo "The file is absent or does not have execute permission"
    echo "This file is needed to run this program"
    exit 1
  fi
fi

# jvisualvm settings

SERVER_ROOT_DIR=`pwd`

export CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=0.0.0.0
-Dcom.sun.management.jmxremote.port=1100
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.password.file=$SERVER_ROOT_DIR/conf/jmxremote.password
-Dcom.sun.management.jmxremote.access.file=$SERVER_ROOT_DIR/conf/jmxremote.access"

# enf of jvisualvm
#设置启动内存
export JAVA_OPTS="$JAVA_OPTS -server -Xms6144m -Xmx6144m -XX:NewSize=1024m -XX:MaxNewSize=2048m -XX:SurvivorRatio=2 -XX:+UseParallelGC"

exec "$PRGDIR"/"$EXECUTABLE" start "[email protected]"

2)设置远程监控账号:

[[email protected] conf]# vi /home/server/tomcat8.35/conf/jmxremote.access

内容如下:

用户名 权限类型(readonly:只读,readwrite:读写)

[[email protected] conf]# cat jmxremote.access
guest readonly
root readwrite

设置远程监控密码:

用户名 密码

[[email protected] conf]# vi /home/server/tomcat8.35/conf/jmxremote.password[[email protected] conf]# cat /home/server/tomcat8.35/conf/jmxremote.passwordguest xxxxxxroot  xxxxxx

3)设置文件权限

[[email protected] conf]# chmod 600 /home/server/tomcat8.35/conf/jmxremote*

4)启动web应用

[[email protected] conf]# sh /home/server/tomcat8.35/bin/startup.sh

3.7、辅助shell

1.内存监控,并回收脚本

#!/bin/bash

LIMIT=512
LOG_FILE="/var/log/timing_dropcaches.log"

#定时清理系统内存
#https://blog.csdn.net/gaojinshan/article/details/40710369
used=`free -m | awk ‘NR==2‘ | awk ‘{print $3}‘`
free=`free -m | awk ‘NR==2‘ | awk ‘{print $4}‘`

echo "===========================" >> $LOG_FILE
date +"%Y-%m-%d %H:%M.%S" >> $LOG_FILE
echo "Memory usage | [Use:${used}MB][Free:${free}MB] | [${LIMIT}]MB" >> $LOG_FILE

# drop caches when the free memory less than 2G
if [ $free -le $LIMIT ] ; then
 #sync && echo 1 > /proc/sys/vm/drop_caches
 #sync && echo 2 > /proc/sys/vm/drop_caches
 sync && echo 3 > /proc/sys/vm/drop_caches
 echo "OK" >> $LOG_FILE
else
 echo "Not required" >> $LOG_FILE
fi

2.日志清理脚本

[[email protected] ~]# crontab -e
#删除2天前的日志
/usr/bin/find /home/server/tomcat8.35 -name *.log -mtime +2 | grep `date +%Y` | xargs rm -Rf {} > /dev/null 2>&1

四、压力测试

4.1、安装Webbench

wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz
tar -zxvf ./webbench-1.5.tar.gz
yum install -y gcc ctags
cd ./webbench-1.5
make &make install
make clean

参考:webbench安装

4.2、使用说明

webbench [option]... URL
  -f|--force               Don‘t wait for reply from server.
  -r|--reload              Send reload request - Pragma: no-cache.
  -t|--time <sec>          Run benchmark for <sec> seconds. Default 30.
  -p|--proxy <server:port> Use proxy server for request.
  -c|--clients <n>         Run <n> HTTP clients at once. Default one.
  -9|--http09              Use HTTP/0.9 style requests.
  -1|--http10              Use HTTP/1.0 protocol.
  -2|--http11              Use HTTP/1.1 protocol.
  --get                    Use GET request method.
  --head                   Use HEAD request method.
  --options                Use OPTIONS request method.
  --trace                  Use TRACE request method.
  -?|-h|--help             This information.
  -V|--version             Display program version.

t是benchmark持续多久。

c是指time时间内请求多少次。

比如我们测试百度, 启动100个客户端同时请求百度首页,持续60S:

webbench -t 60 -c 100 http://www.baidu.com/

4.3、运行结果

Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://www.baidu.com/
100 clients, running 60 sec.

Speed=2643 pages/min, 5045450 bytes/sec.
Requests: 2641 susceed, 2 failed.

五、jvisualvm远程监控

5.1、启动jvisualvm

?  ~ jvisualvm

5.2、添加远程主机

5.3、输入服务IP、默认端口1099,点击确认。

5.4、添加JMX连接,输入端口(本文1100)、用户名、密码,勾选不要求SSL。

5.5、打开连接,查看监控信息。

参考: jvisualvm远程监控tomcat

六、JProfiler远程监控

6.1、下载JProfiler并安装

[[email protected] ~]# wget https://download-keycdn.ej-technologies.com/jprofiler/jprofiler_linux_9_1_1.rpm
[[email protected] ~]# yum -y install jprofiler_linux_9_1_1.rpm

6.2、安装JProfile客户端,并打开软件,选择 Pfofile an application server,locally or remotely

选择对应的Tomcat版本

选择 On a remote computer, 服务器的系统版本

选择JAVA虚拟机的版本

选择稍后远程连接服务器

输入服务器域名或IP

输入服务器端JProfiler安装目录 /opt/jprofiler9

上传服务器Tomcat的startup.sh启动脚本

输入监控连接端口,默认即可

此时会在之前上传的startup.sh文件的同目录下生成一个startup_jprofiler.sh文件,把该文件上传至服务器的Tomcat的bin目录下,使用startup_jprofiler.sh启动Tomcat。

再打开软件JProfiler,选择刚刚设置的连接配置,进行远程监控操作。

查看线程情况, 选择左菜单Threads,选择颜色为红色的线程,右键菜单选择 Show Call Tree For Selected Thread。

查看线程最耗时的操作是在哪个调用栈上,比对对应的源码,找到导致线程阻塞的原因。

或者结合查看内存的使用情况,定位到是哪个类对象使用内存开销过大。

参考:Java性能分析神器-JProfiler详解   使用JProfiler进行内存分析

最后一步,使用webbench进行压力测试,使用监控工具分析应用的性能瓶颈或排查其他比如内存泄漏等程序问题。

PS:

https://www.jianshu.com/p/d59b3b971aa3

jvisualvm远程监控tomcat

https://www.cnblogs.com/wuweidong/p/5815348.html

原文地址:https://www.cnblogs.com/phpdragon/p/10129324.html

时间: 2024-10-12 18:11:12

Centos6.8 下 从零开始 部署 Java Web 应用的相关文章

新手小白Linux(Centos6.5)部署java web项目(总)

一.准备 1.linux  centos版本的相关命令操作,千万别找ubuntu的,好多命令都不一样,新手小白我傻傻不知道硬是浪费了一天的时间--(百度百科linux版本了解一下) 2.远程登录: PuTTY .WinSCP .SecureCRT .mstsc.其他(我用的SecureCRT7.3 ,主要看环境支持哪种工具) 3.确认linux服务器有网,没网的话用不了yum,只能从本机获取资源,操作方式也不一样,本文部分安装只介绍yum. 二.明确部署所需要的环境 1.java环境:jdk 2

CentOS6.5中部署java web环境

原来在linux中部署java web环境,没有做好总结,这次在部署的过程中,将部署的过程做了记录,希望对大家有帮助.主要内容包括CentOS安装以后的网络设置,系统自带jdk的卸载,新版本jdk的安装,tomcat的安装部署. 一 CentOS的网络设置 利用桥接模式,让CentOS连接到网络. Vi /etc/sysconfig/network-scripts/ifcfg-eth0 修改onboot=yes 保存退出 Ifconfig命令查看网络情况 可以看到ip地址 这时就能够ping通外

在linux下用tomcat部署java web项目的过程与注意事项

在linux下用tomcat部署java web项目的过程与注意事项(原创) 一.安装JDK到http://www.oracle.com/technetwork/java/javase/downloads/index.html下载Java SE 6 Update 27根据操作系统选择Linux x64 - RPM Installer或Linux x86 - RPM Installer下载jdk-6u27-linux-x64-rpm.bin后放在/home目录中,当然其它地方也行.注意:LINUX

在linux下用tomcat部署java web项目

在linux下用tomcat部署java web项目的过程与注意事项(原创) 一.安装JDK 到http://www.oracle.com/technetwork/java/javase/downloads/index.html下载Java SE 6 Update 27 根据操作系统选择Linux x64 - RPM Installer或Linux x86 - RPM Installer 下载jdk-6u27-linux-x64-rpm.bin后放在/home目录中,当然其它地方也行. 注意:L

基于IBM Bluemix部署Java Web项目实战演练

林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要介绍了IBM Bluemix,并详细说明了如何部署Java Web项目,如何添加MySql服务.最后,提出了自己的一些看法.  文章目录 一.Bluemix简单介绍 二.BlueMix空间申请试用 三.BlueMix创建Cloud Foundry应用 四.添加新的服务 五.总结 一.Bluemix 简单介绍 1.Bluemix 带来了什么        Bluemix 致力于解

阿里云部署Java web项目初体验

林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了如何在阿里云上安装JDK.Tomcat以及其配置过程.最后以一个实例来演示在阿里云上部署Java web项目. 本文实例访问:http://120.24.19.24:8080/JavaHelloWorld-0.0.1-SNAPSHOT/ (到2016.3.9就不能访问了) 本文实例下载: 一.准备工作 1.注册账号 下载完成后.可到这里https://free.aliyun

Docker学习笔记三:Docker部署Java web系统

Docker部署Java Web系统 1.在root目录下创建一个路径test/app mkdir test && cd test&& mkdir app &&cd app 2.将apache-tomcat-7.0.29.tar.gz及jdk-7u25-linux-x64.tar.gz拷贝 到app目录下 3.解压两个tar.gz文件 tar -zxvf apache-tomcat-7.0.29.tar.gz tar -zxvf jdk-7u25-linux

阿里云部署Java web项目初体验(转)

林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了如何在阿里云上安装JDK.Tomcat以及其配置过程.最后以一个实例来演示在阿里云上部署Java web项目. 本文实例访问:http://120.24.19.24:8080/JavaHelloWorld-0.0.1-SNAPSHOT/(到2016.3.9就不能访问了) war包有需要的可以来这里下载:http://download.csdn.net/detail/evan

Tomcat中部署Java Web应用程序的方式

Tomcat中部署Java Web应用程序的几种方式: #PetWeb是工程名 1.在TOMCAT_HOME\conf\server.xml文件的HOST节点中加入 <Context docBase="F:/workspaces/PetWeb" reloadable="false" path="/Pet"/> 其中reloadable="false"表示当应用程序中的内容发生更改之后服务器不会自动加载,这个属性在开