Linux桌面环境安装与系统配置

snow chuai汇总、整理、撰写---2020/2/25


1. GNOME
1) 安装GNOME
[root@node1 ~]# yum groups install "GNOME Desktop" -y
2) 临时为GUI启动级别 [root@srv1 ~]# systemctl isolate graphical.target
3) 永久切换为GUI启动级别 [root@srv1 ~]# systemctl set-default graphical.target
4) 永久切换为CLI启动级别 [root@srv1 ~]# systemctl set-default multi-user.target
2. CLI下启动GNOME
1) 命令启动
[root@node1 ~]# echo "exec gnome-session" >> ~/.xinitrc
[root@node1 ~]# startx
2) GUI [Sign In]==>点击齿轮====>选择[GNOME]
3. KDE
1) 安装GNOME
[root@node1 ~]# yum groups install "KDE Plasma Workspaces" -y
2) 临时为GUI启动级别 [root@srv1 ~]# systemctl isolate graphical.target
3) 永久切换为GUI启动级别 [root@srv1 ~]# systemctl set-default graphical.target
4) 永久切换为CLI启动级别 [root@srv1 ~]# systemctl set-default multi-user.target
4. Cinnamon
1) 安装GNOME
[root@node1 ~]# yum groups install "Server with GUI" -y
[root@node1 ~]# yum --enablerepo=epel install cinnamon* -y
2) 临时为GUI启动级别 [root@srv1 ~]# systemctl isolate graphical.target
3) 永久切换为GUI启动级别 [root@srv1 ~]# systemctl set-default graphical.target
4) 永久切换为CLI启动级别 [root@srv1 ~]# systemctl set-default multi-user.target
5. MATE
1) 安装GNOME
[root@node1 ~]# yum groups install "Server with GUI" -y
[root@node1 ~]# yum --enablerepo=epel groups install "MATE Desktop" -y
2) 临时为GUI启动级别 [root@srv1 ~]# systemctl isolate graphical.target
3) 永久切换为GUI启动级别 [root@srv1 ~]# systemctl set-default graphical.target
4) 永久切换为CLI启动级别 [root@srv1 ~]# systemctl set-default multi-user.target
6. XFCE
1) 安装GNOME
[root@node1 ~]# yum groups install "Server with GUI" -y
[root@node1 ~]# yum --enablerepo=epel groups install "Xfce" -y
2) 临时为GUI启动级别 [root@srv1 ~]# systemctl isolate graphical.target
3) 永久切换为GUI启动级别 [root@srv1 ~]# systemctl set-default graphical.target
4) 永久切换为CLI启动级别 [root@srv1 ~]# systemctl set-default multi-user.target
7. 设置系统语言
1) 显示当前状态
[root@node1 ~]# localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: us
2) 显示所支持的语言 [root@node1 ~]# localectl list-locales aa_DJ aa_DJ.iso88591 aa_DJ.utf8 aa_ER aa_ER.utf8 aa_ER.utf8@saaho aa_ER@saaho ... ... ... zh_CM.utf8 ... ... ... zh_TW.big5 zh_TW.euctw zh_TW.utf8 zu_ZA zu_ZA.iso88591 zu_ZA.utf8
3) 设置语言 [root@node1 ~]# localectl set-locale LANG=zh_CN.UTF-8 [root@node1 ~]# localectl
8. 设置键盘
1) 显示当前设置
[root@srv1 ~]# localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: us
2) 显示keymaps列表 [root@srv1 ~]# localectl list-keymaps ...... ...... us-dvp us-euro us-hbs us-intl us-mac us-olpc2 us-workman us-workman-intl uz-latin wangbe wangbe2 windowkeys
3) 更改keymaps [root@srv1 ~]# localectl set-keymap cn [root@srv1 ~]# localectl System Locale: LANG=en_US.UTF-8 VC Keymap: cn X11 Layout: us
9. 设置主机名
1) 显示当前主机名
[root@srv1 ~]# hostname
srv1.1000cc.net
2) 更改主机名 [root@srv1 ~]# hostnamectl set-hostname qyy.1000cc.net [root@srv1 ~]# hostname qyy.1000cc.net
3) 查看主机信息 [root@srv1 ~]# hostnamectl Static hostname: qyy.1000cc.net Icon name: computer-vm Chassis: vm Machine ID: def4f43c7d564c5ebc4cc2a3c272df8d Boot ID: c95537e03ead46609c04ca4b439c7a04 Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-1062.el7.x86_64 Architecture: x86-64
10. 时区设置
1) 显示时区列表
[root@srv1 ~]# timedatectl list-timezones
......
......
Asia/Shanghai
......
......
2) 更改时区 [root@srv1 ~]# timedatectl set-timezone Asia/Shanghai
[root@srv1 ~]# timedatectl Local time: Thu 2020-02-27 23:32:45 CST Universal time: Thu 2020-02-27 15:32:45 UTC RTC time: Thu 2020-02-27 15:32:44 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a
11. 添加第三方repo
1) 安装优先级插件
[root@srv1 ~]# yum install yum-plugin-priorities -y
# 设定CentOS-Base源为最高优先级[1为最高,99为最低]
[root@srv1 ~]# sed -i -e "s/\]$/\]\npriority=1/g" /etc/yum.repos.d/CentOS-Base.repo
2) 添加EPEL源 [root@srv1 ~]# yum install epel-release -y
# 设定epel源优先级为5[1为最高,99为最低] [root@srv1 ~]# sed -i -e "s/\]$/\]\npriority=5/g" /etc/yum.repos.d/epel.repo
# 关闭epel源 [root@srv1 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo
# 临时启用epel源 [root@srv1 ~]# yum --enablerepo=epel install [Package]
3) 添加CentOS SCLo源 [root@srv1 ~]# yum install centos-release-scl-rh centos-release-scl -y
[root@srv1 ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo [root@srv1 ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
[root@srv1 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo [root@srv1 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
[root@srv1 ~]# yum --enablerepo=centos-sclo-rh install [Package] [root@srv1 ~]# yum --enablerepo=centos-sclo-sclo install [Package]
4) 添加Remi源 [root@srv1 ~]# yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm -y
[root@srv1 ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/remi-safe.repo [root@srv1 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/remi-safe.repo
[root@srv1 ~]# yum --enablerepo=remi-safe install [Package]
5) 添加elrepo源 [root@srv1 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@srv1 ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
[root@srv1 ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/elrepo.repo [root@srv1 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/elrepo.repo
[root@srv1 ~]# yum --enablerepo=elrepo install [Package]
12. 更新CentOS Kernel
1) 查看现有的内核版本(需elrepo源)
[root@srv1 ~]# yum --disablerepo="*" --enablerepo=elrepo-kernel list available
已加载插件:fastestmirror, priorities
Loading mirror speeds from cached hostfile
可安装的软件包
# lt为长期支持版,ml为当前稳定版
elrepo-release.noarch                7.0-4.el7.elrepo        elrepo-kernel
kernel-lt.x86_64                     4.4.214-1.el7.elrepo    elrepo-kernel
kernel-lt-devel.x86_64               4.4.214-1.el7.elrepo    elrepo-kernel
kernel-lt-doc.noarch                 4.4.214-1.el7.elrepo    elrepo-kernel
kernel-lt-headers.x86_64             4.4.214-1.el7.elrepo    elrepo-kernel
kernel-lt-tools.x86_64               4.4.214-1.el7.elrepo    elrepo-kernel
kernel-lt-tools-libs.x86_64          4.4.214-1.el7.elrepo    elrepo-kernel
kernel-lt-tools-libs-devel.x86_64    4.4.214-1.el7.elrepo    elrepo-kernel
kernel-ml.x86_64                     5.5.6-2.el7.elrepo      elrepo-kernel
kernel-ml-devel.x86_64               5.5.6-2.el7.elrepo      elrepo-kernel
kernel-ml-doc.noarch                 5.5.6-2.el7.elrepo      elrepo-kernel
kernel-ml-headers.x86_64             5.5.6-2.el7.elrepo      elrepo-kernel
kernel-ml-tools.x86_64               5.5.6-2.el7.elrepo      elrepo-kernel
kernel-ml-tools-libs.x86_64          5.5.6-2.el7.elrepo      elrepo-kernel
kernel-ml-tools-libs-devel.x86_64    5.5.6-2.el7.elrepo      elrepo-kernel
perf.x86_64                          5.5.6-2.el7.elrepo      elrepo-kernel
python-perf.x86_64                   5.5.6-2.el7.elrepo      elrepo-kernel
2) 安装所需要的内核版本 [root@srv1 ~]# yum --enablerepo=elrepo-kernel install kernel-lt -y

[root@srv1 ~]# yum --enablerepo=elrepo-kernel install kernel-ml -y
3) 查看系统上可用的kernel [root@csrv ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.5.6-2.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (4.4.214-1.el7.elrepo.x86_64) 7 (Core) 2 : CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core) 3 : CentOS Linux (0-rescue-bbfd63df71dd421d8b89e22811d8d4de) 7 (Core)
4) 选择默认启动的kenrel [root@csrv ~]# grub2-set-default 0
5) 重新生成grub.cfg [root@srv1 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-5.5.6-2.el7.elrepo.x86_64 Found initrd image: /boot/initramfs-5.5.6-2.el7.elrepo.x86_64.img Found linux image: /boot/vmlinuz-4.4.214-1.el7.elrepo.x86_64 Found initrd image: /boot/initramfs-4.4.214-1.el7.elrepo.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-1062.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-1062.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-bbfd63df71dd421d8b89e22811d8d4de Found initrd image: /boot/initramfs-0-rescue-bbfd63df71dd421d8b89e22811d8d4de.img done
6) 重启系统 [root@srv1 ~]# reboot
13. CentOS6及CentOS7发行版发型时间
1. CentOS6发行版发型时间
6.0  ===> 2011.07
6.1  ===> 2011.12
6.2  ===> 2011.12
6.3  ===> 2012.06
6.4  ===> 2013.03
6.5  ===> 2013.12
6.6  ===> 2014.10
6.7  ===> 2015.08
6.8  ===> 2016.05
6.9  ===> 2017.04
6.10 ===> 2018.07
2. CentOS7发行版发型时间
7.0.1406 ===> 2014.06
7.1.1503 ===> 2015.03
7.2.1511 ===> 2015.11
7.3.1611 ===> 2016.11
7.4.1708 ===> 2017.08
7.5.1804 ===> 2018.04
7.6.1810 ===> 2018.10
7.7.1908 ===> 2019.08
7.8.2003 ===> 2020.03 ===> 实际发布时间: 2020.04
7.9.2009 ===> 2020.09 ===> 实际发布时间: 2020.11
14. 设置本地YUM源
1. 基于ISO的本地源
1) 将CentOS系统的ISO复制到本地
2) 挂载ISO
[root@srv1 ~]# mkdir -v /mnt/cdrom [root@srv1 ~]# mount /iso/c7.iso /mnt/cdrom -o loop
3) 将客户端的repos源地址改为本地服务器地址(并注释掉mirrorlist字段,取消baseurl字段的注释) [root@client ~]# vi /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra baseurl=file:///mnt/cdrom gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
2. 同步远程YUM源至本地
1) 安装必要的同步工具
[root@srv1 ~]# yum install rsync createrepo -y
2) 创建本地的同步目录(repos目录) [root@srv1 ~]# mkdir -p /var/www/repos/centos/7/{os,updates,extras}/x86_64 [root@srv1 ~]# chmod -R 755 /var/www/repos
3) 将远程repos同步至本地 # 语法详见rsync服务 # --exclude参数为指定排除(不同步)的目录或文件 # 远程所同步的源为清华大学开源软件镜像站
[root@srv1 ~]# rsync -avz --delete --exclude='repodata' \ rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/ \ /var/www/repos/centos/7/os/x86_64/
[root@srv1 ~]# rsync -avz --delete --exclude='repodata' \ rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/ \ /var/www/repos/centos/7/updates/x86_64/
[root@srv1 ~]# rsync -avz --delete --exclude='repodata' \ rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/x86_64/ \ /var/www/repos/centos/7/extras/x86_64/
4) 创建repodate [root@srv1 ~]# createrepo /var/www/repos/centos/7/os/x86_64/ [root@srv1 ~]# createrepo /var/www/repos/centos/7/updates/x86_64/ [root@srv1 ~]# createrepo /var/www/repos/centos/7/extras/x86_64/
5) 自动每日同步更新 [root@srv1 ~]# vim /etc/cron.daily/update-repo #!/bin/bash
VER='7' ARCH='x86_64' REPOS=(os updates extras)
for REPO in ${REPOS[@]} do rsync -avz --delete --exclude='repodata' \ rsync://mirrors.tuna.tsinghua.edu.cn/centos/${VER}/${REPO}/${ARCH}/ /var/www/repos/centos/${VER}/${REPO}/${ARCH}/ createrepo /var/www/repos/centos/${VER}/${REPO}/${ARCH}/ done

