mac tomcat多开

Mac自带Apache服务器的使用

  1. 打开终端,开启Apache:
1
2
3
4
5
开启apache:  sudo apachectl start

重启apache: sudo apachectl restart

关闭apache: sudo apachectl stop

回车会提示输入密码,也就是你电脑的密码,http://127.0.0.1/测试一下,成功则如
下图:

Alt text

  1. 点击Finder,然后Command+Shift+G,前往Apache服务器的文件路径(/Library/WebServer/Documents),如图:

Alt text

在步骤1中只输入一个http://127.0.0.1其实默认打开的是index.html.en(html是一个网页文件),该文件的内容就是在步骤1中测试时浏览器所显示的内容。此时如果我在浏览器的网址框输入的是http://127.0.0.1/PoweredByMacOSX.gif, 浏览器就便会显示PoweredByMacOSX.gif图片,如果没有正常显示,提示说没有权限时,单击该文件,然后Command+I在末尾设置权限即可。

  1. 测试
    创建一个文件,如test.html(名字能够随意起),
    接下来用浏览器访问 http://127.0.0.1/test.html
    IP(127.0.0.1)也可以换成你电脑的IP地址,这样在同一局域网的设备也可以访问服务器的内容。
    PS:使用过后,记得关闭服务器,要不然会一直消耗你电脑内存,后果你懂的。

tomcat 多开, 前提是已经配好了CATALINA_HOME等的配置

只能开7个8082到8088 , 开第8个, 端口冲突…懒得改了, 8080普通tomcat用, 8081私服用.

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
#!/bin/bash

mkdir -p $HOME/soft/tomcat_cluster

tomcat_cluster_path="$HOME/soft/tomcat_cluster"

tomcat_names=()
tomcat_starts=()

if [ ! -n "$1" ] ;then
count=3
else
count=$1
fi

for (( i=0; i<"$count"; i=i+1 ))

do
tomcat_names+=("tomcat`expr 8082 + $i`")

done

for (( i=0; i<"$count"; i=i+1 ))

do
# echo ${tomcat_names[$i]}
mkdir -p $tomcat_cluster_path/${tomcat_names[$i]}/bin
cp -R $CATALINA_HOME/conf/ $tomcat_cluster_path/${tomcat_names[$i]}/conf/
cp -R $CATALINA_HOME/webapps/ $tomcat_cluster_path/${tomcat_names[$i]}/webapps/
touch $tomcat_cluster_path/${tomcat_names[$i]}/bin/startup.sh
chmod +x $tomcat_cluster_path/${tomcat_names[$i]}/bin/startup.sh

filename="$tomcat_cluster_path/${tomcat_names[$i]}/bin/startup.sh"
tomcatname=${tomcat_names[$i]}

printf '#!/bin/bash

export JRE_HOME=$JAVA_HOME/jre
export CATALINA_HOME=$CATALINA_HOME
export CATALINA_BASE="%s/%s"
export CATALINA_TMPDIR="$CATALINA_BASE/temp"
export CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Djava.awt.headless=true -Dtomcat.name=%s"

#创建logs目录
if [ ! -d "$CATALINA_BASE/logs" ]; then
mkdir $CATALINA_BASE/logs
fi

#创建temp目录
if [ ! -d "$CATALINA_BASE/temp" ]; then
mkdir $CATALINA_BASE/temp
fi

# 调用tomcat启动脚本
bash $CATALINA_HOME/bin/startup.sh "$@"' "$tomcat_cluster_path" "$tomcatname" "$tomcatname" > $filename

filepath="$tomcat_cluster_path/$tomcatname/webapps/ROOT/index.jsp"

sed -i "" "s/<h1>\${pageContext.servletContext.serverInfo}/<h1>\${pageContext.servletContext.serverInfo} | $tomcatname/g" $filepath

val=`expr $i + 2`
serverpath="$tomcat_cluster_path/$tomcatname/conf/server.xml"

sed -i "" "s/<Server port=\"8005\"/<Server port=\"80`echo $val`5\"/g" $serverpath
sed -i "" "s/<Connector port=\"8080\"/<Connector port=\"808`echo $val`\"/g" $serverpath
sed -i "" "s/<Connector port=\"8009\"/<Connector port=\"80`echo $val`9\"/g" $serverpath

$tomcat_cluster_path/${tomcat_names[$i]}/bin/startup.sh

tomcat_starts+=("$tomcat_cluster_path/${tomcat_names[$i]}/bin/startup.sh")

done

echo "#!/bin/bash" > startups.sh

for (( i=0; i<"$count"; i=i+1 ))

do
echo ${tomcat_starts[$i]} >> startups.sh
done

echo -e "\033[0;33;1m■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\033[0m"

success=`cat startups.sh`

echo -e "\033[0;32;1m$success\033[0m"