您的位置:首页 > 运维架构 > Linux

linux 默认语言选中文后中断出现乱…

2016-02-23 17:55 513 查看

ssh客户端连接centos乱码问题 - 转

centos5.2配置完成后,正常能显示中文,查看后发现支持utf-8字符集。

而putty和ssh secure shell连接却发现乱码,主要表现为执行vim乱码,su命令乱码。

使用$ locale命令查看,出现如下:

LANG=zh_CN.UTF-8

LANGUAGE=zh_CN:zh

LC_CTYPE="zh_CN.UTF-8"

LC_NUMERIC="zh_CN.UTF-8"

LC_TIME="zh_CN.UTF-8"

LC_COLLATE="zh_CN.UTF-8"

LC_MONETARY="zh_CN.UTF-8"

LC_MESSAGES="zh_CN.UTF-8"

LC_PAPER="zh_CN.UTF-8"

LC_NAME="zh_CN.UTF-8"

LC_ADDRESS="zh_CN.UTF-8"

LC_TELEPHONE="zh_CN.UTF-8"

LC_MEASUREMENT="zh_CN.UTF-8"

LC_IDENTIFICATION="zh_CN.UTF-8"

LC_ALL=

解决方案:

1. 对于putty0.6版本

a.修改centos上/ect/sysconfig/i18n内容为:

LANG="zh_CN.UTF-8"

b.修改putty的configuration窗口内windows->Appearance->font
setting为新宋体,10号字。

修改Translation的Receive data assumed to be in which character
set为:

UTF-8。(因为下来列表中没有中文字符集,GB2312或cp936)。

这样修改完成后,putty就正常支持中文显示了。

2.对于ssh secure
shell版本。

a.将配置的字体改成宋体,但是还是乱码,

b.修改centos的/ect/sysconfig/i18n内容为:

LANG="zh_CN.GB18030"

LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"

SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"

SYSFONT="latarcyrheb-sun16"

---以上内容是网上找到了,照着写了。

发现连接ssh secure shell可以正常显示中文。

用$ locale查看,上面看到的配置都变成了GB18030编码了

** 但是又用putty连接,却又变成了乱码,我理解因为putty仍然用的是utf8编码,

而配置ssh secure shell时,将centos改成gb18030编码了,所以乱码。

c.到服务器上,重新启动了centos,发现显示中文也正常。

3. 如果发现ssh secure
shell有问题,或相关的引起问题,则重新配置putty使用,

配置方案可以参考上述配置。

结论:

因为ssh secure
shell窗口符合window显示,所以暂时定为使用ssh secure shell客户端。

而其也绑定了ftp上传功能,相对方便。

变化:考虑建立mysql等多处使用utf-8编码,所有仍然使用putty客户端,系统编码改成utf-8

如果还不行试试:

下面两个个命令:

//其实英语已经安装了。只要定义一下就可以了。

或者你可以试一下,在出现乱麻的时候

#export LANG=C

#export LC_ALL=C

然后看一下

如果还不行再试试下面:

系统:英文版的Redhat Enterprise AS 4.0

症状:英文显示没问题;中文输入法也没问题;中文网页显示为乱码,不管是用
GB18030还是2312

解决:安装fonts-chinese-3.02-9.6.el5.
给大家推荐个下载地址:这个网址里有你要的那两个文件:http://ftp.dc.volia.com/pub/CentOS/CentOS/

或者用这两个直接下载链接:

http://ftp.dc.volia.com/pub/CentOS/CentOS/fonts-chinese-3.02-9.6.el5.noarch.rpm

http://ftp.dc.volia.com/pub/CentOS/CentOS/fonts-ISO8859-2-75dpi-1.0-17.1.noarch.rpm

此时相关如下:

[root@localhost ~]# rpm -qa | grep fonts- |
wc -l

14

[root@localhost ~]# rpm -qa | grep
fonts-

