1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
jdk8 sls文件:cat /srv/salt/init/tomcat8.sls
tomcat-install:
file.managed:
- name: /tmp/apache-tomcat-8.5.4.tar.gz
- source: salt://init/files/apache-tomcat-8.5.4.tar.gz
- user: root
- group: root
- mod: 755
cmd.run:
- name: tar -zxf /tmp/apache-tomcat-8.5.4.tar.gz && mv apache-tomcat-8.5.4 /usr/local/tomcat && chown -R root:root /usr/local/tomcat
- unless: test -d /usr/local/tomcat
- require:
- file: tomcat-install
tomcat-config:
file.append:
- name: /etc/profile
- text:
- export TOMCAT_HOME=/usr/local/tomcat
安装jdk8:salt-ssh '*' state.sls init.jdk8
tomcat8 sls文件:cat /srv/salt/init/jdk8.sls
tomcat-install:
file.managed:
- name: /tmp/apache-tomcat-8.5.4.tar.gz
- source: salt://init/files/apache-tomcat-8.5.4.tar.gz
- user: root
- group: root
- mod: 755
cmd.run:
- name: useradd -u 800 tomcat && tar -zxf /tmp/apache-tomcat-8.5.4.tar.gz && mv apache-tomcat-8.5.4 /usr/local/tomcat && chown -R tomcat:tomcat /usr/local/tomcat
- unless: test -d /usr/local/tomcat
- require:
- file: tomcat-install
tomcat-config:
file.append:
- name: /etc/profile
- text:
- export TOMCAT_HOME=/usr/local/tomcat
start-config:
cmd.run:
- name: source /etc/profile && su - tomcat -c "/usr/local/tomcat/bin/startup.sh"
file.append:
- name: /etc/rc.local
- text:
- su - tomcat -c "/usr/local/tomcat/bin/startup.sh"
安装tomcat8:salt-ssh '*' state.sls init.tomcat8
配置tomcat 8管理用户(tomcat7只需第一步)
1、修改/usr/local/tomcat/conf/tomcat-users.xml文件,添加如下内容
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="admin,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status"/>
2、创建/usr/local/tomcat/conf/Catalina/localhost/manager.xml文件,内容如下
<Context privileged="true" antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>
tomcat安全管理
1、修改telnet管理端口号8005
2、ajp连接端口8009保护
3、禁用tomcat manager
4、必须使用非root账号启动tomcat
部署jenkins.war(2.32)
1、上传jenkins.war到/usr/local/tomcat/webapps
2、重启tomcat:/usr/local/tomcat/bin/shutdown.sh && /usr/local/tomcat/bin/startup.sh
3、通过浏览器jenkins,密码:cat /root/.jenkins/secrets/initialAdminPassword
4、创建管理员账号jenkins,密码jenkins
5、修改管理员admin密码为jenkins
常用命令
查看java进程:jps -lvm
实例:处理jvm占用CPU高
1、使用jps -lvm获取进程PID
1250 org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp
2534 sun.tools.jps.Jps -lvm -Denv.class.path=.:/usr/local/jdk/lib:/usr/local/jdk/jre/lib:/usr/local/jdk/lib/tools.jar -Dapplication.home=/usr/local/jdk -Xms8m
2、使用jstack 1250 > 17167.txt导出占用高进程的线程栈
3、使用top -H -p 1250查看哪个线程占用CPU高
4、使用echo "obase=16;1252" | bc 将PID转换为16进制
5、根据转换的16进制PID在17167.txt中查看相应的线程(16进制字母小写)
监控jvm
1、jvm开启远程连接
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.managemnet.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=192.168.8.21"(不对ip地址)
2、使用/usr/local/jdk/bin/jconsole远程连接,查看性能
3、使用/usr/local/jdk/bin/jvisualvm远程连接,查看性能
本文转自1321385590 51CTO博客,原文链接:
http://blog.51cto.com/linux10000/1908000
,如需转载请自行联系原作者
|
saltstack 安装 tomcat8
最新推荐文章于 2024-08-18 23:25:39 发布