Grafana最新版本4.3.1安裝(后端使用mysql)


環境

CentOS release 6.5 (Final) 64bit
zabbix_server (Zabbix) 3.0.3
grafana-4.3.1
mysql-5.6.21

一、安裝grafana

安裝方法有很多,官網有介紹:http://docs.grafana.org/installation/rpm/。我這里采用二進制安裝方法。

1、下載二進制包,安裝

[root@localhost src]# rpm -Uvh grafana-4.3.1-1.x86_64.rpm
warning: grafana-4.3.1-1.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 24098cb6: NOKEY
Preparing... ########################################### [100%]
1:grafana ########################################### [100%]
### NOT starting grafana-server by default on bootup, please execute
sudo /sbin/chkconfig --add grafana-server
### In order to start grafana-server, execute
sudo service grafana-server start
POSTTRANS: Running script

2、修改grafana.ini文件

參考連接http://docs.grafana.org/installation/configuration/

因為默認使用sqlite3,我這里把他替換成mysql,因為我對mysql熟悉些,而且考慮到以后備份、異常恢復啥的。
修改配置:database和session都替換成mysql數據庫。

############################### Database ####################################
[database]
# You can configure the database connection by specifying type, host, name, user and password
# as seperate properties or as on string using the url propertie.
# Either "mysql", "postgres" or "sqlite3", it's your choice
type = mysql
host = 127.0.0.1:3306
name = grafana
user = grafana
password = grafana
################################# Session #################################
[session]
provider = mysql
provider_config = grafana:grafana@tcp(127.0.0.1:3306)/grafana
cookie_name = grafana_session
cookie_secure = false
session_life_time = 86400

3、建庫

CREATE DATABASE grafana DEFAULT CHARACTER SET utf8;

GRANT ALL ON grafana.* TO grafana@'localhost' IDENTIFIED BY 'grafana' WITH GRANT OPTION;

FLUSH PRIVILEGES;

4、啟動服務grafana-server

啟動服務時,出了個小插曲。啟動服務的時候,失敗了。
[root@localhost ~]# /etc/init.d/grafana-server restart
Stopping Grafana Server: ...[FAILED]
Starting Grafana Server: ... [ OK ]
FAILED


解決過程:查log。
[root@localhost grafana]# tail -f /var/log/grafana/grafana.log
t=2017-06-22T11:26:03+0800 lvl=info msg="Executing migration" logger=migrator id="create index UQE_user_email - v2"
t=2017-06-22T11:26:03+0800 lvl=info msg="Executing migration" logger=migrator id="copy data_source v1 to v2"
t=2017-06-22T11:26:03+0800 lvl=info msg="Executing migration" logger=migrator id="Drop old table user_v1"
t=2017-06-22T11:26:03+0800 lvl=info msg="Executing migration" logger=migrator id="Add column help_flags1 to user table"
t=2017-06-22T11:26:03+0800 lvl=info msg="Executing migration" logger=migrator id="Update user table charset"
t=2017-06-22T11:26:03+0800 lvl=info msg="Executing migration" logger=migrator id="create temp user table v1-7"
t=2017-06-22T11:26:03+0800 lvl=info msg="Executing migration" logger=migrator id="create index IDX_temp_user_email - v1-7"
t=2017-06-22T11:26:03+0800 lvl=eror msg="Executing migration failed" logger=migrator id="create index IDX_temp_user_email - v1-7" error="Error 1071: Specified key was too long; max key length is 767 bytes"
t=2017-06-22T11:26:03+0800 lvl=eror msg="Exec failed" logger=migrator error="Error 1071: Specified key was too long; max key length is 767 bytes" sql="CREATE INDEX `IDX_temp_user_email` ON `temp_user` (`email`);"
t=2017-06-22T11:26:03+0800 lvl=eror msg="Fail to initialize orm engine" logger=sqlstore error="Sqlstore::Migration failed err: Error 1071: Specified key was too long; max key length is 767 bytes\n"
根據提示,是在創建索引的時候,長度超過了767bytes導致。在mysql官網查看也可以看到:By default, the index key prefix length limit is 767 bytes.
參考連接https://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html


