此次部署的grafana使用postgres数据库来存放数据
安装postgresql
服务器
ip | 系统 | 配置 | 目录 | 部署版本 |
---|---|---|---|---|
172.24.32.200 | centos7.7 | 2c4g | /var/lib/pgsql/12/ | 12 |
- 1、官网
https://www.postgresql.org/download/linux/redhat/
- 2、下载rpm源
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- 3、安装客户端
yum install -y postgresql12
- 4、安装服务端
yum install postgresql12-server
- 5、初始化并且开机自启动
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12
- 6、创建账号密码
sudo su postgres
psql postgres
ALTER USER postgres WITH PASSWORD 'test123'
执行结果
[root@test01 ~]# sudo su postgres
bash-4.2$ psql postgres
could not change directory to "/root": Permission denied
psql (12.3)
Type "help" for help.
postgres=# ALTER USER postgres WITH PASSWORD 'test123';
ALTER ROLE
- 7、修改配置文件和登陆权限
echo >>/var/lib/pgsql/12/data/pg_hba.conf<<EOF
host all all 172.24.32.200/32 trust
EOF
sed -i "s| listen_addresses = 'localhost' |listen_addresses = '*'|g" /var/lib/pgsql/12/data/postgresql.conf
- 8、重启下数据库
systemctl start postgresql-12
安装grafana
服务器
ip | 系统 | 配置 | 目录 | 部署版本 |
---|---|---|---|---|
172.24.32.200 | centos7.7 | 2c4g | /etc/grafana/grafana.ini | 6.7.3 |
安装
官网
https://grafana.com/docs/grafana/latest/installation/debian/
cd /usr/local/src
wget https://dl.grafana.com/oss/release/grafana-6.7.3-1.x86_64.rpm
yum install -y grafana-6.7.3-1.x86_64.rpm
修改配置文件
主要修改端口、数据库(sqlite改成postgresql)、告警邮箱
echo >>/etc/grafana/grafana.ini<<EOF
[paths]
[server]
http_port = 3001
[database]
type = postgres
host = 172.24.32.200:5432
name = grafana
user = postgres
password = test123
[remote_cache]
[dataproxy]
[analytics]
[security]
[snapshots]
[dashboards]
[users]
[auth]
[auth.anonymous]
[auth.github]
[auth.gitlab]
[auth.google]
[auth.grafana_com]
[auth.azuread]
[auth.generic_oauth]
[auth.saml] # Enterprise only
[auth.basic]
[auth.proxy]
[auth.ldap]
[smtp]
enabled = true
host = smtp.exmail.qq.com:465
user = lugo@test.com
password = test33
skip_verify = true
from_address = lugo@test.com
from_name = Grafana
[emails]
[log]
[log.console]
[log.file]
[log.syslog]
[quota]
[alerting]
[explore]
[metrics]
[metrics.graphite]
[grafana_com]
[tracing.jaeger]
[external_image_storage]
[external_image_storage.s3]
[external_image_storage.webdav]
[external_image_storage.gcs]
[external_image_storage.azure_blob]
[external_image_storage.local]
[rendering]
[panels]
[plugins]
[enterprise]
[feature_toggles]
EOF
启动和开机自启动
systemctl enable grafana-server
systemctl start grafana-server
登陆,初始密码admin、admin
http://172.24.32.200:3001/login
改密码 test123
添加饼图插件
grafana-cli plugins install grafana-piechart-panel
重启服务生效
service grafana-server restart