Chinese characters are garbled when Java generates image watermark under Centos7 because Chinese fonts are not installed.
The following are detailed steps for manually installing Chinese fonts based on Centos7. When there are more servers in the test or production environment, it is recommended to use automated operation and maintenance tools.
1# Install font library
2 $ yum -y install fontconfig
34# Check if there are Chinese fonts
5 $ fc-list :lang=zh
67# Create Chinese font catalog
8 $ mkdir /usr/share/fonts/chinese
910# C in windows:\Windows\Find the corresponding font in the Fonts directory and copy it to the chinese directory. Here we take Songti as an example
11 $ scp simsun.ttc simsunb.ttf root@xxxxx:/usr/share/fonts/chinese
1213# Check if there are Chinese fonts
14 $ fc-list :lang=zh
15 /usr/share/fonts/chinese/simsun.ttc: SimSun,Song Ti:style=Regular,conventional
16 /usr/share/fonts/chinese/simsun.ttc: NSimSun,New Song:style=Regular,conventional
Usually there are many servers in the test or production environment. The following records how to use Ansbile to install Chinese fonts in batches.
1# ansbile playbook execution
2 $ ansible-playbook fonts.yml
34# Verify that all servers are valid
5 $ ansible all -m shell -a "fc-list :lang=zh"
6 sever01 | SUCCESS | rc=0>>7/usr/share/fonts/chinese/simsun.ttc: SimSun,Song Ti:style=Regular,conventional
8 /usr/share/fonts/chinese/simsun.ttc: NSimSun,New Song:style=Regular,conventional
9 sever02 | SUCCESS | rc=0>>10/usr/share/fonts/chinese/simsun.ttc: SimSun,Song Ti:style=Regular,conventional
11 /usr/share/fonts/chinese/simsun.ttc: NSimSun,New Song:style=Regular,conventional
12......
Contents of fonts.yml:
1- - - 2- name: Install Chinese Fonts.3 hosts: all
4 remote_user: root
5 become: yes
6 become_method: sudo
7 become_user: root
8 roles:9- fonts
Ansible playbook directory structure (useless directories removed):
1 $ tree roles/fonts
2 roles/fonts
3 ├── files
4 │ ├── simsun.ttc
5 │ └── simsunb.ttf
6 └── tasks
7 └── main.yml
892 directories,3 files
task/main.yml content:
1- - - 2# tasks file for fonts
34- name: install fontconfig.5 yum:6 name:"{{ item }}"7 state: installed
8 with_items:9- fontconfig
10 ignore_errors:true1112- name: mkdir /usr/share/fonts/chinese.13 file:14 path:/usr/share/fonts/chinese
15 state: directory
16 mode:07551718- name: Copy fonts to agent.19 copy:20 src:"{{ item }}"21 dest:/usr/share/fonts/chinese
22 with_items:23- simsun.ttc
24- simsunb.ttf
Recommended Posts