1 问题定位
windows下面无问题,在linux下面出现问题,中文变成方框,经过排查发现linux下缺少字体,只需将widows字体上传到linux服务器进行配置加载就好
2 解决方案
2.1 方案一
2.1.1 安装字体库
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n7" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@localhost ~]# yum -y install fontconfig</pre>
2.1.2 新建目录
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n9" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@localhost ~]# /usr/share/fonts
[root@localhost fonts]# mkdir chinese
[root@localhost ~]# cd chinese</pre>
2.1.2 上传Windows字体文件
将C:\Windows\Fonts下面的所有文件,上传到服务器的/usr/share/fonts/chinese目录下
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n13" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@localhost chinese]# ll
total 185340
-rwxr-xr-x 1 root root 980756 Jan 20 16:10 arialbd.ttf
-rwxr-xr-x 1 root root 721144 Jan 20 16:10 arialbi.ttf
-rwxr-xr-x 1 root root 717428 Jan 20 16:10 ariali.ttf
-rwxr-xr-x 1 root root 1036584 Jan 20 16:10 arial.ttf
-rwxr-xr-x 1 root root 167592 Jan 20 16:10 ariblk.ttf
-rwxr-xr-x 1 root root 40340 Jan 20 16:10 Arvo-Regular.ttf
-rwxr-xr-x 1 root root 131660 Jan 20 16:10 AxureHandwriting-BoldItalic.otf
-rwxr-xr-x 1 root root 138388 Jan 20 16:10 AxureHandwriting-Bold.otf
-rwxr-xr-x 1 root root 68244 Jan 20 16:10 AxureHandwriting-Italic.otf
-rwxr-xr-x 1 root root 64288 Jan 20 16:10 AxureHandwriting.otf
-rwxr-xr-x 1 root root 322864 Jan 20 16:10 bahnschrift.ttf
-rwxr-xr-x 1 root root 229408 Jan 20 16:10 comicbd.ttf
...</pre>
2.1.3 安装字体
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n15" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@localhost chinese]# yum -y install ttmkfdir </pre>
2.1.4 刷新字体缓存
进行这个操作之后,就不用
重启机器
了
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n19" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@localhost chinese]# fc-cache</pre>
2.1.5 查看安装字体
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n21" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@localhost ~]# fc-list
/usr/share/fonts/chinese/cour.ttf: Courier New:style=Standaard,Regular
/usr/share/fonts/chinese/consolai.ttf: Consolas:style=Italic
/usr/share/fonts/chinese/monbaiti.ttf: Mongolian Baiti:style=Regular
/usr/share/fonts/chinese/georgiai.ttf: Georgia:style=Italic,Cursiva
/usr/share/fonts/chinese/impact.ttf: Impact:style=Regular,Standard
/usr/share/fonts/chinese/PoiretOne-Regular.ttf: Poiret One:style=Regular
/usr/share/fonts/chinese/palabi.ttf: Palatino Linotype:style=Negreta cursiva,Bold Italic
/usr/share/fonts/chinese/ntailu.ttf: Microsoft New Tai Lue:style=Regular
/usr/share/fonts/chinese/himalaya.ttf: Microsoft Himalaya:style=Regular
/usr/share/fonts/chinese/Roboto-Regular.ttf: Roboto:style=Regular
/usr/share/fonts/chinese/LucidaBrightRegular.ttf: Lucida Bright:style=Regular
/usr/share/fonts/chinese/phagspa.ttf: Microsoft PhagsPa:style=Regular
/usr/share/fonts/chinese/trebucbd.ttf: Trebuchet MS:style=Bold,Negrita
/usr/share/fonts/chinese/gadugi.ttf: Gadugi:style=Regular
/usr/share/fonts/chinese/palai.ttf: Palatino Linotype:style=Cursiva,Italic
/usr/share/fonts/chinese/bahnschrift.ttf: Bahnschrift:style=Bold SemiCondensed
/usr/share/fonts/chinese/bahnschrift.ttf: Bahnschrift:style=Light
/usr/share/fonts/chinese/bahnschrift.ttf: Bahnschrift:style=SemiLight SemiCondensed
/usr/share/fonts/chinese/ntailub.ttf: Microsoft New Tai Lue:style=Bold
/usr/share/fonts/chinese/consola.ttf: Consolas:style=Regular
/usr/share/fonts/chinese/ariali.ttf: Arial:style=Πλάγια,Italic
/usr/share/fonts/chinese/bahnschrift.ttf: Bahnschrift:style=Bold Condensed
...</pre>
2.2 方案二
2.2.1 JDK目录
JDK目录
/opt/module/jdk1.8.0_144
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n27" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@localhost jre]# echo $JAVA_HOME
/opt/module/
[root@localhost jre]# cd /opt/module/
[root@localhost module]# ll
total 12
drwxr-xr-x 7 root root 4096 Jul 22 2017 jdk1.8.0_144
[root@localhost module]#</pre>
2.2.2 创建目录
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n29" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@localhost jre]# cd /opt/module/jdk1.8.0_144/jre/lib/fonts
[root@localhost fonts]# mkdir fallback
[root@localhost fonts]# cd fallback</pre>
2.2.3 上传Windows字体文件
将C:\Windows\Fonts下面的所有文件,上传到服务器的/opt/module/jdk1.8.0_144/jre/lib/fonts/fallback目录下
<pre spellcheck="false" class="md-fences mock-cm md-end-block" lang="" cid="n33" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[root@localhost fallback]# ll
total 185340
-rwxr-xr-x 1 root root 980756 Jan 20 16:10 arialbd.ttf
-rwxr-xr-x 1 root root 721144 Jan 20 16:10 arialbi.ttf
-rwxr-xr-x 1 root root 717428 Jan 20 16:10 ariali.ttf
-rwxr-xr-x 1 root root 1036584 Jan 20 16:10 arial.ttf
-rwxr-xr-x 1 root root 167592 Jan 20 16:10 ariblk.ttf
-rwxr-xr-x 1 root root 40340 Jan 20 16:10 Arvo-Regular.ttf
-rwxr-xr-x 1 root root 131660 Jan 20 16:10 AxureHandwriting-BoldItalic.otf
-rwxr-xr-x 1 root root 138388 Jan 20 16:10 AxureHandwriting-Bold.otf
-rwxr-xr-x 1 root root 68244 Jan 20 16:10 AxureHandwriting-Italic.otf
-rwxr-xr-x 1 root root 64288 Jan 20 16:10 AxureHandwriting.otf
-rwxr-xr-x 1 root root 322864 Jan 20 16:10 bahnschrift.ttf
-rwxr-xr-x 1 root root 229408 Jan 20 16:10 comicbd.ttf</pre>
2.3 方案三
如果能确定项目中使用的字体对应的字体文件,只需上传单个文件,比如
宋体
对应的字体文件就是simsun.ttc
,这样只需操作一个文件的上传就可以完成问题解决
3 重启服务
重启应用服务,比如tomcat等
4 相关资源
- 下载地址 https://download.csdn.net/download/qq_15769939/14901213
- 感谢老铁们点个关注,然后评论区留邮箱,看到后第一时间发