解決辦法:
1、修改my.cnf文件,增加如下變量
my.cnf
innodb_large_prefix=ON
innodb_file_format=Barracuda
innodb_file_format_max=Barracuda
進入數據庫,查看這幾個變量的原始值:
mysql> show variables like 'innodb_file%';
+--------------------------+----------+
| Variable_name | Value |
+--------------------------+----------+
| innodb_file_format | Antelope |
| innodb_file_format_check | ON |
| innodb_file_format_max | Antelope |
| innodb_file_per_table | ON |
+--------------------------+----------+
4 rows in set (0.01 sec)

mysql> show variables like 'innodb_large%';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| innodb_large_prefix | OFF |
+---------------------+-------+
1 row in set (0.00 sec)
修改my.cnf文件后,重啟數據庫。
2、修改grafana表的行格式。
temp_user ALTER TABLE temp_user ROW_FORMAT=DYNAMIC;
dashboard ALTER TABLE dashboard ROW_FORMAT=DYNAMIC;
alert ALTER TABLE alert ROW_FORMAT=DYNAMIC;
修改前:
mysql> SHOW TABLE STATUS like 'dashboard'\G
*************************** 1. row ***************************
Name: dashboard
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 21
Avg_row_length: 60074
Data_length: 1261568
Max_data_length: 0
Index_length: 65536
Data_free: 4194304
Auto_increment: 44
Create_time: 2016-07-13 11:07:01
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)