bitmap-fonts-0.3-5.1.1

xorg-x11-fonts-misc-7.1-2.1.el5

fonts-chinese-3.02-9.6.el5

xorg-x11-fonts-base-7.1-2.1.el5

xorg-x11-fonts-75dpi-7.1-2.1.el5

urw-fonts-2.3-6.1.1

xorg-x11-fonts-100dpi-7.1-2.1.el5

bitstream-vera-fonts-1.10-7

ghostscript-fonts-5.50-13.1.1

xorg-x11-fonts-ISO8859-1-75dpi-7.1-2.1.el5

xorg-x11-fonts-Type1-7.1-2.1.el5

xorg-x11-fonts-ISO8859-1-100dpi-7.1-2.1.el5

dejavu-lgc-fonts-2.10-1

xorg-x11-fonts-truetype-7.1-2.1.el5

[root@localhost ~]# cat
/etc/sysconfig/i18n

LANG="en_US.UTF-8"

SYSFONT="latarcyrheb-sun16"

[root@localhost ~]# locale

LANG=en_US.UTF-8

LC_CTYPE="en_US.UTF-8"

LC_NUMERIC="en_US.UTF-8"

LC_TIME="en_US.UTF-8"

LC_COLLATE="en_US.UTF-8"

LC_MONETARY="en_US.UTF-8"

LC_MESSAGES="en_US.UTF-8"

LC_PAPER="en_US.UTF-8"

LC_NAME="en_US.UTF-8"

LC_ADDRESS="en_US.UTF-8"

LC_TELEPHONE="en_US.UTF-8"

LC_MEASUREMENT="en_US.UTF-8"

LC_IDENTIFICATION="en_US.UTF-8"

LC_ALL=

[root@localhost ~]#

网上提供的消除中文乱码的方法如下,只是一种治标的方法,应该是先查看有没有相关的字体包已经安装,再考虑更改如下设置:

将i18n内容改为

LANG="zh_CN.GB18030"

LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"

SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"

SYSFONT="lat0-sun16"

------------------------------------

下述命令如果有下述信息说明装有中文字体:

[root@localhost ~]# xlsfonts | grep
gb

-isas-fangsong
ti-medium-r-normal--16-160-72-72-c-160-gb2312.1980-0

-isas-song
ti-medium-r-normal--16-160-72-72-c-160-gb2312.1980-0

-isas-song
ti-medium-r-normal--24-240-72-72-c-240-gb2312.1980-0

-misc-ar pl shanheisun
uni-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0

-misc-ar pl zenkai
uni-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0

-misc-zysong18030-medium-r-normal--0-0-0-0-c-0-gb18030.2000-0

-misc-zysong18030-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0

-misc-zysong18030-medium-r-normal--0-0-0-0-c-0-gbk-0

-urw-dingbats-medium-r-normal--0-0-0-0-p-0-adobe-fontspecific

hanzigb16fs

hanzigb16st

hanzigb24st

字体所在目录:/usr/share/locale

[root@localhost ~]# cd
/usr/share/locale

[root@localhost locale]#ll

................................................

drwxr-xr-x 4 root root 4096 Dec 14 2006 zh_CN

drwxr-xr-x 3 root root 4096 Sep 26 17:38 zh_CN.GB2312

drwxr-xr-x 3 root root 4096 Sep 26 17:31 zh_HK

drwxr-xr-x 4 root root 4096 Dec 14 2006 zh_TW

drwxr-xr-x 3 root root 4096 Sep 26 17:38 zh_TW.Big5

drwxr-xr-x 3 root root 4096 Sep 26 17:31 znd

drwxr-xr-x 3 root root 4096 Sep 26 17:31 zu

drwxr-xr-x 3 root root 4096 Sep 26 17:31 zun

[root@localhost locale]# cd
zh_CN

[root@localhost zh_CN]# ll

total 16

drwxr-xr-x 2 root root 4096 Oct 12 11:35 LC_MESSAGES