[root@srv1 ~]# chmod 755 /etc/cron.daily/update-repo
6) 启动web服务,以支持yum源
7) 将客户端的repos源地址改为本地服务器地址(并注释掉mirrorlist字段,取消baseurl字段的注释) [root@client ~]# vim /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra baseurl=http://srv1.1000cc.net.cn/repos/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates] name=CentOS-$releasever - Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra baseurl=http://srv1.1000cc.net.cn/repos/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras] name=CentOS-$releasever - Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra baseurl=http://srv1.1000cc.net.cn/repos/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
15. 安装NVIDAI显卡驱动
1) 如果在GUI图形界面,请切换到CLI界面
2) 关闭nouveau驱动 [root@srv1 ~]# lsmod | grep nouveau nouveau 2187264 1 video 45056 1 nouveau mxm_wmi 16384 1 nouveau wmi 32768 2 mxm_wmi,nouveau i2c_algo_bit 16384 1 nouveau drm_kms_helper 200704 1 nouveau ttm 131072 1 nouveau drm 520192 4 drm_kms_helper,ttm,nouveau
[root@srv1 ~]# vim /etc/modprobe.d/blacklist-nouveau.conf ...... ...... ...... ...... ...... ......
# 于文件最后添加如下内容(如果文件不存在,则新建即可) blacklist nouveau options nouveau modeset=0
[root@srv1 ~]# dracut --force [root@srv1 ~]# reboot
3) 安装一些必要的软件 [root@srv1 ~]# yum install kernel-devel-$(uname -r) kernel-header-$(uname -r) gcc make -y
4) 下载NVIDAI驱动 https://www.nvidia.com/Download/index.aspx?lang=cn
5) 检查显卡被设备所认出 [root@srv1 ~]# lspci | grep VGA 05:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1070] (rev a1)
6) 安装显卡驱动 [root@srv1 ~]# bash bash NVIDIA-Linux-x86_64-384.111.run Verifying archive integrity... OK Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.111
...... ...... 选择Accept Accept Do Not Accept
..... .....
Install NVIDIA's 32-bit compatibility libraries? 选择Yes Yes No
Would you like to run the nvidia-xconfig utility to automatically update your X configuration file so that the NVIDIA X driver will be used when you restart X? Any pre-existing X configuration file will be backed up. 选择Yes Yes No
Installation of the NVIDIA Accelerated Graphics Driver for Linux-x86_64 (version: 384.111) is now complete. Please update your xorg.conf file as appropriate; see the file /usr/share/doc/NVIDIA_GLX-1.0/README.txt for details.

