1
2
|
[root@localhost
[root@localhost
|
1
2
3
4
5
6
7
|
[root@localhost
#添加环境变量,增加如下内容
JAVA_HOME=/usr/java/jdk1.
6
.0_21
export
[root@localhost
#执行下脚本,使环境立即生效
[root@localhost
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
-XX:+<option>开启此参数指定的功能
-XX:-<option>关闭功能
-XX:<option>=<value>给option指定的选项赋值
-XX:+PrintFlagsFinal显示所有参数
-D<name>=<value>:设置系统参数
java的相关监控命令
jps:JVM
jstat:JVM
jinfo:显示正在运行的Hotspot虚拟机的配置信息-sysprops
jmap:生成某hotspot虚拟机的内存转储快照,用于调试
可视化工具:
jconsole:java的监控与管理控制台
jvisualvm:java的虚拟平台的可视化工具
fg:使用jconsole工具
[root@localhost
6
.0_21]# jconsole #会启动一个图形界面
|
1
|
[root@localhost
|
1
2
3
4
5
6
7
8
9
10
|
<Server>
<Service>
<Connector />
<Engine>
<Host>
<Context> </Context>
</Host>
</Engine>
</Service>
</Server>
|
1
2
3
4
5
|
[root@localhost
7.0
.
40
.tar.gz -C /usr/local/
#解压到/usr/local
[root@localhost
[root@localhost
7.0
.
40
tomcat
#创建个连接文件
|
1
2
3
4
5
6
7
8
9
10
|
启动tomcat
要想启动tomcat,首先需要输出环境变量,建立tomcat的环境变量
[root@localhost
#编辑环境变量,添加如下内容
export
export
[root@localhost
#执行下脚本,使其加入到环境变量内来
[root@localhost
#查看服务运行情况,也可以使用
var
sion.sh
|
1
2
3
|
[root@localhost
index_jsp.
class
index_jsp.java
#java解析的工作目录,把index转换为.
class
和index.java
|
1
2
3
4
5
6
7
8
9
10
|
[root@localhost
#建立服务脚本,添加如下内容
#!/bin/sh
#
for
Linux.
#
2345
96
14
#
JAVA_HOME=/usr/java/latest
CATALINA_HOME=/usr/local/tomcat
export
exec
|
1
2
3
|
[root@localhost
[root@localhost
[root@localhost
|
1
2
|
[root@localhost
[root@localhost
|
1
2
3
|
[root@localhost
<role
"manager-gui"
/>
<user
"chris"
password=
"chris"
roles=
"manager-gui"
/> #roles有三种:manager-gui实现状态和Manager App查看和管理;manger-status实现Host Manager功能,如果一个用户需要使用多个角色,角色中间使用逗号隔开即可,例如roles=“manger-status,admin-gui”
|
1
2
3
4
5
6
|
[root@localhost
<Engine name=
"Catalina"
defaultHost=
"www.chris.com"
> #把默认引擎修改为我们自己的主机,方便测试
<Host
"www.chris.com"
appBase=
"/web"
unpackWARs=
"ture"
autoDeploy=
"ture"
>
<Context path=
"/"
docBase=
"webapp"
reloadable=
"ture"
/>
</Host>
|
1
2
3
4
5
6
7
|
[root@localhost
172.16
.
7.20
www.chris.com #让其能解析域名
[root@localhost
[root@localhost
[root@localhost
注意:此网站依赖于mysql,利用yum安装下mysql
[root@localhost
|
1
2
3
|
[root@localhost
mysql>
mysql>
'jcenter'
@
'localhost'
IDENTIFIED BY
'chris'
;
|
1
2
3
4
|
Development
[root@node1
106
nginx
[root@node1
106
nginx
[root@node1
|
1
2
3
4
|
[root@node1
1.4
.
1
]# cd nginx-
1.4
.
1
[root@node1
1.4
.
1
]# cd nginx-
1.4
.
1
[root@node1
1.4
.
1
]# ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/
var
/log/nginx/error.log --http-log-path=/
var
/log/nginx/access.log --pid-path=/
var
/run/nginx/nginx.pid --lock-path=/
var
/lock/nginx.lock --user=nginx --group=nginx --
with
-http_ssl_module --
with
-http_flv_module --
with
-http_stub_status_module --
with
-http_gzip_static_module --http-client-body-temp-path=/
var
/tmp/nginx/client/ --http-proxy-temp-path=/
var
/tmp/nginx/proxy/ --http-fastcgi-temp-path=/
var
/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/
var
/tmp/nginx/uwsgi --http-scgi-temp-path=/
var
/tmp/nginx/scgi --
with
-pcre
[root@node1
1.4
.
1
]# make && make install
|
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
[root@node1
1.4
.
1
]# vim /etc/init.d/nginx 添加如下内容
#!/bin/sh
#
#
this
script starts and stops the nginx daemon
#
#
85
15
#
is
an HTTP(S) server, HTTP(S) reverse \
#
#
#
#
#
var
/run/nginx.pid
#
function
library.
.
#
.
#
is
up.
[
"$NETWORKING"
=
"no"
] && exit
0
nginx=
"/usr/sbin/nginx"
prog=$(basename
NGINX_CONF_FILE=
"/etc/nginx/nginx.conf"
[
lockfile=/
var
/lock/subsys/nginx
make_dirs()
# make required directories
user=`nginx -V
2
>&
1
| grep
"configure arguments:"
| sed
's/[^*]*--user=\([^ ]*\).*/\1/g'
-`
options=`$nginx -V
2
>&
1
| grep
'configure arguments:'
`
for
opt
in
$options;
do
if
[ `echo $opt | grep
'.*-temp-path'
` ]; then
value=`echo $opt | cut -d
"="
-f
2
`
if
[ ! -d
"$value"
]; then
# echo
"creating"
$value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start()
[ -x $nginx ] || exit
5
[ -f $NGINX_CONF_FILE ] || exit
6
make_dirs
echo -n $
"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq
0
] && touch $lockfile
return
$retval
}
stop()
echo -n $
"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq
0
] && rm -f $lockfile
return
$retval
}
restart()
configtest ||
return
$?
stop
sleep
1
start
}
reload()
configtest ||
return
$?
echo -n $
"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload()
restart
}
configtest()
$nginx -t -c $NGINX_CONF_FILE
}
rh_status()
status $prog
}
rh_status_q()
rh_status >/dev/
null
2
>&
1
}
case
"$1"
in
start)
rh_status_q && exit
0
$
1
;;
stop)
rh_status_q || exit
0
$
1
;;
restart|configtest)
$
1
;;
reload)
rh_status_q || exit
7
$
1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|
try
-restart)
rh_status_q || exit
0
;;
*)
echo $
"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit
2
esac
|
1
2
3
|
[root@node1
1.4
.
1
]# chmod +x /etc/init.d/nginx
[root@node1
1.4
.
1
]# chkconfig --add nginx
[root@node1
|
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
|
http
include
mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout
65
;
proxy_cache_path /nginx/cache levels=
1
:
2
keys_zone=first:10m inactive=24h max_size=1g;
upstream backend {
server
192.168
.
0.1
weight=
1
;
}
#gzip on;
server {
listen
80
;
server_name localhost;
#charset koi8-r;
index index.jsp index.html;
#access_log logs/host.access.log main;
location ~*
"\.(jsp|do)$"
{
proxy_pass http:
//backend;
}
location / {
root html;
rewrite / http:
//172.16.7.6/index.jsp last;
}
location ~*
"\.(jpg|jpeg|png|gif|html|css)$"
{
proxy_pass http:
//backend;
proxy_cache first;
proxy_cache_valid
200
24h;
proxy_cache_valid
302
10m;
add_header X-Cache-Status $upstream_cache_status;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
外网IP
DEVICE=eth0
BOOTPROTO=
static
IPADDR=
172.16
.
7.6
NETMASK=
255.255
.
0.0
ONBOOT=yes
内网IP
DEVICE=eth1
BOOTPROTO=
static
IPADDR=
192.168
.
0.2
NATMASK=
255.255
.
255.0
ONBOOT=yes
|
1
2
3
4
5
6
7
8
9
10
11
12
|
vim
DEVICE=
"eth0"
BOOTPROTO=
"static"
GATEWAY=
"192.168.0.2"
IPADDR=
"192.168.0.1"
NETMASK=
"255.255.255.0"
NM_CONTROLLED=
"yes"
ONBOOT=
"yes"
TYPE=
"Ethernet"
设置域名解析hosts文件
vim
192.168
.
0.1
tomcat1.chris.com
|
1
2
3
4
5
6
7
8
9
10
11
12
|
vim
DEVICE=
"eth0"
BOOTPROTO=
"static"
GATEWAY=
"192.168.0.2"
IPADDR=
"192.168.0.3"
NETMASK=
"255.255.255.0"
NM_CONTROLLED=
"yes"
ONBOOT=
"yes"
TYPE=
"Ethernet"
设置域名解析hosts文件
vim
192.168
.
0.3
tomcat2.chris.com
|
1
2
3
4
5
6
7
|
[root@localhost
<Engine
"Catalina"
defaultHost=
"tomcat1.chris.com"
>
<Host
"tomcat1.chris.com"
appBase=
"/web"
unpackWARs=
"true"
autoDeploy=
"true"
>
<Context path=
"/"
docBase=
"webapp"
reloadable=
"ture"
/>
</Host>
测试页面为前面搭建的jscent
|
1
2
3
4
5
6
|
[root@localhost
<Engine
"Catalina"
defaultHost=
"tomcat2.chris.com"
>
<Host
"tomcat2.chris.com"
appBase=
"/web"
unpackWARs=
"true"
autoDeploy=
"true"
>
<Context
"/"
docBase=
"webapp"
reloadable=
"ture"
/>
</Host>
|
1
2
3
4
5
|
[root@localhost
mysql>
mysql>
'jsprun'
@
'localhost'
identified by
'chris'
;
安装、初始化jsprun
http:
//192.168.0.3/install.jsp
|
1
2
3
4
|
[root@node1
1.4
.
6
.tar.bz2
[root@node1
1.4
.
6
[root@node1
1.4
.
6
]# ./configure --prefix=/usr/local/apr --disable-ipv6
[root@node1
1.4
.
6
]# make && make install
|
1
2
3
4
|
[root@node1
1.5
.
2
.tar.bz2
[root@node1
1.5
.
2
[root@node1
1.5
.
2
]# ./configure --prefix=/usr/local/apr-util --
with
-apr=/usr/local/apr
[root@node1
1.5
.
2
]# make && make install
|
1
2
3
4
|
[root@node1
2.4
.
4
.tar.bz2
[root@node1
2.4
.
4
[root@node1
2.4
.
4
]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --
with
-zlib --
with
-pcre --
with
-apr=/usr/local/apr --
with
-apr-util=/usr/local/apr-util --enable-mpms-shared=all --
with
-mpm=event --enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-lbmethod-heartbeat --enable-heartbeat --enable-slotmem-shm --enable-slotmem-plain --enable-watchdog
[root@node1
2.4
.
4
]# make && make install
|
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
92
93
|
[root@node1
2.4
.
4
]# vim /etc/init.d/httpd
#!/bin/bash
#
#
for
the Apache HTTP Server
#
#
85
15
#
is
a World Wide Web server. It
is
used to serve \
#
#
#
#
#
var
/run/httpd.pid
#
function
library.
.
if
[ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
#
in
the C locale by
default
.
HTTPD_LANG=${HTTPD_LANG-
"C"
}
#
if
#
INITLOG_ARGS=
""
#
in
/etc/sysconfig/httpd to
use
a server
#
with
the thread-based
"worker"
MPM; BE WARNED that some modules may not
#
with
a thread-based MPM; notably PHP will refuse to start.
#
for
messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/
var
/run/httpd.pid}
lockfile=${LOCKFILE-/
var
/lock/subsys/httpd}
RETVAL=
0
start()
echo -n $
"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL =
0
] && touch ${lockfile}
return
$RETVAL
}
stop()
echo -n $
"Stopping $prog: "
killproc -p ${pidfile} -d
10
$httpd
RETVAL=$?
echo
[ $RETVAL =
0
] && rm -f ${lockfile} ${pidfile}
}
reload()
echo -n $
"Reloading $prog: "
if
! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/
null
; then
RETVAL=$?
echo $
"not reloading due to configuration syntax error"
failure $
"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
#
case
"$1"
in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if
[ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $
"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit
1
esac
exit
|
1
|
[root@node1
2.4
.
4
]# chmod +x /etc/init.d/httpd
|
1
2
3
|
[root@node1
2.4
.
4
]# chkconfig --add httpd
[root@node1
2.4
.
4
]# chkconfig httpd on
[root@node1
2.4
.
4
]# chkconfig --list httpd
|
1
2
3
|
[root@node1
export
[root@node1
|
1
2
3
4
5
6
7
8
|
httpd
proxy_module
proxy_http_module
proxy_ajp_module
lbmethod_byrequests_module
lbmethod_bytraffic_module
lbmethod_bybusyness_module
lbmethod_heartbeat_module
|
1
2
3
4
5
6
7
8
9
10
|
注释中心主机
增加虚拟主机的配置文件
#DocumentRoot
"/usr/local/apache/htdocs"
ServerRoot
"/usr/local/apache"
PidFile
"/var/run/httpd.pid"
# 增加pid
#
#Include
Include
LoadModule
LoadModule
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@node1
<VirtualHost
80
>
ProxyRequests
ProxyPass
//192.168.0.1:80/ #前面把tomcat的8080端口修改为了80
ProxyPassReverse
//192.168.0.1:80/
<Proxy
Require all granted
</Proxy>
<Location
Require all granted
</Location>
</VirtualHost>
|
1
2
3
4
|
[root@node1
1.2
.
37
-src.tar.gz
[root@node1
1.2
.
37
-src/
native
/
[root@node1
native
]# ./configure --
with
-apxs=/usr/local/apache/bin/apxs #编译apache的模块
[root@node1
native
]# make && make install
|
1
2
3
4
5
6
7
8
9
|
#
LoadModule
JkWorkersFile
JkLogFile
JkLogLevel
JkMount
为了让apache能使用/etc/httpd/extra/httpd-jk.conf配置文件中的配置信息,需要编辑/etc/httpd/httpd.conf,添加如下一行:
Include
|
1
2
3
4
5
6
7
|
[root@node1
LoadModule
JkWorkersFile
JkLogFile
JkLogLevel
JkMount
JkMount
|
1
2
3
4
5
6
7
|
[root@node1
worker.list
worker.tomcat1.type
worker.tomcat1.host
192.168
.
0.1
worker.tomcat1.port
8009
worker.tomcat1.lbfactor=
1
worker.stat1.type
|
1
2
|
[root@localhost
<Engine
"Catalina"
defaultHost=
"tomcat1.chris.com"
jvmRoot=
"tomcat1"
>
|
1
|
[root@localhost
|
1
2
3
4
|
[root@localhost
<Engine
"Catalina"
defaultHost=
"tomcat2.chris.com"
jvmRoot=tomcat2
""
>
[root@localhost
[root@localhost
|
1
2
3
4
5
6
7
|
修改/etc/httpd/extra/httpd-jk.conf为如下内容:
LoadModule
JkWorkersFile
JkLogFile
JkLogLevel
JkMount
JkMount
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
worker.list
worker.TomcatA.type
worker.TomcatA.host
172.16
.
100.1
worker.TomcatA.port
8009
worker.TomcatA.lbfactor
5
worker.TomcatB.type
worker.TomcatB.host
172.16
.
100.2
worker.TomcatB.port
8009
worker.TomcatB.lbfactor
5
worker.lbcluster1.type
worker.lbcluster1.sticky_session
1
会话绑定
worker.lbcluster1.balance_workers
worker.stat1.type
|
1
2
3
|
[root@node1
Include
#Include
|
1
2
3
4
5
|
ProxyRequests
<proxy
//lbcluster1>
BalancerMember
//192.168.0.1:8009 loadfactor=10 route=tomcat1
BalancerMember
//192.168.0.3:8009 loadfactor=10 route=tomcat2
</proxy>
|
1
2
3
4
5
|
<VirtualHost
80
>
ServerName
ProxyPass
//lbcluster1/ stickysession=jsessionid
ProxyPassReverse
//lbcluster1/
</VirtualHost>
|