linux安装glibc-2.14后字符集出问题

hickwu 2020-01-31

1)升级出问题,ssh登录系统显示

-bash: warning: setlocale: LC_CTYPE: cannot change locale (zh_CN.UTF-8): No such file or directory
-bash: warning: setlocale: LC_COLLATE: cannot change locale (zh_CN.UTF-8): No such file or directory
-bash: warning: setlocale: LC_MESSAGES: cannot change locale (zh_CN.UTF-8): No such file or directory
-bash: warning: setlocale: LC_NUMERIC: cannot change locale (zh_CN.UTF-8): No such file or directory
-bash: warning: setlocale: LC_TIME: cannot change locale (zh_CN.UTF-8): No such file or directory

2)猜想问题原因

安装了一个新的glibc库而不是覆盖升级,造成系统中目前至少有两个locale命令,Linux不知道用哪个?而用了新装的/usr/local/glibc-2.14/bin/locale,而不是系统默认的/usr/bin/locale

3)问题排查

联想到安装glibc后出的问题,运行命令

#strace localedef

open("/usr/local/glibc-2.14/lib/locale/zh_CN.UTF-8/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh_CN.utf8/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh_CN/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh.UTF-8/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh.utf8/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh_CN.UTF-8/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh_CN.utf8/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh_CN/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh.UTF-8/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh.utf8/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/glibc-2.14/lib/locale/zh/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory)

注:也可以用(# strings /opt/glibc-2.14/bin/locale|grep locale)

查找/usr/local/glibc-2.14/bin目录下没有locale文件夹

4)问题解决

# cp /usr/lib/locale/locale-archive /usr/local/glibc-2.14/lib/locale/locale-archive

5)检查

运行命令

strings /opt/glibc-2.14/bin/locale|grep locale
setlocale
b/localeH
b/localeH
/locale.
locale (GNU %s) %s
all-locales
/usr/local/glibc-2.14/lib/locale/locale-archive
locale: %-15.15s archive: /usr/local/glibc-2.14/lib/locale/locale-archive
/usr/local/glibc-2.14/lib/locale
locale: %-15.15s directory: %.*s
/usr/local/glibc-2.14/share/locale
Cannot set LC_CTYPE to default locale
Cannot set LC_MESSAGES to default locale
Cannot set LC_COLLATE to default locale
Cannot set LC_ALL to default locale
Write names of available locales
Get locale-specific information.

问题解决。

相关推荐