1. Reason
Because the customer Red Hat 7.5 server installation and deployment grafana can not add prometheus data source, and can not modify the initial password, in order to ensure the security of environmental access, special research to access prometheus through account and password authentication, Baidu has a lot of information, but it is lacking, so I The specific implementation process is recorded here:
Two, install and deploy httpd
Method 1: Use yum to install
yum -y install apr apr-util httpd
Method 2: Install from source code
yum -y install expat-devel gcc gcc-c++ autoreconf libtoolize automake
1. Download the httpd installation package
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.46.tar.gz
2. Unzip
tar zxvf httpd-2.4.46.tar.gz
3. Download the new apr and apr-util installation (there will be various strange errors during the installation process, which will be solved by Baidu, not explained here in detail)
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
4. Install 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
5. Enter the directory cd httpd-2.4.46/
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
Three, create prometheus access authentication account password
Note: The path, user name and password are changed according to the actual environment operation (enter the same password twice in the interactive interface)
/usr/bin/htpasswd -c /etc/nginx/.htpasswd promethues
Four, configure nginx access configuration
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
Five, modify the prometheus.yml file, configure basic auth authentication
1. Modify the prometheus.yml file
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: 密码
2. Restart the prometheus service
systemctl restart prometheus
systemctl status prometheus
3. Access the prometheus service interface
4. Enter the configured user name and authentication password
5. View the targets information