drwxr-xr-x 2 root root 4096 Sep 26 17:35 LC_TIME

[root@localhost zh_CN]#

LC_MESSAGES目录中是MO (Machine
Object) files,可以理解为中文库文件,示例如下:

[root@localhost zh_CN]# cd LC_MESSAGES/

[root@localhost LC_MESSAGES]# msgunfmt bindconf.mo -o
/tmp/ttt.po

[root@localhost LC_MESSAGES]#

[root@localhost LC_MESSAGES]# cat /tmp/ttt.po| more

msgid ""

msgstr ""

"Project-Id-Version: zh_CN\n"

"Report-Msgid-Bugs-To: \n"

"POT-Creation-Date: 2007-09-11 09:59+0800\n"

"PO-Revision-Date: 2005-12-07 11:33+1000\n"

"Last-Translator: \n"

"Language-Team: <zh@li.org>\n"

"MIME-Version: 1.0\n"

"Content-Type: text/plain; charset=UTF-8\n"

"Content-Transfer-Encoding: 8bit\n"

"X-Generator: KBabel 1.9.1\n"

msgid ""

"\n"

"\n"

"\n"

"\n"

"\n"

msgstr ""

"\n"

"\n"

"\n"

"\n"

"\n"

msgid ""

"\n"

" Note that enabling the update forwarding feature on a slave
server may "

"expose master servers relying on insecure IP address based access
control to "

"attacks."

msgstr ""

"\n"

"请注意,在一个从服务器上启用更新转发功能可能会使那些依赖基于访问控制的不安全"

"的 IP 地址的主服务器受到恶意攻击。"

----more----

定义区域语言的配置文件位置:

[root@localhost ~]# cd
/usr/share/i18n/

[root@localhost i18n]# ll

total 32

drwxr-xr-x 2 root root 12288 Sep 26 17:31 charmaps

drwxr-xr-x 2 root root 12288 Sep 26 17:31 locales

[root@localhost i18n]# ll
charmaps/GB*

-rw-r--r-- 1 root root 472428 Jan 15 2007 charmaps/GB18030.gz

-rw-r--r-- 1 root root 1603 Jan
15 2007 charmaps/GB_1988-80.gz

-rw-r--r-- 1 root root 44803 Jan 15 2007 charmaps/GB2312.gz

-rw-r--r-- 1 root root 119113 Jan 15 2007 charmaps/GBK.gz

[root@localhost i18n]# ll
locales/zh_*

-rw-r--r-- 1 root root 5618 Jan 15 2007 locales/zh_CN

-rw-r--r-- 1 root root 5851 Jan 15 2007 locales/zh_HK

-rw-r--r-- 1 root root 6102 Jan 15 2007 locales/zh_SG

-rw-r--r-- 1 root root 5605 Jan 15 2007 locales/zh_TW

以前还有/usr/share/i18n/repertoiremaps目录和其中相关的配置文件,现在已经不用。

[root@localhost i18n]# man
localedef 用来生成区域设置

修改系统编码变换设置,告诉系统如何将汉字编码转换为系统内部码:

[root@localhost ~]# locate
gconv-modules
//查找配置文件位置

/usr/lib/gconv/gconv-modules

/usr/lib/gconv/gconv-modules.cache

XFree86设置:

[root@localhost ~]# locate locale.dir

/usr/share/X11/locale/locale.dir

环境变量的设置:

[root@localhost ~]# echo
$LANG
//这是我电脑上的配置

en_US.UTF-8

变回英文语言

修改/etc/sysconfig/i18n内容为:

LANG="en_US.UTF-8"

SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en"

SYSFONT="latarcyrheb-sun16"

export LC_ALL=en_US

相关阅读:

vim使用简介

Shutdown(自动关机) 命令用法

Linux route 命令输出信息

Linux操作系统安装VMware过程详细解析
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: