预计阅读时间:15分钟
预计配置时间:30分钟 (前提是已经申请AWS的EC2的rhel7 云主机并且成功运行)
目前AWS 亚马逊云免费试用一年,申请一个学习使用
痛点:没有GUI,无法搭建Jenkins 平台,只能terminal 访问
踩过的坑:
1.由于需求设计(坑爹?)亚马逊的Amazon Linux AMI release 2017.03 不支持任何桌面版的安装!
详细解释在:http://stackoverflow.com/questions/21908912/amazon-ec2-ami-install-gnome-kde-or-any-other-x
2.需要配置安全组策略才能ping、vnc访问EC2机器
[EC2 端的操作]
远程连接EC2,XX-XX-XX-XX 为机器的IP,以EC2控制台为准
$ ssh -i "test.pem" [email protected] 更新包,安装桌面
$ sudo yum update -y
$ sudo yum groupinstall "X Window System" "Desktop"
$ sudo yum -y groupinstall gnome $ rpm -qa |grep -i desktop
gsettings-desktop-schemas-3.14.2-1.el7.x86_64
gnome-desktop3-3.14.2-2.el7.x86_64
desktop-file-utils-0.22-1.el7.x86_64
sound-theme-freedesktop-0.8-3.el7.noarch
abrt-desktop-2.1.11-45.el7.x86_64 安装vnc,添加用户
$ sudo yum install vnc-server
$ sudo useradd awsgui
$ sudo passwd awsgui
$ vncpasswd
$ cd .vnc
$ ls
$ cat passwd
$ rpm -qa |grep -i vnc
tigervnc-server-minimal-1.3.1-9.el7.x86_64
gtk-vnc2-0.5.2-7.el7.x86_64
tigervnc-license-1.3.1-9.el7.noarch
gvnc-0.5.2-7.el7.x86_64
tigervnc-server-1.3.1-9.el7.x86_64 修改vncservers 配置文件,添加用户awsgui的相关配置
$ sudo vi /etc/sysconfig/vncservers
$ sudo cat /etc/sysconfig/vncservers
# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/[email protected]
VNCSERVERS="1:awsgui"
VNCSERVERARGS[1]="-geometry 1024x768" 修改xstartup配置文件,注释掉最后一行并且添加配置如下:
$ sudo vi /home/ec2-user/.vnc/xstartup
$ cat /home/ec2-user/.vnc/xstartup
#!/bin/sh unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
#exec /etc/X11/xinit/xinitrc
exec gnome-session & 启动vncserver服务
$ vncserver New 'ip-XX-XX-XX-XX.us-west-2.compute.internal:1 (ec2-user)' desktop is ip-XX-XX-XX-XX.us-west-2.compute.internal:1 Starting applications specified in /home/ec2-user/.vnc/xstartup
Log file is /home/ec2-user/.vnc/ip-XX-XX-XX-XX.us-west-2.compute.internal:1.log [Windows端的操作]
1.修改控制台EC2机器的安全组,允许本机IP访问远程EC2主机 (可以参考http://gloriasilveira.com/installing-a-gui-on-an-ec2-rhel-7-instance.html)
2. 安装VNC viewer: https://www.realvnc.com/download/viewer/
3. 启动VNC viewer进行连接: <your IP>:5902
大功告成
参考文档:https://forums.aws.amazon.com/message.jspa?messageID=304630
http://gloriasilveira.com/installing-a-gui-on-an-ec2-rhel-7-instance.html