RouterSrv上的服务器任务

发布时间:2025-06-24 18:34:26  作者:北方职教升学中心  阅读量:227


(4) 测试服务器监控脚本(routersrv 首先执行网页检测脚本󿀌 appsrv 执行 tail -f /etc/httpd/logs/access_log);【3 分】。

nginx代理配置#xff0c;并创建缓存目录。

RouterSrv上的服务器任务。

添加测试页󿀌proxy文件结构如下:a;

[root@routesrv ~]# echo "This site is being maintained" > /home/index.html。在返回信息尾部添加指定内容,例如:%{http_code}、

评分点󿄚

通过 web. chinaskills. cn 能访问到 www. chinaskills. cn 页面内容, www. chinaskills. cn 是 wordpress 主页, 还有绿色带锁的标志, 如果不携带 hostname 的截图或者 hostname 截图主机名不是 insidecli 这个问题没有得分。

项目配置:

安装nginx组件:

[root@routesrv ~]# yum install nginx -y。

安装 Nginx 组件;

配置文件名称 proxy.conf,放置在/etc/nginx/conf.d/目录下;

为 www.chinaskills.cn 前端配置代理󿀌通过 HTTPS 的访问后端 Web服务器;

需要记录真实客户端的后端服务器日志内容 IP 地址;

缓存后端 Web 服务器上的静态页面;

创建服务监控脚本:/shells/chkWeb.sh;

编写脚本监控公司网站运行情况;

脚本可以在后台继续运行;

每隔 3S 检查网站的运行状态,若发现异常尝试 3 二次;

如果确定网站无法访问󿀌然后返回用户“返回用户”“然后返回用户”The site is being maintained”。

(1) 检查 nginx 服务状态(routersrv 执行 systemctl status nginx) ; 【1 分】。

缓存配置:

# 添加proxy__cache_path /tmp/cache levels=1:2 keys_zone=cskcache:10m;

继续添加代理配置:

location / { proxy_pass https://www.chinaskills.cn/; proxy_ssl_trusted_certificate /root/csk-ca.pem; proxy_cache_key $request_uri; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }。

添加文档:

[root@routesrv ~]# cat /shell/chkweb.sh#/bin/bashweb_server(){testweb=`curl -k -s -w %{http_code} -o /dev/null https://www.chinaskills.cn`if [[ $testweb -eq 200 ]]then sleep 3s echo "httpd is running"fi}while truedo web_serverif [[ $testweb -ne 200 ]]then for i in {1..3} do web_server echo Try $i time sleep 3s done echo "httpd is down" sed -i "s/proxy_pass/#&/" /etc/nginx/conf.d/proxy.conf sed -i "s/#root/root/g" /etc/nginx/conf.d/proxy.conf systemctl restart nginx breakfidone[root@routesrv ~]#。-s 安静模式-w 操作完成后,

%h ip࿰记录访问者c;如果web前端有代理,所以这个%h实际上是代理服务器的ip%{X-Real-IP}i 字段将记录客户端的真实ip,因此,

重启nginx:

[root@routesrv ~]# systemctl restart nginx。

测试启动:

curl -k -s -w %{http_code} -o /dev/null https://www.chinaskills.cn。

评分标准。

(2) 客户端访问测试#xff08;使用 insidecli 访问 web.chinaskills.cn,并将其携带到终端输入 hostname 截图) ; 【2分】。

创建服务监控脚本:

[root@routersrv ~]# mkdir /shells[root@routersrv ~]# vim /shells/chkweb.sh。 进行网页监控, 如图所示的 11: 42: 28 – 11: 42: 31 – 11: 42: 34。

说明。

运行测试:

[root@routesrv ~]# bash /shell/chkweb.shhttpd is runninghttpd is runninghttpd is runninghttpd is runninghttpd is runninghttpd is running# 将apache关闭后3秒切换成nginx网页。免费分析访问更多细节。%{local_ip},后面可以跟随转义字符n-o 将返回内容输出到文件中。

项目配置:

安装nginx组件:

[root@routesrv ~]# yum install nginx -y。

-k 设置此选项可以使用无证不安全SSL进行连接和传输。

重启Apache:

[root@appsrv csk-rootca]# systemctl restart httpd。 。https://blog.51cto.com/lyx88/category3.html。

测试启动:

curl -k -s -w %{http_code} -o /dev/null https://www.chinaskills.cn。

评分点:

服务状态为 running 即可得分。

后端服务器日记录真实客户端ip地址:

proxy_set_header X-Real-IP $remote_addr;

整体模块:

[root@routesrv shell]# cat /etc/nginx/conf.d/proxy.confproxy_cache_path /tmp/cache levels=1:2 keys_zone=cskcache:10m;server { listen 443 ssl; server_name web.chinaskills.cn; ssl_certificate /root/apache.crt; ssl_certificate_key /root/apache.key; root /home; proxy_cache cskcache; proxy_cache_valid 1s; location / { proxy_pass https://www.chinaskills.cn/; proxy_ssl_trusted_certificate /root/csk-ca.pem; proxy_cache_key $request_uri; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}[root@routesrv shell]# [root@routesrv shell]#。(3) 检查网页日志(appsrv 执行 tail -f /etc/httpd/logs/access_log) ; 【2 分】。

说明。   。评分点:每三秒作为间隔。将log日志修改为logFormatloglog "%h %{X-Real-IP}i%l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined的%{X-FORWARDED-FOR}i 也可以,只在后端为nginx时使用。 第二个地址必须是 192. 168. 0. 190, 第一个地址可以是 192. 168. 100. 254 或 192. 168. 0. 254。评分点:能看到代理服务器 IP 真实的客户端 IP 即可得分, 例如 192. 168. 100. 254 192. 168. 0. 190 的地址。Try 1 timeTry 2 timeTry 3 timehttpd is down[root@routesrv ~]#。

题目要求。

重启nginx:

[root@routesrv ~]# systemctl restart nginx。

[root@routesrv ~]# mkdir /tmp/cache[root@routesrv ~]# vim /etc/nginx/conf.d/proxy.conf。

AppSrv服务器修改后端apache日志设置a;

[root@appsrv ~]# vim /etc/httpd/conf/httpd.conf# 196行LogFormattloglog "%h %{x-real-ip}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined。