5月 242019
 

官方Yum仓库地址

https://pkg.jenkins.io/redhat-stable/

安装Jenkin LTS版本的Yum仓库源

[root@iZj6cehstgjoj3qav88fidZ ~]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
--2019-06-12 18:27:21-- https://pkg.jenkins.io/redhat-stable/jenkins.repo
Resolving pkg.jenkins.io (pkg.jenkins.io)... 52.202.51.185
Connecting to pkg.jenkins.io (pkg.jenkins.io)|52.202.51.185|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85
Saving to: ‘/etc/yum.repos.d/jenkins.repo’

100%[=======================================================================================================================================================>] 85 --.-K/s in 0s

2019-06-12 18:27:22 (19.3 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [85/85]

[root@iZj6cehstgjoj3qav88fidZ ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
[root@iZj6cehstgjoj3qav88fidZ ~]#

安装OpenJDK环境并查看版本信息
[root@iZj6cehstgjoj3qav88fidZ ~]# yum install java-1.8.0-openjdk
[root@iZj6cehstgjoj3qav88fidZ ~]# java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
[root@iZj6cehstgjoj3qav88fidZ ~]#

使用Yum源安装Jenkins服务

[root@iZj6cehstgjoj3qav88fidZ ~]# yum install jenkins

查看安装路径

[root@iZj6cehstgjoj3qav88fidZ ~]# rpm -lq jenkins
/etc/init.d/jenkins
/etc/logrotate.d/jenkins
/etc/sysconfig/jenkins
/usr/lib/jenkins
/usr/lib/jenkins/jenkins.war
/usr/sbin/rcjenkins
/var/cache/jenkins
/var/lib/jenkins
/var/log/jenkins
[root@iZj6cehstgjoj3qav88fidZ ~]#

查看Jenkins服务注册信息

[root@iZj6cehstgjoj3qav88fidZ ~]# chkconfig --list jenkins

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.

jenkins 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@iZj6cehstgjoj3qav88fidZ ~]#

启动服务

[root@iZj6cehstgjoj3qav88fidZ ~]# service jenkins start
Starting jenkins (via systemctl): [ OK ]
[root@iZj6cehstgjoj3qav88fidZ ~]#

查看监听

使用浏览器访问

查看初始密码

[root@iZj6cehstgjoj3qav88fidZ ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
5228940ac30a481d97a4efbabe4147a3
[root@iZj6cehstgjoj3qav88fidZ ~]#

安装推荐的插件

插件安装过程

创建第一个管理员用户

实例配置

安装完成

控制台首页

6月 282016
 

 

已启用iptables防火墙服务的主机,开放1099端口,启动服务,发现visualvm无法获取数据,jstatd日志无输出

[root@linuxcache bin]# ./jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.logCalls=true -p 1099
Jun 28, 2016 3:06:04 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(1)-120.111.100.123: [120.111.100.123: sun.rmi.registry.RegistryImpl[0:0:0, 0]: void rebind(java.lang.String, java.rmi.Remote)]
Jun 28, 2016 3:06:04 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(2)-120.111.100.123: [120.111.100.123: sun.rmi.transport.DGCImpl[0:0:0, 2]: java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[], long, java.rmi.dgc.Lease)]
Jun 28, 2016 3:06:13 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-58.60.169.210: [58.60.169.210: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]

通过查看jstatd进程端口监听,发现进程额外启用了一个随机端口。

[root@linuxcache ~]# netstat -lutnp |grep jstatd
tcp 0 0 0.0.0.0:1099 0.0.0.0:* LISTEN 23209/./jstatd 
tcp 0 0 0.0.0.0:55941 0.0.0.0:* LISTEN 23209/./jstatd 
[root@linuxcache ~]#

在防火墙中放开随机监听端口后,jstatd日志正常输出,visualvm连接成功并显示数据。

[root@linuxcache ~]# iptables -I INPUT -p tcp --dport 55941 -j ACCEPT
[root@linuxcache ~]#
6月 092016
 

1,安装JDK

visualvm-and-tomcat-jvm-01

[root@localhost ~]# yum install jdk-7u80-linux-x64.rpm


[root@localhost ~]# java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
[root@localhost ~]#

2,运行Tomcat

[root@localhost ~]# tar xzf apache-tomcat-7.0.69.tar.gz
[root@localhost ~]# mv apache-tomcat-7.0.69 /usr/local/
[root@localhost ~]# cd /usr/local/apache-tomcat-7.0.69/bin/
[root@localhost bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.69
Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.69
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.69/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-7.0.69/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.69/bin/tomcat- 
juli.jar
Tomcat started.
[root@localhost bin]#

查看端口监听

visualvm-and-tomcat-jvm-02

访问页面

visualvm-and-tomcat-jvm-03
3,使用jstatd提供监控

新建一个安全策略配置文件
进入jstatd命令所在目录

visualvm-and-tomcat-jvm-04

root@localhost bin]# vi jstatd.all.policy
grant codebase "file:${java.home}/../lib/tools.jar" {
 permission java.security.AllPermission;
};

修改本机hosts主机名及IP对应关系

[root@localhost ~]# hostname -i
127.0.0.1 127.0.0.1
[root@localhost ~]#

修改

#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.95 localhost localhost.localdomain

再次确认

[root@localhost ~]# hostname -i
192.168.2.95
[root@localhost ~]#

启动jstatd服务
使用-p指定端口,默认TCP/1099
使用-J-Djava.rmi.server.logCalls=true开启日志
使用-J-Djava.rmi.server.hostname=192.168.2.95指定主机IP地址

[root@localhost ~]# cd /usr/java/jdk1.7.0_80/bin/
[root@localhost bin]# ./jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.logCalls=true -p 11099

内容引用:

Using Internal RMI Registry

This example demonstrates starting jstatd with an internal RMI registry. This example assumes that no other server is bound 
to the default RMI Registry port (port 1099).
jstatd -J-Djava.security.policy=all.policy

Enabling RMI logging capabilities.

This example demonstrates starting jstatd with RMI logging capabilities enabled. This technique is useful as a 
troubleshooting aid or for monitoring server activities.
jstatd -J-Djava.security.policy=all.policy -J-Djava.rmi.server.logCalls=true

-p portPort number where the RMI registry is expected to be found, or, if not found, created if -nr is not specified.

 

使用VisualVM连接jstatd主机

visualvm-and-tomcat-jvm-05

visualvm-and-tomcat-jvm-06 visualvm-and-tomcat-jvm-07
4,使用jmx提供监控

修改catalina.sh并重启tomcat服务

XMX和XMS设置值相同,MaxPermSize和MinPermSize设置值相同,可以避免伸缩堆内存大小带来的应用程序暂停,使用户访问Web或Application时获得流畅的体验。

[root@localhost ~]# cd /usr/local/apache-tomcat-7.0.69/bin/
[root@localhost bin]# vi catalina.sh

JAVA_OPTS="-Xms256m -Xmx256m -XX:PermSize=128m -XX:MaxPermSize=128m"

CATALINA_OPTS="-Djava.rmi.server.hostname=192.168.2.95
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8081
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false"

重启tomcat并确认端口监听

[root@localhost bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.69
Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.69
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.69/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-7.0.69/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.69/bin/tomcat- 
juli.jar
Tomcat started.
[root@localhost bin]# netstat -ltn |grep 8081
tcp 0 0 :::8081 :::* LISTEN
[root@localhost bin]#

使用VisualVM连接jstatd主机

visualvm-and-tomcat-jvm-08

visualvm-and-tomcat-jvm-09 visualvm-and-tomcat-jvm-10