我開始這個系列,是爲了系統性的學習和記錄企業應用服務的環境搭建和應用部署等整個過程,這個系列會精彩呈現如何經過一點點的砌磚,鑄成一座高樓。其中可能會包含了一些比較初級的內容,大家若是早就掌握了能夠跳過,挑選本身關心的章節。
這個系列開始的背景,是一位慷慨的許姓朋友贊助了我一臺騰訊雲服務器,CentOS7.4+單核+2G內存。配置低了一點,但考慮到只是本身玩玩也還湊合,下面就開始咱們漫漫長征第一步。vim
用root 用戶
一、建立組 fzuwindows
[root@VM_60_202_centos ~]#groupadd fzu --建立組 fzu [root@VM_60_202_centos ~]#useradd -g fzu -m kerry --建立用戶 kerry 並加入fzu [root@VM_60_202_centos ~]#passwd kerry --設置/修改 kerry的密碼,會彈出輸入密碼,再確認密碼
二、建立/u01 目錄,並將 /u01 的權限賦予 kerrycentos
[root@VM_60_202_centos ~]#mkdir /u01 [root@VM_60_202_centos ~]#chown -R kerry:fzu /u01
三、給kerry 用戶賦予 sudo,/etc/sudoers 文件只能用專用的 visudo 編輯器編輯,執行命令 visudo 就能夠服務器
[root@VM_60_202_centos ~]#visudo --進入 /etc/sudoers 的文本 -- 添加上如下代碼,就能夠用kerry用戶登陸時用sudo,而且不須要輸入kerry的密碼進行驗證。 kerry ALL=(ALL) NOPASSWD: ALL
一、首先試試服務器裝了VNC沒session
[root@VM_60_202_centos ~]#rpm -q tigervnc tigervnc-server
沒安裝的話會直接出現tcp
[root@VM_60_202_centos ~]#package tigervnc is not installed [root@VM_60_202_centos ~]#package tigervnc-server is not installed
二、若是沒有安裝X-Windows 桌面的話要先安裝Xwindows編輯器
[root@VM_60_202_centos ~]#yum check-update [root@VM_60_202_centos ~]#yum groupinstall "X Window System" [root@VM_60_202_centos ~]#yum install gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts [root@VM_60_202_centos ~]#unlink /etc/systemd/system/default.target [root@VM_60_202_centos ~]#ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target [root@VM_60_202_centos ~]#reboot
三、安裝VNC packages學習
[root@VM_60_202_centos ~]#yum install tigervnc-server -y
修改配置信息,在/etc/systemd/system/下創建文件夾vncserver@:1.service 把example config 文件從/lib/systemd/system/vncserver@.service複製到裏面rest
[root@VM_60_202_centos ~]#cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
而後打開這個配置文件/etc/systemd/system/vncserver@:1.service替換掉默認用戶名。找到這一行code
ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" PIDFile=/home/<USER>/.vnc/%H%i.pid
這裏我直接用root 用戶登陸,因此我替換成:
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i" PIDFile=/root/.vnc/%H%i.pid
若是是其餘用戶的話好比john替換以下:
ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" PIDFile=/home/<USER>/.vnc/%H%i.pid
重加載 systemd
[root@VM_60_202_centos ~]#systemctl daemon-reload --重加載 systemd [root@VM_60_202_centos ~]#vncpasswd --爲VNC設密碼
因爲我這邊的Centos 7 是用iptable防火牆的因此須要修改配置:
[root@VM_60_202_centos ~]#vim /etc/sysconfig/iptables --在iptables文件,合適位置加上 -A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT [root@VM_60_202_centos ~]#service iptables restart --重啓iptable
若是是用Centos 7 默認防火牆的可能須要
[root@VM_60_202_centos ~]#firewall-cmd --permanent --add-service vnc-server [root@VM_60_202_centos ~]#systemctl restart firewalld.service
設默認啓動並開啓VNC
[root@VM_60_202_centos ~]#systemctl enable vncserver@:1.service [root@VM_60_202_centos ~]#systemctl start vncserver@:1.service