去评论
海欣资源

linux系统安装中文字体库教程

dscca
2022/05/12 18:13:25
Linux字体文件放在/usr/share/font/,只要将字体文件拷贝到这里就可以了。
这里示例安装Windows的所有字体。
    1,新建路径存放字体库:/usr/share/fonts/
    2,进入Windows下> 的字体库目录c:\windows\Fonts。复制字体库到创建好的字体库目录/usr/share/fonts/。
    3,进入字体库目录,刷新系统即刻生效,输入命令:mkfontscale ; mkfontdir ; fc-cache。
一、查看系统字体
在开始安装之前,我们先查看系统中已经安装的字体。
要查看系统中已经安装的字体,我们可以使用fc-list命令进行查看。如果系统中没有该命令的话,我们需要先安装相关的软件包。
查看系统类型:cat /etc/issue
在centos上,使用如下命令进行安装:
yum install -y fontconfig mkfontscale
在ubuntu上,使用如下命令进行安装:
sudo apt-get -y install fontconfig xfonts-utils
查看系统默认字体:fc-list
如果要查看系统中已经安装的中文字体,我们可以使用如下命令:fc-list :lang=zh

二、安装字体
在centos上和ubuntu上安装字体方法都是一样的,我们只需要进行相关的操作即可。
把MSYH.TTF复制到/usr/share/fonts/目录下,使用rz,Xftp等方式都可以:


更新字体缓存,使用如下命令:
cd /usr/share/fonts/
mkfontscale
mkfontdir
fc-cache


[root@scm fonts]# cd /usr/share/fonts/
[root@scm fonts]# mkfontscale
[root@scm fonts]# mkfontdir
[root@scm fonts]# fc-cache -fv
/usr/share/fonts: caching, new cache contents: 2 fonts, 0 dirs
/usr/share/X11/fonts/Type1: skipping, no such directory
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/var/cache/fontconfig: cleaning cache directory
/root/.fontconfig: not cleaning non-existent cache directory
fc-cache: succeeded


至此,字体已经安装完毕。
现在我们再来查看微软雅黑字体,是否安装成功,使用如下命令:
fc-list :lang=zh


[root@tonykorn97 fonts]# fc-list :lang=zh
华文彩云,STCaiyun:style=Regular
幼圆,YouYuan:style=Regular
华文琥珀,STHupo:style=Regular
方正姚体,FZYaoTi:style=Regular
新宋体,NSimSun:style=Regular
仿宋,FangSong:style=Normal,oby?ejné,Standard,Κανονικ?,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
楷体,KaiTi:style=Normal,oby?ejné,Standard,Κανονικ?,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
华文宋体,STSong:style=Regular
微软雅黑,Microsoft YaHei:style=Normal,oby?ejné,Standard,Κανονικ?,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
宋体,SimSun:style=Regular
华文仿宋,STFangsong:style=Regular
华文新魏,STXinwei:style=Regular
华文行楷,STXingkai:style=Regular
华文隶书,STLiti:style=Regular
黑体,SimHei:style=Normal,oby?ejné,Standard,Κανονικ?,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
华文中宋,STZhongsong:style=Regular
微软雅黑,Microsoft YaHei:style=Negreta,tu?né,fed,Fett,?ντονα,Bold,Negrita,Lihavoitu,Gras,Félk?vér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kal?n,Krepko,Lodia
方正舒体,FZShuTi:style=Regular
华文细黑,STXihei:style=Regular
隶书,LiSu:style=Regular
华文楷体,STKaiti:style=Regular


通过上图,我们可以很明显的看出微软雅黑字体已经成功安装。
    部署中遇到的问题:
    测试环境:部署完成没有重启jar包,程序里读取不出来字体库,重启服务器可以了,
    生产环境:部署完成字体库,没有重启服务器,重启的jar包,程序读取出字体库了,
    综合以上情况,先重启服务程序,最后如果都不行在启动服务器,别被其他的文章坑了。
安装yum install -y fontconfig mkfontscale 报错:

[root@VM-16-11-centos fonts]# yum install -y fontconfig mkfontscale
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-Epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Repository epel is listed more than once in the configuration
CentOS Linux 8 - AppStream                                                                                                                22  B/s |  38  B     00:01   
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist


解决办法:
# 进入yum.repos.d 目录下
cd /etc/yum.repos.d/
# 修改源链接
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
# 要将之前的mirror.centos.org 改成 vault.centos.org
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*