修改grafana的admin账号密码

网友投稿 2264 2022-09-02

修改grafana的admin账号密码

修改grafana的admin账号密码

方法一:进入pod内部进行访问

1.进入相关的pod

Plaintext
 kubectl exec -it pod/grafana-978f4bb88-xfbv8 -c grafana -nmonitoring /bin/sh

2.修改用户admin密码:grafana-cli admin reset-admin-password

Plaintext
/usr/share/grafana $ grafana-cli admin reset-admin-password Aa123456@123
INFO [08-04|04:58:38] Starting Grafana                         logger=settings version= commit= branch= compiled=1970-01-01T00:00:00+0000
INFO [08-04|04:58:38] The state of unified alerting is still not defined. The decision will be made during as we run the database migrations logger=settings
INFO [08-04|04:58:38] Config loaded from                       logger=settings file=/usr/share/grafana/conf/defaults.ini
INFO [08-04|04:58:38] Config overridden from Environment variable logger=settings var="GF_PATHS_DATA=/var/lib/grafana"
INFO [08-04|04:58:38] Config overridden from Environment variable logger=settings var="GF_PATHS_LOGS=/var/log/grafana"
INFO [08-04|04:58:38] Config overridden from Environment variable logger=settings var="GF_PATHS_PLUGINS=/var/lib/grafana/plugins"
INFO [08-04|04:58:38] Config overridden from Environment variable logger=settings var="GF_PATHS_PROVISIONING=/etc/grafana/provisioning"
INFO [08-04|04:58:38] Path Home                                logger=settings path=/usr/share/grafana
INFO [08-04|04:58:38] Path Data                                logger=settings path=/var/lib/grafana
INFO [08-04|04:58:38] Path Logs                                logger=settings path=/var/log/grafana
INFO [08-04|04:58:38] Path Plugins                             logger=settings path=/var/lib/grafana/plugins
INFO [08-04|04:58:38] Path Provisioning                        logger=settings path=/etc/grafana/provisioning
INFO [08-04|04:58:38] App mode production                      logger=settings
INFO [08-04|04:58:38] Connecting to DB                         logger=sqlstore dbtype=sqlite3
INFO [08-04|04:58:38] Starting DB migrations                   logger=migrator
INFO [08-04|04:58:38] migrations completed                     logger=migrator performed=0 skipped=392 duration=914.099µs

Admin password changed successfully ✔

方法二:直接修改

kubectl exec -it pod/grafana-978f4bb88-xfbv8 -nmonitoring -c grafana grafana-cli admin reset-admin-password Welc@me123

Plaintext
[root@k8s-master tidb]# kubectl exec -it pod/grafana-978f4bb88-xfbv8 -nmonitoring -c grafana grafana-cli admin reset-admin-password Aa123456@123
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
INFO [08-04|05:04:45] Starting Grafana                         logger=settings version= commit= branch= compiled=1970-01-01T00:00:00+0000
INFO [08-04|05:04:45] The state of unified alerting is still not defined. The decision will be made during as we run the database migrations logger=settings
INFO [08-04|05:04:45] Config loaded from                       logger=settings file=/usr/share/grafana/conf/defaults.ini
INFO [08-04|05:04:45] Config overridden from Environment variable logger=settings var="GF_PATHS_DATA=/var/lib/grafana"
INFO [08-04|05:04:45] Config overridden from Environment variable logger=settings var="GF_PATHS_LOGS=/var/log/grafana"
INFO [08-04|05:04:45] Config overridden from Environment variable logger=settings var="GF_PATHS_PLUGINS=/var/lib/grafana/plugins"
INFO [08-04|05:04:45] Config overridden from Environment variable logger=settings var="GF_PATHS_PROVISIONING=/etc/grafana/provisioning"
INFO [08-04|05:04:45] Path Home                                logger=settings path=/usr/share/grafana
INFO [08-04|05:04:45] Path Data                                logger=settings path=/var/lib/grafana
INFO [08-04|05:04:45] Path Logs                                logger=settings path=/var/log/grafana
INFO [08-04|05:04:45] Path Plugins                             logger=settings path=/var/lib/grafana/plugins
INFO [08-04|05:04:45] Path Provisioning                        logger=settings path=/etc/grafana/provisioning
INFO [08-04|05:04:45] App mode production                      logger=settings
INFO [08-04|05:04:45] Connecting to DB                         logger=sqlstore dbtype=sqlite3
INFO [08-04|05:04:46] Starting DB migrations                   logger=migrator
INFO [08-04|05:04:46] migrations completed                     logger=migrator performed=0 skipped=392 duration=827.05µs

Admin password changed successfully ✔

方法三:通过class="data-table" data-id="t7a7e9d1-Hh9gkNHE" data-width="" style="outline: none; border-collapse: collapse; width: 100%;">

Plaintext
curl -X PUT -H "Content-Type: application/json" -d '{"oldPassword": "admin","newPassword": "Aa123456@123","confirmNew": "Aa123456@123"}' class="data-table" data-id="t7a7e9d1-d5Tga79A" data-width="" style="outline: none; border-collapse: collapse; width: 100%;">

