备忘录:做个笔记,即可。
记录:NO.217
本例环境:
操作系统:CentOS-7-x86_64-DVD-1908
nginx版本:nginx-1.18.0.tar
远程连接工具:SecureCRT 8.0
虚拟机:vmware 12
下载地址:http://nginx.org/en/download.html
官网介绍:
nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server.
名词:
gcc: The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Ada, Go, and D, as well as libraries for these languages (libstdc++,...).
pcre: The Perl Compatible Regular Expressions (PCRE) library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5. PCRE has its own native API, in addition to a set of POSIX compatible wrapper functions. PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。
zlib:A Massively Spiffy Yet Delicately Unobtrusive Compression Library.
openssl:Open Secure Sockets Layer.OpenSSL是一个开放源代码的软件库包,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连接者的身份。这个包广泛被应用在互联网的网页服务器上。Cryptography and SSL/TLS Toolkit.
nginx安装部署
1.安装nginx的依赖
主要包括:gcc,pcre,pcre-devel,zlib,zlib-devel,openssl,openssl-devel
命令:
yum gcc
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl-devel
2.查看依赖是否安装
命令:
gcc -v
openssl version -a
rpm -qa pcre
rpm -qa zlib
3.解压
在/home/app解压nginx-1.18.0.tar.gz
命令:tar -zxvf nginx-1.18.0.tar.gz
把nginx-1.18.0重名为nginx
命令:mv nginx-1.18.0 nginx
4.安装
在/home/app/nginx目录下执行命令
./configure
make && make install
5.安装后nginx的目录(本例是默认安装)
安装后所在目录:/usr/local/
6.启动
在/usr/local/nginx/sbin启动
命令:
./nginx
7.查看启动进程和端口
进程:
ps -aux | grep nginx
端口
netstat -tlnp | grep nginx
8.关闭防火墙
命令:
service firewalld stop
9.测试
访问地址:http://192.168.110.130:80
访问页面:
10.关闭nginx
找到进程并kill
ps -aux | grep nginx
kill -9 进程号
负载均衡搭建
1.修改配置文件
进入/usr/local/nginx/conf修改nginx.conf配置文件在相应模块修改
http {
upstream zbzserver{
server 192.168.110.130:18080 weight=1;
server 192.168.110.130:18081 weight=2;
}
server {
listen 17000;
server_name 192.168.110.130;
location / {
proxy_pass http://zbzserver;
}
}
}
2.启动nginx
./nginx
3.启动tomcat
本例使用apache-tomcat-8.5.53,需要jdk 1.8环境
配置两个tomcat分别是:在/home/apps/apache-tomcat-18080和/home/apps/apache-tomcat-18081
apache-tomcat-18080
apache-tomcat-18081
4.为了分区负载起作用
分别修改/home/apps/apache-tomcat-18080/webapps/ROOT和/home/apps/apache-tomcat-18081/webapps/ROOT的index.jsp文件。
把/home/apps/apache-tomcat-18080/webapps/ROOT/index.jsp的导航标签nav-home的Home改成Home-18080
把/home/apps/apache-tomcat-18081/webapps/ROOT/index.jsp的导航标签nav-home的Home改成Home-18081
比如:
分别在/home/apps/apache-tomcat-18080/bin和/home/apps/apache-tomcat-18081/bin启动tomcat
命令:
./startup.sh
5.分别调用apache-tomcat-18080和apache-tomcat-18081
apache-tomcat-18080地址 http://192.168.110.130:18080 如下:
apache-tomcat-18081地址 http://192.168.110.130:18081如下
6.使用nginx地址调用
地址:http://192.168.110.130:17000
调用到18080端口
调用到18081端口
以上,感谢。