易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 32|回复: 1
收起左侧

centos8.3安装vncserver服务提供访问

[复制链接]
发表于 2024-10-15 17:00:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
Installing VNC Server
) X; v0 v$ W' N4 N* I$ T( C0 p8 r安装vncserver  s5 R# n8 O$ @2 h
TigerVNC is an actively maintained high-performance open-source VNC server. It is available in the default CentOS repositories. To install it, type:
/ Y8 Z+ U" N7 @6 i% U8 Q0 P: D# X2 g
, X% j3 O5 Y  P$ Z#dnf install tigervnc-server   -y: @$ }. n. n9 w

( }/ S" |9 @3 t; d. Q2 P配置vncServer* E  l6 u" N5 |  j* q
Configuring VNC Server' `/ D8 c, c: M/ S* {
In CentOS 8, TigerVNC is configured using the systemd daemon.
3 v3 t* I. V5 l  p( e& Q$ d4 \0 h' s2 [' g7 @
7 Q$ S0 k& x; w0 R
In this example, we’ll show you how to configure TigerVNC for one or more VNC users.& L+ h. i! o1 Z* z9 E
6 [" P1 T$ F* h8 N
Use the vncpasswd command to set up the password. Run the command as the user that will access the VNC server, do not use sudo:
4 p6 J( p3 n, p这里配置vnc的密码:   (root)
; g: d' T" a' `  O6 t2 Svncpasswd. Y; J, L- S8 s2 J5 Y" h" R: G. T
( C' M# J9 t6 k: e# h
7 F" y; t$ {0 s2 F8 {
You will be prompted to enter and confirm the password and whether to set it as a view-only password. If you choose to set up a view-only password, the user will not be able to interact with the VNC instance with the mouse and the keyboard.
0 a8 M+ V/ o: Y$ J  ^3 c$ j8 ~1 L* H% ]/ B# V
The first time the vncpasswd command is run, it will create and store the password file in the user’s ~/.vnc directory.0 F( O0 f3 ]/ C4 |

5 R& ~! Q  f7 `  U$ P. wPassword:
1 p7 K+ M2 C( C; x% n- EVerify:
$ b  w, q2 k$ O# s% IWould you like to enter a view-only password (y/n)? n: w3 l- R" Y3 z; }: j
A view-only password is not used
6 r. g5 K- x2 z( |; X6 B
# i  t' D2 ?0 y) h- `
* o& K1 o6 x; F- k% a( T* w! ~- XIf you’re adding a second user, switch to it and set the password with vncpasswd.
3 N& H$ ^, d0 X2 n" ]- J- S+ u: \) h" n1 }; N
The next step is to configure TigerVNC to use Gnome. VNC reads the user configuration settings from the ~/.vnc/config file. Open the file and add the following:, L9 W  S7 G: e5 e! N

4 R  H* b# O& v$ H7 A2 _0 X#vim ~/.vnc/config9 z- T* G/ e1 n$ ^. L/ U1 E
session=gnome+ S$ D0 N. l  R/ q5 R
geometry=1920x1200    (or 1280x720)
/ F4 b& v9 ?) Y9 F( u8 `localhost          (这个地方不配置,表示所有的都能访问)/ w& W1 d& M2 W
alwaysshared
& s" P3 D! D2 G8 C+ Q4 A' Y
0 @# x+ ~! {5 T7 v$ ~例如:
* e& N/ P; ~0 Q! F1 W7 j- A/ g5 S6 j" X+ N1 ~3 B( X7 t' M
$ cat ~/.vnc/config 4 @6 n) I3 Y' z; l
session=gnome/ e* W* l9 A$ S- p' m
geometry=1280x720
) }# [5 u5 C( |  Q7 Galwaysshared
$ I' P0 b* h" r1 s6 q, n7 V( N2 O( i5 ]9 j: c! ?
; A+ J4 q2 u" X: v/ |$ a/ S

8 P9 X4 O; t. D4 t1 b7 SThe session option specifies the session you want to start, and the geometry option specifies the size of the VNC desktop.
! y( |% p0 F( e  g+ N: v: R( V
$ }( D- j6 l5 mSave and close the file . If you’re adding multiple users, repeat the same step.$ m' `, o2 u, u. T6 T  g, V/ r9 F. v

  H( U& ^5 y6 }; U7 dTigerVNC ships with a file that allows you to map a user to a particular port. The mapping is configured in the /etc/tigervnc/vncserver.users file:! N4 g$ o9 I5 |- q  u/ ~5 a

/ r/ H( _+ T  N  u$ C配置vnc的用户:  L' l: v: _( B# r! w& |( m) V

6 W) n* q. h1 S" l#sudo vim /etc/tigervnc/vncserver.users: b( ^  k. t: n% y! H' P
+ `% o5 j; I- b3 Q, {9 ~4 K/ s$ V
The file uses <display_port>=<username> syntax. In the example below, we are mapping display port :1 to user linuxize. Use the same format to add more users.
  k  Q# n* w5 h/ d  y9 M: ~0 D
# @) Q& ~0 Y3 i4 b. ~# TigerVNC User assignment( x1 p/ C' g4 W
#
! a9 N7 J8 J% k# This file assigns users to specific VNC display numbers.
  U: q5 w5 H4 X2 O, b# The syntax is <display>=<username>. E.g.:
3 r+ H) m/ ~  W6 X#- P3 Z/ R+ [7 W; ?% l& k, C
# :2=andrew
+ i, A' Q. Z1 A: e- L* b' E# :3=lisa7 H# z- }2 q8 h9 q. @5 `
:1=root
* b1 T: |+ J" P! W& ]; w5 A5 o! B: _  |$ x0 Y" `" K
' Z4 w5 h7 ^; j1 P) F: j

& V; W$ U: v3 {9 e+ l' |:1 is the display port number on which the VNC server will run. In our case, the server is running on TCP port 5901 (5900+1). If you map another user, for example, to display port :2, the server will also listen on port 5902 (5900+2).% g4 j* g# \0 Z% i

# H9 X( B) R+ |* e- ^What is important to understand is that when working with VNC servers, :X is a display port that refers to 5900+X.6 D! L* S  Z2 }* w

6 F) c% @" M& q" w% J- w* z8 ?) z! |启动vncserver
9 G8 ?9 z/ ]) U3 p. l- ]0 n8 pStarting the Tigervnc Server' q; s( M# |7 a# U$ K! P" [. x! S
Once you’re done with the configuration, the last step is to start the VNC server.5 y* ~. x& k7 K- Q  ^9 U1 M: X$ ~
4 O  |3 ?9 o! o5 }0 |
To start and enable the VNC service for the user mapped to the display port :1, enter:
0 E. i# t! E+ d! A% [9 E- u6 p
3 [) ?6 s* Y" o* g& R. {' i$ I. e' P1 H3 m" j( e, R, J, Y: X
复制配置文件:& f$ O% b& m- j6 M  V
8 n2 O$ N+ V) F6 R* B+ t
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
, p4 C3 M! U4 i; y
6 F: t# D9 v) [' V# ^: n1 U启动并加入开机启动:
7 Z: `% f* I; k# S9 I% J! s; c0 Msudo systemctl enable vncserver@:1 --now
; I. w. E- O( }" m9 P+ G0 q# w
! s* o! ]5 m: p2 UThe VNC server will listen on port 5901, as we discussed in the previous section.
1 A$ ^. _. Q3 c
8 X8 ]/ S4 C  P! jYou can verify that the service is successfully started with:+ H; ^8 h9 @. M& U/ N) ~5 D
4 d- \: D" n4 J5 N
. @3 i* j" @( G# M6 z5 ^# @
sudo systemctl status vncserver@:1
; _; D4 Z4 M$ e3 ?1 m& ^+ [7 `# B
  I+ E, n. U" b. r● vncserver@:1.service - Remote desktop service (VNC)3 ]" J+ Q1 a$ `2 `5 U* ?* n
   Loaded: loaded (/usr/lib/systemd/system/vncserver@.service; enabled; vendor preset: disabled)/ R, p2 o) R5 _9 m( w# B' r
   Active: active (running) since Thu 2020-12-17 21:49:41 UTC; 8s ago3 N# b0 O7 e( j( B6 ~+ H
  ...
9 J9 ~4 X+ v3 R( A
  A$ B7 X$ b1 {1 \To enable VNC for other users, simply replace 1 with the display port mapped to the user.
9 P% B; z  d. J0 N! d* b
# b3 ?4 i# J' O! y* q& E# t7 OConnecting to VNC server
. O' y- M; J$ E8 t# X1 K% nVNC is not an encrypted protocol and can be subject to packet sniffing. The recommended approach is to create an SSH tunnel to securely forward traffic from your local machine on port 5901 to the remote server on the same port.# k+ ~& m2 q' m
2 k* c; c9 {. ^9 T. Q  E

) U' Y6 @4 [, o' v: SSet Up SSH Tunneling on Linux and macOS8 V' |/ p( k  z1 d
If you run Linux, macOS, or any other Unix-based operating system on your machine, you can easily create a tunnel using the following ssh command:0 W3 [  s6 ~. y8 Q

: ?0 g1 j* c( u# \! J" W0 ]: R1 S4 @ssh -L 5901:10.16.68.5:5901 -N -f -l username remote_server_ip8 x3 C9 `0 O% f, x
Copy8 i1 m! ^% Y. c! W5 Y* x# Z
You will be prompted to enter the user password.( X% Z- A0 L: [% Y

1 s% @7 G! b% g) q# J, \8 qDo not forget to replace username and server_ip_address with your username and the IP address of your server.
7 i8 S" C# o4 o4 d0 P: }, v0 f# }6 O/ S
 楼主| 发表于 2024-10-15 17:00:03 | 显示全部楼层
然后就可以通港vnc客户端进行访问
" c. }& q! g) c, h+ R或者通过外网telnet ip 5901 这个地址,即可  
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-9 00:00 , Processed in 0.052523 second(s), 34 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

快速回复 返回顶部 返回列表