从Github上能够看到netdata的主要功能,主要有几点:
NetData工作界面
Centos7
# 下载项目代码
➜ git clone https://github.com/firehol/netdata.git
# 安装变异所需要的包
➜ yum -y install zlib-devel libuuid-devel libmnl-devel gcc make git autoconf autogen automake pkgconfig
# 运行自带的安装启动脚本
➜ cd ./netdata
➜ ./netdata-installer.sh
安装启动脚本时,提示netData安装的详细目录,按下Enter键执行。
安装启动脚本
安装完成后,脚本输出一段信息,包括:KSM、端口、启动命令
开启 KSM 以节省储存占用
如果有下列信息,说明你的系统有 KSM,但是未启用,可以按照说明执行两句echo命令,节省 40-60% 的储存空间。
--- Check KSM (kernel memory deduper) ---
Memory de-duplication instructions
You have kernel memory de-duper (called Kernel Same-page Merging,
or KSM) available, but it is not currently enabled.
To enable it run:
echo 1 >/sys/kernel/mm/ksm/run
echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
If you enable it, you will save 40-60% of netdata memory.
web端口配置
默认的web访问端口为19999。
netdata by default listens on all IPs on port 19999,
so you can access it with:
http://this.machine.ip:19999/
修改web端口
启动/关闭netData
# 停止
➜ systemctl stop netdata
# 启动
➜ systemctl start netdata
# 重启
➜ systemctl restart netdata
# 开机启动
➜ systemctl enable netdata
# 卸载
➜ ./netdata-uninstaller.sh --force
至此,NetData安装启动完毕,可以通过http://host_ip:port 进行访问,无需账号密码。
下面将结合Nginx设置账号密码。
由于netdata没有帐号密码体系,为保护服务器隐私,我们要使用nginx反向代理配置域名访问,并使用账号密码授权。
事先准备:
生成Nginx密码文件
# 密码文件存放位置自定义,路径需记录下来,放在Nginx配置中。
➜ printf "netdata:$(openssl passwd -apr1)" > /usr/local/nginx/conf/htpasswd
配置nginx.conf
在 ...nginx/conf.d 中创建netdata.conf文件,写入如下内容,适当修改端口号、域名、auth_basic_user_file。
upstream backend {
# the netdata server,请修改具体端口号
server 127.0.0.1:19999;
keepalive 64;
}
server {
# nginx listens to this
listen 80;
# the virtual host name of this,请求改具体域名
server_name netdata.example.com;
# auth password
auth_basic "netdata Login";
# 上一步生成的密码文件路径
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_pass_request_headers on;
proxy_set_header Connection "keep-alive";
proxy_store off;
}
}
重启nginx
# 密码文件存放位置自定义,路径需记录下来,放在Nginx配置中。
➜ systemctl reload nginx
重启Nginx后,可以直接通过域名netdata.example.com访问,并且需要输入账号和密码。但是依然可以通过http://IP:Port的方式访问,接下来禁用IP访问。
NetData禁用外部IP请求
[web]
bind to = 127.0.0.1 ::1
留言与评论(共有 0 条评论) |