OK
7) 确认 [root@srv1 ~]# nvidia-smi Sun Jul 26 23:14:45 2020 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 384.111 Driver Version: 430.50 CUDA Version: 10.1 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 1070 Off | 00000000:05:00.0 Off | N/A | | 27% 37C P5 12W / 180W | 0MiB / 8119MiB | 2% Default | +-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+
16. 使用snappy管理软件包
1) 安装snappy
[root@srv1 ~]# yum install epel-release -y
[root@srv1 ~]# yum install yum-plugin-copr -y
[root@srv1 ~]# yum copr enable ngompa/snapcore-el7
[root@srv1 ~]# yum install snapd -y
[root@srv1 ~]# ln -s /var/lib/snapd/snap /snap [root@srv1 ~]# echo 'export PATH=$PATH:/var/lib/snapd/snap/bin' > /etc/profile.d/snap.sh [root@srv1 ~]# systemctl enable --now snapd.socket
2) 基础使用 # 显示已安装的软件包 [root@srv1 ~]# snap list No snaps are installed yet. Try 'snap install hello-world'.
# 查找软件包 [root@srv1 ~]# snap find kubernetes Name Version Publisher Notes Summary microk8s v1.18.6 canonical classic Lightweight Kubernetes for workstations and appliances kata-containers 1.11.2 katacontainers classic Lightweight virtual machines that seamlessly plug into the containers ecosystem doctl v1.46.0 digitalocean - The official DigitalOcean command line interface kubectl 1.18.6 canonical classic Command line client for controlling a Kubernetes cluster. ..... .....
3) 安装软件包 [root@srv1 ~]# snap install hello-world 2020-07-13T18:24:08+08:00 INFO Waiting for automatic snapd restart... hello-world 6.4 from Canonical installed
[root@srv1 ~]# snap list Name Version Rev Tracking Publisher Notes core 16-2.45.2 9665 latest/stable canonical core hello-world 6.4 29 latest/stable canonical -
4) 显示软件包信息 [root@srv1 ~]# snap info hello-world name: hello-world summary: The 'hello-world' of snaps publisher: Canonical store-url: https://snapcraft.io/hello-world contact: snappy-devel@lists.ubuntu.com license: unset description: | This is a simple hello world example. commands: - hello-world.env - hello-world.evil - hello-world - hello-world.sh snap-id: buPKUD3TKqCOgLEjjHx5kSiCpIs5cMuQ tracking: latest/stable refresh-date: today at 16:23 JST channels: latest/stable: 6.4 2019-04-17 (29) 20kB - latest/candidate: 6.4 2019-04-17 (29) 20kB - latest/beta: 6.4 2019-04-17 (29) 20kB - latest/edge: 6.4 2019-04-17 (29) 20kB - installed: 6.4 (29) 20kB -
5) 运行应用程序 [root@srv1 ~]# hello-world Hello World!
6) 显示应用程序所在路径 [root@srv1 ~]# which hello-world /var/lib/snapd/snap/bin/hello-world
[root@srv1 ~]# ll /var/lib/snapd/snap/bin/hello-world lrwxrwxrwx. 1 root root 13 Jul 13 18:30 /var/lib/snapd/snap/bin/hello-world -> /usr/bin/snap
7) 关闭应用程序 [root@srv1 ~]# snap disable hello-world hello-world disabled
[root@srv1 ~]# snap list Name Version Rev Tracking Publisher Notes core 16-2.45.2 9665 latest/stable canonical core hello-world 6.4 29 latest/stable canonical disabled
[root@srv1 ~]# hello-world -bash: /var/lib/snapd/snap/bin/hello-world: No such file or directory
8) 开启应用程序 [root@srv1 ~]# snap enable hello-world hello-world enabled
[root@srv1 ~]# hello-world Hello World!
9) 卸载应用程序(需要tar命令。如tarm命令不存在请自行安装) [root@srv1 ~]# snap remove hello-world hello-world removed
[root@srv1 ~]# snap list Name Version Rev Tracking Publisher Notes core 16-2.45.2 9665 latest/stable canonical core

 

如对您有帮助,请随缘打个赏。^-^

gold