Centos6.8 下 從零開始 部署 Java Web 應用

1、硬件信息

CPU:html

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

系統:java

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

內存:mysql

[root@localhost ~]# 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

硬盤:linux

[root@localhost ~]# 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:web

[root@localhost 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
[root@localhost ~]# 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線程redis

系統:Centos6.8sql

內存:16Gshell

硬盤:50G + 860G + 477M數據庫

軟件:Tomcat8.35 \ JDK1.8.0_191-b12express

 

2、調整Linux設置

2.一、調整DNS

1)編輯DNS

[root@localhost ~]# vi /etc/resolv.conf
[root@localhost ~]# cat /etc/resolv.conf
#阿里雲 DNS
nameserver 223.5.5.5
nameserver 223.6.6.6

#Google DNS
nameserver 8.8.8.8 

2)重啓網絡服務

[root@localhost ~]# service network restart
正在關閉接口 em2:                                         [肯定]
關閉環回接口:                                             [肯定]
彈出環回接口:                                             [肯定]
彈出界面 em2: Determining if ip address 221.235.184.199 is already in use for device em2...
                                                           [肯定]

 

2.二、調整軟件源

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

若是無wget命令,則手動編輯。

 

2.三、安裝ntp ,用於同步系統時間

1)安裝並啓動

[root@localhost ~]# yum -y install ntp

2)同步時間

[root@localhost ~]# 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

[root@localhost ~]# vi /etc/ntp.conf
[root@localhost ~]# 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)設置當前時區爲上海

[root@localhost ~]# rm -rf /etc/localtime
[root@localhost ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

5)啓動ntpd服務

ntpd 已停
[root@localhost ~]# service ntpd start
正在啓動 ntpd: [肯定]
[root@localhost ~]# service ntpd status
ntpd (pid 30317) 正在運行...
[root@loahlhost ~]# 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.四、關閉selinux

1)臨時關閉:

[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive

2)永久關閉:

[root@localhost ~]# vim /etc/sysconfig/selinux

SELINUX=enforcing 改成 SELINUX=disabled

[root@localhost ~]# 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.五、調整ulimit

1)查看當前限制

[root@localhost ~]# 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設置參考 )

[root@localhost ~]# ulimit -n 65535
[root@localhost ~]# ulimit -u 65535

3)永久修改

[root@localhost ~]# vi /etc/security/limits.conf

在文件末尾添加如下內容:

* soft noproc 65535
* hard noproc 65535 * soft nofile 65535 * hard nofile 65535
[root@localhost ~]# 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)再次查看當前限制信息

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.六、調整SSH,保持長鏈接

[root@localhost ~]# vi /etc/ssh/sshd_config

ClientAliveInterval 60   #server每隔60秒發送一次請求給client,而後client響應,從而保持鏈接

ClientAliveCountMax 3  #server發出請求後,客戶端沒有響應得次數達到3,就自動斷開鏈接,正常狀況下,client不會不響應

[root@localhost ~]# service sshd restart
中止 sshd:                                                [肯定]
正在啓動 sshd:                                            [肯定]

 

2.七、 安裝crontab

[root@localhost ~]# yum install vixie-cron crontab
[root@localhost ~]# chkconfig --level 2345 crond on

 

2.八、安裝輔助命令

[root@localhost ~]# yum install wget zip unzip lrzsz telnet

 

3、安裝執行環境

3.一、下載JAVA JDK

[root@localhost ~]# 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

[root@localhost ~]# yum install jdk-8u191-linux-x64.rpm

3.二、安裝MySQL

1)下載MySQL

[root@localhost ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar
[root@localhost ~]# tar xvf mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar
[root@localhost ~]# yum install mysql-*.rpm
[root@localhost ~]# 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"

[root@localhost ~]# 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=1000
wait_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

[root@localhost ~]# service mysqld start
[root@localhost ~]# chkconfig --level 2345 mysqld on

4)查看msyql root密碼

[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log

5)登陸mysql

[root@localhost ~]# mysql -uroot -p密碼

6)修改密碼

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼';

7)編輯防火牆,開放端口3306

[root@localhost ~]# vi /etc/sysconfig/iptables

添加一條命令:

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

[root@localhost ~]# 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
COMMI

8)重啓防火牆

[root@localhost ~]# service iptables restart

 

