Ambari自定义服务开发问题处理-中文乱码
[toc]
# 注意事项
params.py
代码中尽量不要写中文注释,否则安装服务时候可能报错
Traceback (most recent call last):
File "/var/lib/ambari-agent/cache/stacks/HDP/3.1/services/DORIS/package/scripts/be_master.py", line 86, in <module>
Master().execute()
File "/usr/lib/ambari-agent/lib/resource_management/libraries/script/script.py", line 352, in execute
method(env)
File "/var/lib/ambari-agent/cache/stacks/HDP/3.1/services/DORIS/package/scripts/be_master.py", line 37, in install
import params
File "/var/lib/ambari-agent/cache/stacks/HDP/3.1/services/DORIS/package/scripts/params.py", line 40
SyntaxError: Non-ASCII character '\xe6' in file /var/lib/ambari-agent/cache/stacks/HDP/3.1/services/DORIS/package/scripts/params.py on line 40, but no encoding declared; see http://www.python.org/peps/pep-0263.html for detail
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 问题
自定义开发组件,配置中文预警在页面显示乱码
alerts.json配置文件内容如下
{
"DORIS": {
"service": [],
"FRONTEND": [
{
"name": "doris_fe_server_process",
"label": "Doris FE 中文测试",
"description": "Doris FE 中文中文",
"interval": 1,
"scope": "ANY",
"enabled": true,
"source": {
"type": "PORT",
"uri": "{ {fe/http_port}}",
"default_port": 8030,
"reporting": {
"ok": {
"text": "TCP OK - {0:.3f}s response on port {1}"
},
"warning": {
"text": "TCP OK - {0:.3f}s response on port {1}",
"value": 1.5
},
"critical": {
"text": "Connection failed",
"value": 5
}
}
}
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
页面乱码时在ambari
数据库alert_definition
表中也可以看到乱码,因为Ambari-server会读取该表的内容
tip:第一次安装服务时或者服务重启时才会读取一次表,然后放到缓存中进行使用
# 解决方法
下面2个方法可以按照顺序去检查一下
# 方法一
确认数据库、表格式是否为utf8
# MySQL编码
在MySQL中执行show variables like '%char%';
确认编码格式,如果不为utf8需要修改配置。
修改vim /etc/my.cnf
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
1
2
3
4
5
6
2
3
4
5
6
保存配置文件,重启服务:service mysqld restart
# 表编码
数据库:ambari
修改 alert_definition 与 alert_current 表编码格式,修改为utf-8编码。
# 方法二
在/usr/sbin/ambari-server
文件中添加
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
1
2
2
重启服务ambari-server restart
,然后卸载重新安装服务。恢复正常
上次更新: 2024/04/08, 10:55:49