Linux系统

Linux的Tomcat部署

2018-10-11  本文已影响0人  ssttIsme
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.161.1:3306/exdb2?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
jdbc.username=root
jdbc.password=123456

run as maven install

改名字为Root.war

1.部署单台Tomcat
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# mkdir tomcats
[root@localhost src]# cd tomcats/
上传tomcat安装包linux版


[root@localhost tomcats]#
[root@localhost tomcats]# ls
apache-tomcat-7.0.55.tar.gz
解压安装文件
[root@localhost tomcats]# tar -xvf apache-tomcat-7.0.55.tar.gz
[root@localhost tomcats]# ls
apache-tomcat-7.0.55 apache-tomcat-7.0.55.tar.gz
改名字
[root@localhost tomcats]# mv apache-tomcat-7.0.55 tomcat-8091
删除压缩包
[root@localhost tomcats]# rm apache-tomcat-7.0.55.tar.gz

rm: remove regular file `apache-tomcat-7.0.55.tar.gz'? y
进入
[root@localhost tomcats]# cd tomcat-8091/
[root@localhost tomcat-8091]# ls
bin lib logs RELEASE-NOTES temp work
conf LICENSE NOTICE RUNNING.txt webapps
[root@localhost tomcat-8091]# cd conf/
[root@localhost conf]# vim server.xml

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Connector port="8091" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

改完后 :wq
[root@localhost conf]# cd ../
[root@localhost tomcat-8091]# cd bin

[root@localhost bin]# ls
bootstrap.jar                 setclasspath.sh
catalina.bat                  shutdown.bat
catalina.sh                   shutdown.sh
catalina-tasks.xml            startup.bat
commons-daemon.jar            startup.sh
commons-daemon-native.tar.gz  tomcat-juli.jar
configtest.bat                tomcat-native.tar.gz
configtest.sh                 tool-wrapper.bat
daemon.sh                     tool-wrapper.sh
digest.bat                    version.bat
digest.sh                     version.sh
setclasspath.bat

启动tomcat
[root@localhost bin]# sh startup.sh
或者
[root@localhost bin]# ./startup.sh

Using CATALINA_BASE:   /usr/local/src/tomcats/tomcat-8091
Using CATALINA_HOME:   /usr/local/src/tomcats/tomcat-8091
Using CATALINA_TMPDIR: /usr/local/src/tomcats/tomcat-8091/temp
Using JRE_HOME:        /usr/local/src/java/jdk1.8.0_51
Using CLASSPATH:       /usr/local/src/tomcats/tomcat-8091/bin/bootstrap.jar:/usr/local/src/tomcats/tomcat-8091/bin/tomcat-juli.jar
Tomcat started.

操作时
关闭防火墙
[root@localhost bin]# service iptables stop

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]

在windows浏览器输入
http://192.168.161.130:8091/



[root@localhost bin]# ./shutdown.sh
将webapps中的ROOT文件夹先删除再部署war包
[root@localhost bin]# cd ..
[root@localhost tomcat-8091]# cd webapps/
[root@localhost webapps]# rm -rf ROOT/
拖入war包
[root@localhost webapps]# ls
docs examples host-manager manager ROOT.war
[root@localhost webapps]# cd ../bin/
[root@localhost bin]# sh startup.sh
检查日志文件
[root@localhost bin]# cd ../
[root@localhost tomcat-8091]# cd logs
[root@localhost logs]# ls
catalina.2018-10-10.log
catalina.out
host-manager.2018-10-10.log
localhost.2018-10-10.log
localhost_access_log.2018-10-10.txt
manager.2018-10-10.log
看日志catalina.out
[root@localhost logs]# cat catalina.out
要能看到
Oct 10, 2018 7:29:44 PM org.apache.catalina.startup.Catalina start

在pc浏览器端输入
http://192.168.161.130:8091/

要求:需要在mysql客户端执行
语法:
    grant [权限] on [数据库名].[表名] to ['用户名']@['web服务器的ip地址'] identified by ['密码'];
     
    grant all on *.* to 'root'@'%' identified by '123456';
        或者指定IP地址
    grant all on *.* to 'root'@'192.168.161.1' identified by '123456';
#Linux集群部署
    upstream jtLinux{
        server 192.168.161.130:8091;
        server 192.168.161.130:8092;
        server 192.168.161.130:8093;
    }
    #后台系统
    server{
        listen 80;
        server_name manage.jt.com;
        location / {
            proxy_pass http://jtLinux;
            #proxy_connect_timeout       1;  
            #proxy_read_timeout      1;  
            #proxy_send_timeout      1; 
        }
    }

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

   

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

    #实现图片回显 配置图片服务器 image.jt.com
    server{
        listen 80;
        server_name image.jt.com;
        #个别电脑需要区分斜杠
        location / {
            root D:/jtupload; 
        }
    }
    #配置tomcat负载均衡 1.轮询 2.权重 3.ip_hash方式
    upstream jt{
        #ip_hash;
        server localhost:8091 max_fails=1 fail_timeout=60s;
        server localhost:8092 max_fails=1 fail_timeout=60s;
        server localhost:8093 max_fails=1 fail_timeout=60s;
    }
    #Linux集群部署
    upstream jtLinux{
        server 192.168.161.130:8091;
        server 192.168.161.130:8092;
        server 192.168.161.130:8093;
    }
    #后台系统
    server{
        listen 80;
        server_name manage.jt.com;
        location / {
            proxy_pass http://jtLinux;
            #proxy_connect_timeout       1;  
            #proxy_read_timeout      1;  
            #proxy_send_timeout      1; 
        }
    }
}


用浏览器访问
http://manage.jt.com/index

上一篇下一篇

猜你喜欢

热点阅读