Plaintext
1.1、通过master节点查找grafana所在的节点
[root@k8s-master tidb]# kubectl get pod -nmonitoring -owide
grafana-978f4bb88-xfbv8                2/2     Running   0          2d      10.244.2.82    k8s-node2   <none>           <none>

1.2、在node2节点上查找文件
[root@k8s-node2 tidb]# find / -name "grafana.db"
/home/docker/images/overlay2/91c653a478a35838845a2c314e5837222390e10abebb0d9dda6d3a3776a18cfc/diff/var/lib/grafana/grafana.db
/home/docker/images/overlay2/ad79d41289140a452d6a1cf6134c87cf02e223fc2586b6fb4ed178e95197de5e/diff/var/lib/grafana/grafana.db
/home/docker/images/overlay2/3533bf5033accdd47191823259eaf2ab0435bc35e334a3051aab5e0f91ea7518/diff/var/lib/grafana/grafana.db
/home/k8s/kubelet/pods/2cb51d4d-ac72-47fe-a5fb-729e905c3939/volumes/kubernetes.io~empty-dir/grafana-storage/grafana.db
[root@k8s-node2 tidb]# ll /home/k8s/kubelet/pods/2cb51d4d-ac72-47fe-a5fb-729e905c3939/volumes/kubernetes.io~empty-dir/grafana-storage/grafana.db
-rw-r----- 1 nfsnobody nfsnobody 1900544 Aug  4 16:53 /home/k8s/kubelet/pods/2cb51d4d-ac72-47fe-a5fb-729e905c3939/volumes/kubernetes.io~empty-dir/grafana-storage/grafana.db
[root@k8s-node2 tidb]# sqlite3 /home/k8s/kubelet/pods/2cb51d4d-ac72-47fe-a5fb-729e905c3939/volumes/kubernetes.io~empty-dir/grafana-storage/grafana.db

1.3、查找所在的docker进程
[root@k8s-node2 tidb]# docker ps |grep grafana
645833ef5efb   grafana/grafana                                                      "/run.sh"                2 days ago    Up 2 days              k8s_grafana_grafana-978f4bb88-xfbv8_monitoring_2cb51d4d-ac72-47fe-a5fb-729e905c3939_0
a846c6165742   grafana/grafana-image-renderer                                       "dumb-init -- node b…"   2 days ago    Up 2 days              k8s_grafana-image-render_grafana-978f4bb88-xfbv8_monitoring_2cb51d4d-ac72-47fe-a5fb-729e905c3939_0
f79e5eb37904   k8s.gcr.io/pause:3.4.1                                               "/pause"                 2 days ago    Up 2 days              k8s_POD_grafana-978f4bb88-xfbv8_monitoring_2cb51d4d-ac72-47fe-a5fb-729e905c3939_0

1.4、通过比较发现grafana所在的id是:2cb51d4d-ac72-47fe-a5fb-729e905c3939。所以可以确定grafna.db文件在
/home/k8s/kubelet/pods/2cb51d4d-ac72-47fe-a5fb-729e905c3939/volumes/kubernetes.io~empty-dir/grafana-storage/grafana.db

2.使用sqlite3加载数据库文件

Plaintext
[root@k8s-node2 tidb]# sqlite3 /home/k8s/kubelet/pods/2cb51d4d-ac72-47fe-a5fb-729e905c3939/volumes/kubernetes.io~empty-dir/grafana-storage/grafana.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
sqlite> select * from user;
1|0|admin|admin@localhost||7964ca22222f077bb226f19c415564ea5a5c2af4306942d90bea214046dd90518096c9c9dc4ce086fe249fa09fb1cd0b6640a|OOo71b544U|FauHeT5hUo||1|1|0||2022-08-02 09:03:26|2022-08-04 05:12:09|0|2022-08-04 05:27:00|0|0
2|0|chaosmesh|chaosmesh@123.com|chaosmesh|b22226d5734061e60c4cca730b68f9bbe9be037565e998c7fa1f475ba1fbe7451e8c718425ce7a55174ecaccab3de66a37401b4|dKngYxNZ7h|HF5kYgeQC8||1|0|0||2022-08-04 03:57:47|2022-08-04 03:59:15|0|2022-08-04 04:47:25|0|0

3.对密码进行还原(设置密码为admin/admin)

Plaintext
#.tables查看有那些表
.tables
#select查看表里面的内容
select * from user;
#使用update更新密码
update user set password = '59acf18b94d7eb0694c61e60ce44c110c7a683ac6a8f09580d626f90f4a242000746579358d77dd9e570e83fa24faa88a8a6', salt = 'F3FAxVm33R' where login = 'admin';
#修改完成后退出
.exit

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Docker真的很好用,PHP开发者都应该学起来(docker 好用吗)
下一篇:PHP浮点数运算精度问题(php高精度计算)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~