mysql> ALTER TABLE dashboard ROW_FORMAT=DYNAMIC;
Query OK, 0 rows affected (0.17 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> ALTER TABLE dashboard ROW_FORMAT=DYNAMIC;
Query OK, 0 rows affected (0.17 sec)
Records: 0 Duplicates: 0 Warnings: 0
修改后:
mysql> SHOW TABLE STATUS like 'dashboard'\G
*************************** 1. row ***************************
Name: dashboard
Engine: InnoDB
Version: 10
Row_format: Dynamic
Rows: 22
Avg_row_length: 72238
Data_length: 1589248
Max_data_length: 0
Index_length: 65536
Data_free: 0
Auto_increment: 44
Create_time: 2017-05-24 12:01:03
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options: row_format=DYNAMIC
Comment:
3、重啟grafana服務,一切OK。

t=2017-06-22T11:39:21+0800 lvl=info msg="Starting Grafana" logger=main version=4.3.1 commit=befc15c compiled=2017-05-23T21:50:22+0800
t=2017-06-22T11:39:21+0800 lvl=info msg="Config loaded from" logger=settings file=/usr/share/grafana/conf/defaults.ini
t=2017-06-22T11:39:21+0800 lvl=info msg="Config loaded from" logger=settings file=/etc/grafana/grafana.ini
t=2017-06-22T11:39:21+0800 lvl=info msg="Config overriden from command line" logger=settings arg="default.paths.data=/var/lib/grafana"
t=2017-06-22T11:39:21+0800 lvl=info msg="Config overriden from command line" logger=settings arg="default.paths.logs=/var/log/grafana"
t=2017-06-22T11:39:21+0800 lvl=info msg="Config overriden from command line" logger=settings arg="default.paths.plugins=/var/lib/grafana/plugins"
t=2017-06-22T11:39:21+0800 lvl=info msg="Path Home" logger=settings path=/usr/share/grafana
t=2017-06-22T11:39:21+0800 lvl=info msg="Path Data" logger=settings path=/var/lib/grafana
t=2017-06-22T11:39:21+0800 lvl=info msg="Path Logs" logger=settings path=/var/log/grafana
t=2017-06-22T11:39:21+0800 lvl=info msg="Path Plugins" logger=settings path=/var/lib/grafana/plugins
t=2017-06-22T11:39:21+0800 lvl=info msg="Initializing DB" logger=sqlstore dbtype=mysql
t=2017-06-22T11:39:21+0800 lvl=info msg="Starting DB migration" logger=migrator
t=2017-06-22T11:39:21+0800 lvl=info msg="Executing migration" logger=migrator id="copy data account to org"
t=2017-06-22T11:39:21+0800 lvl=info msg="Skipping migration condition not fulfilled" logger=migrator id="copy data account to org"
t=2017-06-22T11:39:21+0800 lvl=info msg="Executing migration" logger=migrator id="copy data account_user to org_user"
t=2017-06-22T11:39:21+0800 lvl=info msg="Skipping migration condition not fulfilled" logger=migrator id="copy data account_user to org_user"
t=2017-06-22T11:39:21+0800 lvl=info msg="Executing migration" logger=migrator id="add index alert state"
t=2017-06-22T11:39:21+0800 lvl=info msg="Executing migration" logger=migrator id="add index alert dashboard_id"
t=2017-06-22T11:39:21+0800 lvl=info msg="Executing migration" logger=migrator id="create alert_notification table v1"
t=2017-06-22T11:39:21+0800 lvl=info msg="Executing migration" logger=migrator id="Add column is_default"
t=2017-06-22T11:39:22+0800 lvl=info msg="Executing migration" logger=migrator id="add index alert_notification org_id & name"
t=2017-06-22T11:39:22+0800 lvl=info msg="Executing migration" logger=migrator id="Update alert table charset"
t=2017-06-22T11:39:22+0800 lvl=info msg="Executing migration" logger=migrator id="Update alert_notification table charset"
t=2017-06-22T11:39:22+0800 lvl=info msg="Executing migration" logger=migrator id="Drop old annotation table v4"
t=2017-06-22T11:39:22+0800 lvl=info msg="Executing migration" logger=migrator id="create annotation table v5"
t=2017-06-22T11:39:23+0800 lvl=info msg="Executing migration" logger=migrator id="add index annotation 0 v3"
t=2017-06-22T11:39:23+0800 lvl=info msg="Executing migration" logger=migrator id="add index annotation 1 v3"
t=2017-06-22T11:39:23+0800 lvl=info msg="Executing migration" logger=migrator id="add index annotation 2 v3"
t=2017-06-22T11:39:23+0800 lvl=info msg="Executing migration" logger=migrator id="add index annotation 3 v3"
t=2017-06-22T11:39:23+0800 lvl=info msg="Executing migration" logger=migrator id="add index annotation 4 v3"
t=2017-06-22T11:39:23+0800 lvl=info msg="Executing migration" logger=migrator id="Update annotation table charset"
t=2017-06-22T11:39:24+0800 lvl=info msg="Executing migration" logger=migrator id="Add column region_id to annotation table"
t=2017-06-22T11:39:24+0800 lvl=info msg="Executing migration" logger=migrator id="create test_data table"
t=2017-06-22T11:39:25+0800 lvl=info msg="Created default admin user: admin"
t=2017-06-22T11:39:25+0800 lvl=info msg="Starting plugin search" logger=plugins
t=2017-06-22T11:39:25+0800 lvl=warn msg="Plugin dir does not exist" logger=plugins dir=/var/lib/grafana/plugins
t=2017-06-22T11:39:25+0800 lvl=info msg="Plugin dir created" logger=plugins dir=/var/lib/grafana/plugins
t=2017-06-22T11:39:25+0800 lvl=info msg="Initializing Alerting" logger=alerting.engine
t=2017-06-22T11:39:25+0800 lvl=info msg="Initializing CleanUpService" logger=cleanup
t=2017-06-22T11:39:25+0800 lvl=info msg="Initializing Stream Manager"
t=2017-06-22T11:39:25+0800 lvl=info msg="Initializing HTTP Server" logger=http.server address=0.0.0.0:3000 protocol=http subUrl= socket=

5、打開主頁

PS:本文純屬記錄個人實踐經歷,如有問題,可隨時聯系我。QQ505711559


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM