使用SSHSecureShellClient客户端连接Linux服务器,把字符集设置为:
export LC_CTYPE=zh_CN.GB18030
export LC_ALL=zh_CN.GB18030
export LANG=zh_CN.GB18030
中文可以正常显示了,解决了客户端连接Linux系统中文乱码问题。但是在安装一些软件时,比如安装GitLab时,显示Warnings信息安装失败,Warnings信息截取部分如下:
Running handlers:
There was an error running gitlab-ctl reconfigure:
execute[/opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8] (postgresql::enable line 49) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘1’
---- Begin output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
STDOUT: The files belonging to this database system will be owned by user “gitlab-psql”.
This user must also own the server process.
The database cluster will be initialized with locale “zh_CN.GB18030”.
STDERR: initdb: error: encoding mismatch
The encoding you selected (UTF8) and the encoding that the
selected locale uses (GB18030) do not match. This would lead to
misbehavior in various character string processing functions.
Rerun initdb and either do not specify an encoding explicitly,
or choose a matching combination.
---- End output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
Ran /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 returned 1
Warnings:
Environment variable LC_ALL specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.
截图如下:
以上是安装GitLab时,把字符集更改成zh_CN.GB18030造成安装失败。通常Linux服务器安装软件都是英文版的,如果把字符集设置成zh_CN.GB18030可能安装失败,所以把字符集更改为en_US.UTF-8字符集就解决问题了:
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
如下图所示:
更改字符集后再进行安装GitLab软件就成功了。这个方法也适用其他软件。
注:每次使用客户端连接Linux服务器时,都要手动改一下。