The Chinese language of the Linux system is garbled, which is a problem that many friends often encounter when they first come into contact with Linux. Moreover, when we move the projects that have been deployed in Wndows to run on Linux, the Chinese output logs of Tomcat are all garbled. (Normal on Windows), it looks very frustrating, so how should we solve it?
System Chinese garbled code
## Tomcat output log Chinese garbled code System environment## Solution steps:
First check whether the Chinese language pack is installed on the system
machines in her in in in on in on in on in on in on in on the names in all available public locales What do several items mean?
{Language code}_{Country code}.{Character set}
zh is the code for Chinese, CN is the code for China, gb18030, gb2312, utf8 is the language character set
Then each item can be commonly understood as "You speak Chinese, you are in China, and the language character set is gb18030/gb2312/utf8" ccosten in us\If the above items are not found, manually install the Chinese language Packageyum install kde-l10n-Chinese somehow 11M in about 11M
# Before modifying the configuration file, let’s take a look at the current system locale
LANG: The language of the current system LC_CTYPE: Language symbols and their classification
LC_NUMERIC: Numbers LC_COLLATE: Comparison and sorting Habit
LC_TIME: Time display format
LC_MONETARY: Currency unit LC_MESSAGES: The information is mainly prompt information, error information, status information, title, label, button and menu, etc. LC_NAME:Name writing method LC_ADDRESS:Address writing method LC_TELEPHONE:Phone number writing method LC_MEASUREMENT:Weights and measures expression LC_PAPER: Default paper size LC_IDENTIFICATION: Overview of the information contained in the locale itself LC_ALL: The highest priority variable. If this variable is set, all LC_* and LANG variables will be forced to follow. Its value We see that although the Chinese language pack is installed, the locale of the machine is not Chinese. First modify the i18n configuration file vim /etc/sysconfig/i18nAdd the following two lines of code LANG="zh_CN.UTF-8"
LC_ALL="zh_CN.UTF-8"
# source /etc/sysconfig/i18n Modify the locale.cnf configuration file
# vim /etc/locale.conf
LANG="zh_CN.UTF-8"
## shall should should should be 10-100ml
####
####
##Change the encoding to UTF-8
Reconnect and check the current system locale
Locale
It is found that the system locale has been successfully changed to "zh_CN.UTF-8"
Try editing Chinese again
# SUCCESS! At this point, the problem of garbled Chinese characters in the system has been solved. 4. Solve the problem of garbled Chinese characters in the Tomcat output log
Now that the Chinese garbled characters in the system have been solved, will the Chinese garbled characters in the Tomcat output log also be solved?
Let’s take a look at the Tomcat output log now
Enter the Tomcat directory
# cd $CATALINA_HOME # tail -f ./logs/catalina.out#, Tomcat log Chinese is still garbled.
Analysis: Since Chinese garbled characters no longer appear in the system, it proves that the system language environment is normal, but Chinese garbled characters still appear in the Tomcat log, indicating that it is an internal problem of Tomcat. I checked some information online and found that it is the JVM. (Java Virtual Machine)
The character set used by the Java virtual machine is inconsistent with the character set used by the system. If you know the reason, the problem will be solved. You can modify the JVM startup parameters by configuring the JVM startup parameters. Character set purpose.
# ls -l ./bin/
Find daemon.sh and catalina.sh and add the following codes respectively:
JAVA_OPTS= "$JAVA_OPTS -Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8 -Duser.language=zh_CN -Dsun.jnu.encoding=UTF-8"
# vim ./ bin/daemon.sh
# vim ./bin/catalina.sh
Save and exit, restart Tomcat # ./bin/shutdown.sh
# ./bin/startup.sh
Now check the output log
# tail -f ./ logs/catalina.out
Send a request to the serverThe above is the detailed content of How to solve the Chinese garbled characters in Tomcat logs?. For more information, please follow other related articles on the PHP Chinese website!