RHEL7 and CentOS7 languages, character encoding, keyboard mapping, X11 layout settings (localectl) - system management (1)

Keywords: encoding Linux Red Hat less

Reading the official documents of Red Hat Enterprise Linux 7 these days, I found some system management methods that are much better than before. I am going to share my reading and learning experience with a series of articles. At the beginning of the system management guidance, the problems of language, character encoding and keyboard layout were mentioned. Now let's share these contents. There will be no more nonsense in the next series of articles. Please forgive me!
System area settings refer to the language settings of system services and user interfaces. Keyboard layout settings are used to control character console layout and graphical user interface. These settings can be modified by modifying the / etc/locale.conf configuration file or by using the localectl unit. Of course, you can also use the graphical user interface to accomplish this task. I am accustomed to the operation and maintenance of Linux server under the character console, so this article will not involve the operation of graphical interface settings.

I. Setting up System Area

Most system locales are stored in the / etc/locale.conf configuration file
At the beginning of system startup, it will be read by the system daemon. This setting is inherited by each service and user unless individual users or programs rewrite them.
1. By modifying / etc/locale.conf, the system area settings can be modified. Edit the file: Write the following two lines in the configuration file:

LANG=zh_CN.UTF-8
LC_MESSAGES=C

zh: Language is Chinese, CN: Mainland China of a country or region, UTF-8: character encoding is UTF-8.
LC_MESSAGES=C: Determines the locale and uses it to write diagnostic information to standard error output.
Other options can be found in the following table:

Option Description
LANG Provides a default value for the system locale.
LC_COLLATE Changes the behavior of functions which compare strings in the local alphabet.
LC_CTYPE Changes the behavior of the character handling and classification functions and the multibyte character functions.
LC_NUMERIC Describes the way numbers are usually printed, with details such as decimal point versus decimal comma.
LC_TIME Changes the display of the current time, 24-hour versus 12-hour clock.
LC_MESSAGES Determines the locale used for diagnostic messages written to the standard error output.

2. Modify the system area through the localectl command.
(1) Display the current system area status.

[root@Geeklp-Administrator ~]# localectl status
   System Locale: LANG=zh_CN.UTF-8
       VC Keymap: cn
      X11 Layout: cn

(2) List available system locales.

[root@Geeklp-Administrator ~]# localectl list-locales
...
zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8
zh_HK
zh_HK.big5hkscs
zh_HK.utf8
zh_SG
zh_SG.gb2312
zh_SG.gbk
zh_SG.utf8
zh_TW
zh_TW.big5
zh_TW.euctw
zh_TW.utf8
...

The above only excerpts the content of the regional settings of the Chinese Department system.
(3) Modify the system area settings.

[root@Geeklp-Administrator ~]# localectl set-locale LANG=zh_HK.utf8

Modifications will not take effect immediately after they are completed. They must be restarted before they take effect.

2. Setting Keyboard Mapping and X11 Layout

(1) List keyboard mappings.

[root@Geeklp-Administrator ~]# localectl list-keymaps 

(2) Modify keyboard mapping.

[root@Geeklp-Administrator ~]# localectl set-keymap us
[root@Geeklp-Administrator ~]# localectl
   System Locale: LANG=zh_CN.utf8
       VC Keymap: us
      X11 Layout: us
       X11 Model: pc105+inet
     X11 Options: terminate:ctrl_alt_bksp

In the above, we can see that VC Keymap is CN and X11 Layout is cn, which will take effect immediately after the modification is completed.
(3) Modify the X11 layout.

[root@Geeklp-Administrator ~]# localectl set-x11-keymap cn
[root@Geeklp-Administrator ~]# localectl 
   System Locale: LANG=zh_CN.utf8
       VC Keymap: cn
      X11 Layout: cn

We can see that the display content is two lines less, and the modification takes effect in time.
Here are some helpful information about localectl.

[root@Geeklp-Administrator ~]# localectl --help
localectl [OPTIONS...] COMMAND ...
Query or change system locale and keyboard settings.
  -h --help                Show this help
     --version             Show package version
     --no-pager            Do not pipe output into a pager
     --no-ask-password     Do not prompt for password
  -H --host=[USER@]HOST    Operate on remote host
  -M --machine=CONTAINER   Operate on local container
     --no-convert          Don't convert keyboard mappings
Commands:
  status                   Show current locale settings
  set-locale LOCALE...     Set system locale
  list-locales             Show known locales
  set-keymap MAP [MAP]     Set console and X11 keyboard mappings
  list-keymaps             Show known virtual console keyboard mappings
  set-x11-keymap LAYOUT [MODEL [VARIANT [OPTIONS]]]
                           Set X11 and console keyboard mappings
  list-x11-keymap-models   Show known X11 keyboard mapping models
  list-x11-keymap-layouts  Show known X11 keyboard mapping layouts
  list-x11-keymap-variants [LAYOUT]
                           Show known X11 keyboard mapping variants
  list-x11-keymap-options  Show known X11 keyboard mapping options

Posted by napa169 on Thu, 20 Dec 2018 22:27:05 -0800