一、Tomcat的安装
1.更新yum及系统
# 升级所有包和和系统内核
[root@iZbp17oxotxuhf5g2zr3brZ ~]# yum -y update
2.安装JDK
# OpenJDK install
[root@iZbp17oxotxuhf5g2zr3brZ ~]# sudo yum install java-1.8.0-openjdk -y
3.Tomcat下载安装
首先切换到/usr/src目录下
[root@iZbp17oxotxuhf5g2zr3brZ ~]# cd /usr/src
下载
# download
[root@iZbp17oxotxuhf5g2zr3brZ src]# wget https://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.57/bin/apache-tomcat-8.5.57.tar.gz
解压
# tar 命令解压
[root@iZbp17oxotxuhf5g2zr3brZ src]# tar -xvf apache-tomcat-8.5.57.tar.gz
启动
进入到/usr/src/apache-tomcat-8.5.57/bin
目录中
# 进入到tomcat目录下的bin目录中
[root@iZbp17oxotxuhf5g2zr3brZ bin]# cd /usr/src/apache-tomcat-8.5.57/bin
# 启动tomcat
[root@iZbp17oxotxuhf5g2zr3brZ bin]# ./startup.sh
查看日志
日志文件存放在tomcat目录下的logs目录中
# 回到logs目录
[root@iZbp17oxotxuhf5g2zr3brZ bin]# cd ..
# 进入logs目录
[root@iZbp17oxotxuhf5g2zr3brZ apache-tomcat-8.5.57]# cd logs
# 查看日志
[root@iZbp17oxotxuhf5g2zr3brZ logs]# tail -f catalina.out
关闭
# 关闭 ./shutdon.sh
[root@iZbp17oxotxuhf5g2zr3brZ bin]# ./shutdown.sh
访问
浏览器地址输入:IP:PORT
即可。218.244.158.200:8080
注意:PORT必须在服务器安全组中开放,否则无法访问。
关于开放端口在这篇笔记中中有说明。
二、配置域名访问
1.pcre依赖安装
进入到/usr/src
目录下
# 目录切换
[root@iZbp17oxotxuhf5g2zr3brZ bin]# cd /usr/src
下载pcre依赖
# 下载
[root@iZbp17oxotxuhf5g2zr3brZ src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
解压pcre依赖
# 解压
[root@iZbp17oxotxuhf5g2zr3brZ src]# tar -xvf pcre-8.37.tar.gz
进入解压之后的pcre目录
[root@iZbp17oxotxuhf5g2zr3brZ src]# cd pcre-8.37
编译安装
如果没有安装C会出现错误configure: error: You need a C++ compiler for C++ support.
需要先安装C
安装gcc ,c++
[root@iZbp17oxotxuhf5g2zr3brZ pcre-8.37]# yum install -y gcc gcc-c++
# check
[root@iZbp17oxotxuhf5g2zr3brZ pcre-8.37]# ./configure
# 编译安装
[root@iZbp17oxotxuhf5g2zr3brZ pcre-8.37]# make && make install
查看版本
# 查看版本
[root@iZbp17oxotxuhf5g2zr3brZ pcre-8.37]# pcre-config --version
8.37
2.其他依赖安装
通过yum方式安装其他依赖,包括zlib以及openssl,不再使用下载压缩包,编译安装的方式,且自动下载依赖。执行下面一条命令即可。
# yum 一键安装依赖
[root@localhost pcre-8.37]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
3.安装Nginx
进入到/usr/src
。通过wget方式下载nginx压缩文件包。
下载nginx
# wget下载nginx压缩包
[root@iZbp17oxotxuhf5g2zr3brZ src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
解压
# 解压
[root@iZbp17oxotxuhf5g2zr3brZ src]# tar -xvf nginx-1.12.2.tar.gz
编译安装
进入到解压之后的nginx目录下,进行编译安装。
# 切换目录
[root@iZbp17oxotxuhf5g2zr3brZ src]# cd nginx-1.12.2
# check
[root@iZbp17oxotxuhf5g2zr3brZ nginx-1.12.2]# ./configure
# 编译安装
[root@iZbp17oxotxuhf5g2zr3brZ nginx-1.12.2]# make && make install
至此,Nginx就安装完成了。安装成功之后,在 usr 目录中 多出来一个目录 local/nginx,在 nginx 目录下 有 sbin 目录,有启动脚本。如下:
[root@iZbp17oxotxuhf5g2zr3brZ nginx-1.12.2]# cd /usr/local
[root@iZbp17oxotxuhf5g2zr3brZ local]# ls
aegis bin etc games include lib lib64 libexec nginx sbin share src
[root@iZbp17oxotxuhf5g2zr3brZ local]#
查看nginx版本
在usr/local/nginx/sbin
目录下执行./nginx -v
# 查看版本
[root@iZbp17oxotxuhf5g2zr3brZ sbin]# ./nginx -v
nginx version: nginx/1.12.2
启动nginx
同样在usr/local/nginx/sbin
目录下操作。
[root@iZbp17oxotxuhf5g2zr3brZ sbin]# ./nginx
[root@iZbp17oxotxuhf5g2zr3brZ sbin]#
查看nginx进程
# 进程查看
[root@iZbp17oxotxuhf5g2zr3brZ sbin]# ps -ef | grep nginx
root 7701 1 0 13:52 ? 00:00:00 nginx: master process ./nginx
nobody 7702 7701 0 13:52 ? 00:00:00 nginx: worker process
root 7710 31503 0 13:54 pts/0 00:00:00 grep --color=auto nginx
由于nginx中默认的端口是80端口,但是出于linux系统安全方面考虑,所以系统中默认没有开放80端口,需要在服务器安全组中开放80端口。否则无法访问。
访问nginx
浏览器地址输入IP即可。
停止nginx
[root@iZbp17oxotxuhf5g2zr3brZ sbin]# ./nginx -s stop
重载Nginx
[root@iZbp17oxotxuhf5g2zr3brZ sbin]# ./nginx -s reload
4.配置反向代理
在Nginx的配置文件(在/usr/local/nginx/conf路径的nginx.conf)中配置。
[root@localhost /]# cd /usr/local/nginx/conf
使用vi命令打开nginx.conf
[root@localhost conf]# vi nginx.conf
将server节点下server_name后的
localhost
改成192.168.232.129
另外在location
节点中添加一条用于转发的信息:
proxy_pass http://127.0.0.1:8080;
重载nginx
# 重启nginx
[root@localhost sbin]# ./nginx -s reload
完结!
Q.E.D.