CentOS/RedHat 6.5环境报出中文字符集问题
现象:
=====================================================================
[root@gpu-centos-no server]# local -a
bash: local: can only be used in a function
[root@gpu-centos-no server]# locale -a
C
POSIX
[root@gpu-centos-no server]# export LANG="zh_CN.UTF-8"
[root@gpu-centos-no server]# locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
POSIX
[root@gpu-centos-no server]# localedef -h
bash: localedef: command not found
=======================================================================
分析: 该情况为系统内缺少语言包,属于较难解决的问题
解决方法:
==========================================================================
第一步: 重装glibc-common
yum remove glibc-common -y
yum install glibc-common -y
===重编译UTF-8(容器内使用可能会报错,可不予理会)
localedef -v -c -i zh_CN -f UTF-8 zh_CN.UTF-8
=============================================================
[root@gpu-centos-no log]# localedef -v -c -i zh_CN -f UTF-8 zh_CN.UTF-8
cannot open locale definition file `zh_CN': No such file or directory
============================================================
第二步:安装中文支持
yum groupinstall chinese-support
yum groupinstall "fonts"(一般无需安装)
=============================================================
mkdir -p /iflytek/chinese-support
yum groupinstall --downloadonly --downloaddir=/iflytek/chinese-support chinese-support
cd /iflytek/chinese-support && yum localinstall chinese-support(离线安装)
==============================================================
第三步:从其他已解决字符集的RedHat 6.5机器上拷贝字典与字符集
位置:/usr/share/i18n/charmaps
所有的 *.gz
位置:/usr/share/locale
部分如en_US、zh_CN等中文支持包
第四步:设置locale-archive
localedef -f UTF-8 -i zh_CN zh_CN.UTF8
==================================================================
运行localedef命令,能在/usr/lib/locale下自动生成locale-archive文件
==================================================================
若执行localedef报错,未能自动生成locale-archive,从其他已解决字符集的RedHat 6.5机器上拷贝过来
/usr/lib/locale/
---locale-archive
----locale-archive.tmpl
第五步:设置环境变量
locale -a 或 locale -a | grep -E "CN|utf8"
===========================================================打印信息
[root@gpu-centos-no chinese-support]# locale -a | grep CN | grep utf8
bo_CN.utf8
ug_CN.utf8
zh_CN.utf8 (en_US.UTF-8亦可)
==================================================================
echo "export LANG=\"zh_CN.UTF-8\"" >> /etc/profile (配置到~/.bashrc亦可)
env | grep -E "LC|LANG"
locale -a
至此,顽强的RedHat 6.5/CentOS 6.5中文字符集问题解决
=======================================================================
CentOS 6部分中文字符集【其他可能方案】
现象:
中文乱码
解决方法:
vi /etc/sysconfig/i18n (/etc/locale.conf文件亦有效果)
LANG="zh_CN.UTF-8"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
==========================================================
其他涉及的字符集
LANGUAGE="zh_CN.UTF-8"
LC_ALL="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8",
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
==========================================================
参考
http://blog.chinaunix.net/uid-20648944-id-2950413.html
写于文末
第一篇技术类的博客,希望能帮助到遇到同样问题的同道。本文仅表达自我的解决思路,内容可能存在不合理或多余的地方,欢迎邮件 [email protected]进行指正。谢谢。