3.三、安裝redis

[root@localhost ~]# yum install epel-release   #添加epel源
[root@localhost ~]# yum install redis
[root@localhost ~]# service redis start
[root@localhost ~]# chkconfig --level 2345 redis on

 

3.四、下載Tomcat ( 官網下載地址 )

[root@localhost ~]# 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
[root@localhost ~]# cd /home/server/tomcat8
[root@localohst ~]# tar zxvf apache-tomcat-8.5.35.tar.gz

 

3.五、上傳Web應用代碼

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

➜  ~ rsync webApllication.war root@www.xxx.com:/home/server/tomcat8.35/webapps/
[root@localohst ~]# jar xvf webApllication.war

 

3.六、jvisualvm遠程監控tomcat

1)添加以下配置:

[root@localohst ~]# 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.passwordDcom.sun.management.jmxremote.access.file=SERVERROOTDIR/conf/jmxremote.password−Dcom.sun.management.jmxremote.access.file=SERVER_ROOT_DIR/conf/jmxremote.access"

 

[root@localohst ~]# 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 "$@"

2)設置遠程監控帳號:

[root@localhost conf]# vi /home/server/tomcat8.35/conf/jmxremote.access

內容以下: 

用戶名 權限類型(readonly:只讀,readwrite:讀寫)

[root@localhost conf]# cat jmxremote.access
guest readonly
root readwrite

設置遠程監控密碼: 

用戶名 密碼

[root@localhost conf]# vi /home/server/tomcat8.35/conf/jmxremote.password
[root@localhost conf]# cat /home/server/tomcat8.35/conf/jmxremote.password
guest xxxxxx
root xxxxxx

3)設置文件權限

[root@localhost conf]# chmod 600 /home/server/tomcat8.35/conf/jmxremote*

4)啓動web應用

[root@localhost conf]# sh /home/server/tomcat8.35/bin/startup.sh

PS: Java性能調優:利用VisualVM進行性能分析

 

3.七、輔助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.日誌清理腳本

[root@localhost ~]# 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、壓力測試

4.一、安裝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.二、使用說明

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.三、運行結果

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.

 

5、jvisualvm遠程監控

5.一、啓動jvisualvm

➜  ~ jvisualvm

 

5.二、添加遠程主機

 

5.三、輸入服務IP、默認端口1099,點擊確認。

 

5.四、添加JMX鏈接,輸入端口(本文1100)、用戶名、密碼,勾選不要求SSL。

 

5.五、打開鏈接,查看監控信息。

參考: jvisualvm遠程監控tomcat

 

6、JProfiler遠程監控

6.一、下載JProfiler並安裝

[root@localhost ~]# wget https://download-keycdn.ej-technologies.com/jprofiler/jprofiler_linux_9_1_1.rpm
[root@localhsot ~]# yum -y install jprofiler_linux_9_1_1.rpm

 

6.二、下載並安裝JProfile客戶端,輸入註冊碼

下載地址:http://pan.baidu.com/s/1o8kAHIi

https://download-keycdn.ej-technologies.com/jprofiler/jprofiler_windows-x64_9_1_1.exe
https://download-keycdn.ej-technologies.com/jprofiler/jprofiler_windows-x64_9_1_1.zip

註冊碼:

L-Larry_Lau@163.com#23874-hrwpdp1sh1wrn#0620

L-Larry_Lau@163.com#36573-fdkscp15axjj6#25257

L-Larry_Lau@163.com#5481-ucjn4a16rvd98#6038
L-Larry_Lau@163.com#99016-hli5ay1ylizjj#27215
L-Larry_Lau@163.com#40775-3wle0g1uin5c1#0674
--------------------------------------------------------------
L-Larry_Lau@163.com#7009-14frku31ynzpfr#20176
L-Larry_Lau@163.com#49604-1jfe58we9gyb6#5814
L-Larry_Lau@163.com#25531-1qcev4yintqkj#23927
L-Larry_Lau@163.com#96496-1qsu1lb1jz7g8w#23479
L-Larry_Lau@163.com#20948-11amlvg181cw0p#171159 
View Code

打開軟件,選擇 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:

 Java性能調優:利用VisualVM進行性能分析

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

jvisualvm遠程監控tomcat

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

相關文章
相關標籤/搜索