目录
1、为什么需要nginx代理这个请求呢?
直接将微服务对skywalking的请求发到skywalking的接收地址不就可以了吗?
是的,正常是这样的。但是,在项目实施的过程中,往往都是各种千奇百怪的场景。如果,不是因为应对这些客户提出的场景,谁也不会舍近求远,还要多加一层。以下就是在此次实施过程中的场景,看到这个场景大家应该不难理解为什么使用nginx做代理转发了。
所以,此时就需要在B服务器上面安装一个ngin,来转发A服务器的请求到C服务器的skywalking上。
2、具体实施流程
1、找到nginx.conf配置文件(一般在/usr/local/nginx/conf下),在配置文件里面添加如下配置:
#代理转发对skywalking的转发,grpc
server {
listen 11800 http2; #监听端口
server_name localhost;
access_log /usr/local/nginx/logs/host.access.skywalking.log ;
location / {
grpc_pass grpc://101.32.7.128:11800; #真正skywalking安装的服务器接收请求地址
}
}
注:skywalking是使用的grpc协议,而不是http协议
如果未安装nginx,可以使用如下步骤进行安装:
1)创建nginx的安装目录
mkdir /opt/software/nginx
2) 切换到nginx的安装目录,下载1.13.10以上版本的nginx
cd /opt/software/nginx
wget http://nginx.org/download/nginx-1.19.3.tar.gz
3)解压下载好的nginx
tar -zxvf nginx-1.19.3.tar.gz
4)切换到安装目录
cd nginx-1.19.3
5)配置nginx
./configure
6)编译安装nginx
make && make install
此步骤,执行成功后,在/usr/local下就会出现nginx目录,也就预示着安装成功。
注意:在安装nginx的第五步的时候可能会报如下错误:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
这个报错就是缺少库文件或者其它文件,我们把缺失的库文件安装上进行了。依次执行如下命令后再执行5)步骤的命令 :
yum -y install pcre pcre-devel
yum -y install openssl openssl-devel
2、修改完成后,使用nginx -t检查配置文件是否有问题,没有问题则进行下一步,若有问题则根据提示进行修正。
nginx -t
这里可能会提示识别不了grpc_pass,或者报如下错误 :
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/nginx/conf/nginx.conf:1
nginx: [emerg] the "http2" parameter requires ngx_http_v2_module in /usr/local/nginx/conf/nginx.conf:49
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
这是需要引入模块:--with-http_ssl_module --with-http_v2_module
切换到nginx的安装目录执行如下命令:
./configure --with-http_ssl_module --with-http_v2_module//如果此命令不能执行成功,则执行./configure --with-http_v2_module
make && make install
3、重启nginx,使配置文件生效
停止nginx: nginx -s stop
指定配置启动nginx: nginx -c /usr/local/nginx/conf/nginx.conf
4、修改启动脚本 ,重启启动需要监测的服务
-Dskywalking.collector.backend_service=10.121.17.8:11800 #这个地址更改为nginx所在服务器的地址,端口和nginx.conf里面配置的监听端口保持一致。
当在skywalking管理界面能够出现你需要监测的服务实例的时候,就说明nginx代理转发对skywalking的请求成功了。