CentOS 升级 glibc 及升级后中文乱码

(39) 2024-03-20 07:01:01

编译安装 glibc :

下载地址:http://ftp.gnu.org/gnu/glibc/

// 查看系统glibc支持的版本:
strings /lib64/libc.so.6 |grep GLIBC_ 
...

rpm -qa |grep glibc
glibc-common-2.12-1.209.el6_9.2.x86_64
glibc-2.12-1.209.el6_9.2.x86_64
glibc-headers-2.12-1.209.el6_9.2.x86_64
glibc-devel-2.12-1.209.el6_9.2.x86_64
// 目前最高只支持到 2.12 版本。现需升级到GLIBC_2.14

// 根据情况安装开发工具
yum groupinstall -y "development tools"

// 下载地址:http://www.gnu.org/software/libc/
tar -vxf glibc-2.14.tar.gz
mkdir build
cd build

../glibc-2.14/configure --prefix=/usr/local/glibc-2.14
make -j4

// 执行 "make install" 的过程中 可能 会提示:
// Can't open configuration file /usr/local/glibc-2.14/etc/ld.so.conf: No such file or directory
// 解决:
mkdir -p /usr/local/glibc-2.14/etc/
cp /etc/ld.so.conf /usr/local/glibc-2.14/etc/ld.so.conf
make install

// 下面的命令解决 glibc 在更新到 libc-2.14.so 后中文乱码的问题:
// 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_ALL to default locale: No such file or directory
make localedata/install-locales

// 临时修改环境变量,否则执行任何命令都会报:
// libc.so.6: cannot open shared object file: No such file or directory
echo $LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/glibc-2.14/lib:$LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH

// 修改/lib64/libc.so.6的软链接来源,由之前的libc-2.12.so修改为libc-2.14.so
cd /lib64
ll libc.so.6
ll /usr/local/glibc-2.14/lib/libc-2.14.so
cp /usr/local/glibc-2.14/lib/libc-2.14.so /lib64/

// 删除libc-2.12.so之前的软链接
unlink /lib64/libc.so.6

ln -s libc-2.14.so /lib64/libc.so.6
ll libc.so.6

// 验证
strings /lib64/libc.so.6 |grep GLIBC_

glibc 安装参考:https://www.cnblogs.com/kevingrace/p/8744417.html

异常

执行 “make install” 时提示:

Can't open configuration file /usr/local/glibc-2.14/etc/ld.so.conf: No such file or directory

解决

whereis 查找一下d.so.conf所在的路径
[root@I05-1 glibc]# whereis ld.so.conf
ld.so: /etc/ld.so.cache /etc/ld.so.conf /usr/share/man/man8/ld.so.8.gz

然后将d.so.conf拷贝到 /usr/local/glibc-2.14/etc/ld.so.conf(提示的文件目录中)

cp /etc/ld.so.conf /usr/local/glibc-2.14/etc/ld.so.conf
升级完 glibc 后,在命令行执行 locale 后提示:
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

...

解决:

进入安装 glibc 时创建的编译目录,这里是 build 目录,执行命令:

make localedata/install-locales

再次执行 locale 命令, 即显示正常。

参考 : https://blog.csdn.net/guitar___/article/details/77651983

end.

THE END

发表回复