因客戶Red Hat 7.5服務器安裝部署grafana沒法添加prometheus數據源,以及沒法修改初始密碼,爲確保環境訪問安全,特別研究經過帳號密碼認證訪問prometheus,搜索了不少資料,但都缺這缺那,因此我這裏記錄下具體實現過程:html
方法一:使用yum安裝nginx
yum -y install apr apr-util httpd
方法二:使用源碼安裝c++
yum -y install expat-devel gcc gcc-c++ autoreconf libtoolize automake
一、下載httpd安裝包apache
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.46.tar.gz
二、解壓vim
tar zxvf httpd-2.4.46.tar.gz
三、下載新的apr、apr-util安裝(安裝過程會有各類奇葩錯誤,自行搜索資料解決,這裏不具體講解)安全
wget http://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
四、安裝apr、apr-util服務器
tar -zxvf apr-1.7.0.tar.gz tar -zxvf apr-util-1.6.1.tar.gz cd /opt/apr-1.7.0 ./configure --prefix=/usr/local/apr && make && make install cd /opt/apr-util-1.6.1 ./configure --prefix=/usr/local/apr-util && make && make install
五、進入目錄cd httpd-2.4.46/ide
cd /opt/httpd-2.4.46/ ./configure --prefix=/usr/local/apache2/ --enable-rewrite --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util make && make install
備註:路徑與用戶名及密碼根據實際環境操做變動(在交互界面輸入兩次相同的密碼)rest
/usr/bin/htpasswd -c /etc/nginx/.htpasswd promethues
vim /etc/nginx/conf/nginx.conf location / { auth_basic "Prometheus"; auth_basic_user_file /etc/nginx/.htpasswd; proxy_pass http://localhost:9090; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; root html; index index.html index.htm; } /etc/nginx/sbin/nginx -t /etc/nginx/sbin/nginx -s reload
一、修改prometheus.yml文件code
vim /usr/local/prometheus/prometheus.yml - job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090'] basic_auth: username: promethues password: 密碼
二、重啓prometheus服務
systemctl restart prometheus systemctl status prometheus
三、訪問prometheus服務界面
四、輸入配置的用戶名與認證密碼
五、查看targets信息