centos7下远程图形化浏览器解决方案

背景:

越来越多的项目会首选linux作为基础系统,一般情况下客户提供的都是没有图像化的linux,但有些配置需要通过浏览器来修改并查看(比如nacos,roketmq-admin等),因此便需要centos7下实现浏览器功能。

环境:

系统:centos7.6 1810
浏览器:centos7下通过yum安装chrome和firefox
Ssh工具:MobaXterm

浏览器的安装详见centos7浏览器安装文档,此处略。

以下以firefox为例。

通过MobaXterm远程ssh服务器

1.启动firefox发现报错

处理:
yum -y install xorg-x11-xauth
reboot
机器重启后查看DISPLAY值,并运行Firefox进行测试。
如果DISPLAY值还是空的

根据登录信息

以下以MobaXterm为例:
export DISPLAY=192.168.11.58:0.0
永久生效考虑放在/etc/profile
source /etc/profile
拓展:如果是xmanager,就根据broadcast进行配置

  1. 启用 X11 Forwarding
    sudo vim /etc/ssh/sshd_config
1 #AllowAgentForwarding yes
2 #AllowTcpForwarding yes
3 #GatewayPorts no
4 X11Forwarding yes
5 #X11DisplayOffset 10
6 X11UseLocalhost no

systemctl restart sshd
3.如果有如下报错:

处理方法
vim ~/.bash_profile

追加以下一行:

 unset LIBGL_ALWAYS_INDIRECT

yum install -y mesa-libGLES-devel.x86_64 mesa-dri-drivers
4.再次启动

选择是
展现出来,浏览器可以使用,但是出现了乱码

5.乱码处理:
A.查看所有字体:
fc-list // 如果提示 fc-list: command not found,则需要安装# yum install fontconfig

B.查看中文字体:
fc-list :lang=zh

此处可以看出,系统没有中文字体;
C.找到win10的字体,并复制到其他目录:
C:\Windows\Fonts\微软雅黑

D.上传字体到/root:

E.把MSYH.TTF复制到/usr/share/fonts/目录下,使用如下命令:
cd /root
cp msyh.ttc /usr/share/fonts/

F.建立字体索引信息,更新字体缓存,使用如下命令:
cd /usr/share/fonts/

mkfontscale //如果提示 mkfontscale: command not found,需自行安装 # yum install mkfontscale

mkfontdir

fc-cache //如果提示 fc-cache: command not found,则需要安装# yum install fontconfig

G.查看中文字体是否安装成功:
fc-list :lang=zh

重新打开firefox

显示正常

验证下谷歌

google-chrome --no-sandbox http://www.baidu.com

验证下谷歌

google-chrome --no-sandbox http://www.baidu.com

谷歌启动后也显示正常,可直接使用,但是session有报错,不影响使用,回头在研究处理。

posted @ 2023-02-14 12:52  海yo  阅读(770)  评论(0编辑  收藏  举报