在web服务器上安装niginx

一、在之前的web服务器上安装nginx

1.直接用yum安装

[root@web-1 yum.repos.d]# yum install nginx  -y        安装nginx

[root@web-1 yum.repos.d]# systemctl  start nginx        启动nginx

[root@web-1 yum.repos.d]# ps aux|grep nginx        查看nginx进程是否启动

[root@web-1 yum.repos.d]# netstat -anplut|grep nginx        查看端口

直接输入ip地址访问网站

二、在新的web服务器安装nginx

1.新安装一台web服务器,名为web-2

安装步骤和之前一样,挂在centos7.9系统,然后最小化安装,网络打开,很简单

2.在ansible里添加进入主机清单

位置在/etc/ansible/

[root@ansible-prome ansible]# vim hosts         进入配置文件

[web2]

192.168.205.135  ansible_ssh_user='root' ansible_ssh_pass='123456'

[root@ansible-prome ansible]# ssh  root@192.168.205.135        使用ssh连接

3.初始化新的web服务器

传输初始化脚本,并执行初始化

[root@web-1 ~]# scp init_env.sh 192.168.205.135:/root            远程拷贝脚本

[root@localhost ~]# bash init_env.sh ansible   web-2 192.168.205.135  192.168.205.2         传递参数并执行初始化脚本

然后可以ip add和ip route看一下脚本是否执行有效

4.使用ansible去安装node_exporter

将web-1服务器上的安装脚本和源码包文件,scp到ansible机器上

[root@web-1 ~]# scp install_node_exporter.sh root@192.168.205.134:/etc/ansible

将web-1服务器上的node_exporters软件scp到ansible机器上

[root@web-1~]# scp node_exporter-1.4.0-rc.0.linux-amd64.tar.gz root@192.168.205.134:/etc/ansible

[root@ansible-prome ansible]# ansible web2 -m copy -a "src=node_exporter-1.4.0-rc.0.linux-amd64.tar.gz  dest=/root"        利用ansible的copy模块将node_exporter传到web2服务器上

[root@ansible-prome ansible]# ansible web2 -m script -a "install_node_exporter.sh"        利用ansible的script模块远程执行node_exporter的安装脚本

5.验证exporter是否安装成功

[root@web-2 network-scripts]# ps aux|grep node        看进程信息

[root@web-2 network-scripts]# netstat -anlput|grep node         看端口信息

6.在prometheus上添加web-2机器信息

[root@ansible-prome playbook]# cd /prome/prometheus        找到配置文件

[root@ansible-prome prometheus]# vim prometheus.yml         修改配置文件

在配置文件中添加服务器名字,ip地址和端口号

[root@ansible-prome prometheus]# systemctl  restart prometheus        重启Prometheus 服务

然后打开网页看到有web-2的信息就表示成功

  • 24
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值