Tomcat基础

Tomcat基础

  1. tomcat服务器是一个免费的开放源代码的web应用服务器,属于轻量级应用服务器,是开发和调试jsp程序的首选。
    tomcat是apache服务器的扩展,是作为一个与apache独立的进程单独运行的
  1. java web 环境:Nginx+JDK+Tomcat+MySQL
    1)所有服务器部署在同一台主机上,也可以分开部署
    2)Nginx默认开启的是80端口,用来接受用户的web请求
    3)tomcat默认开启的是8080端口,用来接受nginx转发过来的web请求
  1. 环境部署流程(服务器IP:192.168.88.100)
    1)安装JDK(java解析器)
         [root@tomcat ~]# tar xf jdk-7u25-linux-x64.tar.gz
         [root@tomcat ~]# mv jdk1.7.0_25/* /usr/local/jdk1.7
         vim /etc/profile
         export JAVA_HOME=/usr/local/jdk1.7
         export JAVA_BIN=/usr/local/jdk1.7/bin
         export PATH=$PATH:$JAVA_HOME/bin
         export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
         [root@tomcat ~]# source /etc/profile
         [root@tomcat ~]# java -version
         
     2)安装tomcat
         [root@tomcat ~]# tar xf apache-tomcat-8.5.51.tar.gz     
         [root@tomcat ~]# cp -a apache-tomcat-8.5.51 /usr/local/tomcat
         vim /etc/profile
         export TOMCAT_HOME=/usr/local/tomcat
         export PATH=$PATH:$TOMCAT_HOME/bin
         [root@tomcat ~]# source /etc/profile
         [root@tomcat ~]# chmod +x /usr/local/tomcat/bin/*
         [root@tomcat ~]# /usr/local/tomcat/bin/catalina.sh start
         [root@tomcat ~]# netstat -antp | grep 8080
         [root@tomcat ~]# systemctl stop firewalld.service
         [root@tomcat ~]# systemctl disable firewalld.service

     3)CentOS6编译安装MySQL
         [root@localhost ~]# yum -y install ncurses-devel gcc*
         [root@localhost ~]# useradd -r -s  /sbin/nologin mysql
         [root@localhost ~]# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312
         [root@localhost ~]# make
         [root@localhost ~]# make install
         
         生成配置文件
         [root@localhost ~]# cp -a support-files/my-medium.cnf /etc/my.cnf
         [root@localhost ~]#  ln -s /usr/local/mysql/bin/* /usr/local/bin/
         [root@localhost ~]# ln -s /usr/local/mysql/sbin/* /usr/local/sbin/
         
         初始化数据库,生成授权表
         [root@localhost ~]# cd /usr/local/mysql/
         [root@localhost mysql]# ./bin/mysql_install_db --user=mysql
         
         生成启动管理脚本,启动mysql并设置开机自启动
         [root@localhost mysql]#  cd ~/mysql-5.1.55/support-files
         [root@localhost support-files]# cp -a mysql.server /etc/init.d/mysqld
         [root@localhost support-files]# chmod +x /etc/init.d/mysqld
         [root@localhost support-files]# chkconfig --add mysqld
         [root@localhost support-files]# chkconfig mysqld on
         [root@localhost support-files]# service mysqld start
         
         为数据库的管理用户root设置登录密码
         [root@localhost support-files]# mysqladmin -uroot password 123456
         
         [root@localhost ~]# mysql -uroot -p
         Enter password: 
         Welcome to the MySQL monitor.  Commands end with ; or \g.
         Your MySQL connection id is 3
         Server version: 5.1.55-log Source distribution

         Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
         This software comes with ABSOLUTELY NO WARRANTY. This is free software,
         and you are welcome to modify and redistribute it under the GPL v2 license

         Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

         mysql> 

         
     4)安装Nginx
         [root@localhost ~]# wget http://nginx.org/download/nginx-1.2.6.tar.gz
         [root@localhost ~]# tar xf nginx-1.2.6.tar.gz
         [root@localhost ~]# yum -y install pcre-devel zlib-devel 
         [root@localhost ~]# useradd -r -s /sbin/nologin nginx
         [root@localhost ~]# cd nginx-1.2.6
         [root@localhost nginx-1.2.6]# ./configure --user=nginx --group=nginx
         [root@localhost nginx-1.2.6]# make && make install
         
         修改nginx配置文件:添加反向代理(由于都是在一台服务器上部署,所以反向代理自己,让nginx的80代理到tomcat上的8080)
         [root@localhost nginx-1.2.6]# vim /usr/local/nginx/conf/nginx.conf
         upstream tomcat {
         server 192.168.88.100:8080;
         }

         server {
         listen       80;
         server_name  localhost;

         #charset koi8-r;

         #access_log  logs/host.access.log  main;

         location / {
            root   html;
            index  index.html index.htm;
            proxy_pass http://tomcat;
            proxy_set_header Host $host;
         }
         
         重起nginx服务
         [root@localhost nginx-1.2.6]# pkill -HUP nginx
         
         部署java的war包打包的网站
         1.在/usr/local/tomcat/conf/server.xml配置文件中的 server区域中添加如下内容:
         [root@localhost ~]# vim /usr/local/tomcat/conf/server.xml
         
         
         2.将war包拷贝到webapps目录中
         [root@localhost ~]# cp -a atguigu.war /usr/local/tomcat/webapps/
         
         3.删除webapps目录下的原ROOT目录
         
         4.重启tomcat服务
         [root@localhost ~]# /usr/local/tomcat/bin/catalina.sh stop
         [root@localhost ~]# /usr/local/tomcat/bin/catalina.sh start

         5.测试:使用客户端浏览器访问Nginx服务的端口
         
4. 创建多个tomcat实例
         [root@localhost ~]# /usr/local/tomcat/bin/catalina.sh stop
         [root@localhost ~]# cp -a /usr/local/tomcat/ /usr/local/tomcat-2
         [root@localhost ~]# rm -rf /usr/local/tomcat-2/logs/*
         [root@localhost ~]# vim /usr/local/tomcat-2/conf/server.xml
         
          #把8005改成8009
         
         

你可能感兴趣的:(Tomcat基础)