笔记:在CentOS上开始你的工作
基本设置
联网
CentOS安装后默认是不联网的,网卡处于down的状态,可以通过下面的步骤启动网卡。
# cd /etc/sysconfig/network-scripts
# ls ifcfg-* | grep -v ifcfg-lo
ifcfg-eno1
# ifup eno1
现在我们可以用过ip addr
命令来验证网卡的启动情况了。
然而,这个设置只是临时的,如果需要让CentOS每次启动时都会为我们自动启动这块网卡。我们可以修改/etc/sysconfig/network-scripts/ifcfg-eno1
配置文件,将其中的ONBOOT=no
改为ONBOOT=yes
来实现网卡的自动启动。
设置主机名
我们可以通过下面的命令完成对主机名的设置:
sudo hostname cheshi-desktop1.nay.redhat.com
sudo sh -c "echo cheshi-desktop1.nay.redhat.com > /etc/hostname"
重新打开终端窗口后就可以看到变化。
设置时区
我们可以使用下面的命令将系统时区设置为中国:
# ls -la /etc/localtime
lrwxrwxrwx. 1 root root 38 Jan 29 20:40 /etc/localtime -> ../usr/share/zoneinfo/America/New_York
# rm -f /etc/localtime
# ln -s ../usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# ls -la /etc/localtime
lrwxrwxrwx. 1 root root 35 Jan 31 15:27 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai
重启系统后新的时区设置就会生效。
创建用户
创建账户
添加一个名为cheshi
的用户,并为其设置密码:
# useradd cheshi
# passwd cheshi
删除账户
此外,删除一个名为cheshi
的用户,方法如下:
# userdel cheshi
userdel
命令的-r
参数用于同时删除用户的家目录,-f
参数用于强制删除一个正在登录的用户。
设置为sudoer
使用visudoer
命令,打开/etc/sudoers
配置文件,找到名为root
的用户,并在其下方添加新用户,保存后这个用户就具有了sudo权限。
更改后的配置文件大约会是这个样子:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
cheshi ALL=(ALL) ALL
配置VNC
安装GUI界面
首先我们需要安装桌面环境,也就是GUI界面,它是VNC的基础,而默认最小安装的CentOS是不带GUI界面的。
但我们可以通过下面的命令来安装GNOME桌面环境:
# yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
安装大概需要下载600MB左右的文件。
参考文献:http://www.linuxidc.com/Linux/2017-03/141465.htm
安装VNC Server
通过下面的命令安装VNC Server:
$ sudo yum install tigervnc-server
配置VNC
配置VNC有两种方法,一种是通过vncserver
命令直接启动,这个方法简单直接,另一种是通过systemctl
来启动VNC服务,这个方法可以自动启动VNC。
实测第二种方法启动后的界面有些问题,无法正常使用,因此这里只介绍第一种方法。
有关这个问题的bug可以参见:https://github.com/TigerVNC/tigervnc/issues/577
首先使用vncpasswd
命令设置VNC密码,然后使用vncserver
命令创建VNC桌面。一个VNC桌面对应一个VNC Server进程,也对应一个端口号。使用的时候通过在客户端指定不同的端口号,连接不同的VNC桌面。
$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:$ vncserverNew 'dhcp-15-173.nay.redhat.com:1 (cheshi)' desktop is dhcp-15-173.nay.redhat.com:1Starting applications specified in /home/cheshi/.vnc/xstartup
Log file is /home/cheshi/.vnc/dhcp-15-173.nay.redhat.com:1.log
首次运行vncserver
命令,将会产生一个端口号为1的桌面(这个端口号是VNC虚拟的端口号,一般来说与真实的物理端口号相差5900,后面还会说到)。
设置防火墙
由于使用第一种方法,所以VNC Server并没有对应的服务用于添加到防火墙的白名单里。所以我们可以找到VNC Server对应的端口,然后将其添加到防火墙的白名单,以达到相同的目的。
通过netstat -anotl
命令或nmap
命令(可通过sudo yum install nmap
命令安装),可以得到VNC桌面的对应端口号:
$ nmap localhostStarting Nmap 6.40 ( http://nmap.org ) at 2018-01-29 22:23 EST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00063s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 994 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
111/tcp open rpcbind
631/tcp open ipp
5901/tcp open vnc-1
6001/tcp open X11:1Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
接下来我们把对应的端口号5901/tcp
加入到防火墙的白名单中:
$ sudo firewall-cmd --get-zones
block dmz drop external home internal public trusted work
$ sudo firewall-cmd --get-default-zone
public
$ sudo firewall-cmd --add-port=5901/tcp
success
连接VNC
通过另外一台计算机上的VNC Viewer或者Remmina一类的软件,连接我们前面配置好的VNC Server即可。
连接时直接指定VNC Server上的虚拟端口号即可,例如:vncviewer 10.0.0.1:1
重新配置VNC桌面
验证过VNC一切正常后,下面就可以精心设置自己的VNC桌面了。为了避免资源浪费,我们首先需要刚才建立的VNC桌面:
$ vncserver -kill :1
Killing Xvnc process ID 3064
然后我们更改一下VNC桌面的配置。经过刚才的步骤,VNC应该已经为我们自动创建好了配置文件,它的位置应该是~/.vnc/config
。我们需要向其中写入默认的桌面大小,将geometry=1920x1080
加入到配置文件中,这样当我们没有通过vncserver
命令指定桌面大小时,VNC就会使用这个默认值。
可选的配置还有很多,这里就不再赘述。接下来,我们重新启动刚才的桌面,这次我们可以通过指定端口号的方式,启动一个VNC桌面:
$ vncserver :1New 'dhcp-15-173.nay.redhat.com:1 (cheshi)' desktop is dhcp-15-173.nay.redhat.com:1Starting applications specified in /home/cheshi/.vnc/xstartup
Log file is /home/cheshi/.vnc/dhcp-15-173.nay.redhat.com:1.log
再次登录这个桌面,应该就会看到效果。
高级设置
使用ZSH
安装ZSH
ZSH就是”Z Shell”,最小化安装的CentOS并不带有这个shell,这一点可以通过zsh --version
来验证。它的安装方法也很简单:
$ sudo yum install zsh
参考文献: https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH
配置ZSH
第一次运行时,ZSH会提示我们进行配置,所有的配置信息都会被保存到~/.zshrc
中,但是由于一会儿我们要使用”Oh My Zsh”的模板覆盖这个配置文件,因此这里我们选择”0”以跳过设置。
$ zshThis is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.You can:(q) Quit and do nothing. The function will be run again next time.(0) Exit, creating the file ~/.zshrc containing just a comment.That will prevent this function being run again.(1) Continue to the main menu.--- Type one of the keys in parentheses ---
如果想要设置ZSH为当前用户默认的Shell,可以执行chsh -s $(which zsh)
这条命令。
使用”Oh My Zsh”
“Oh My Zsh”是一个开源项目,它提供了很多ZSH的主题,使得ZSH更加强大并易于使用。它的全部代码和文档都可以在GitHub上找到。
安装”Oh My Zsh”最便捷的方式是执行官方提供的install.sh
,不过在此之前我们需要执行sudo yum install -y git
,来安装脚本所需的git
命令。
接下来,我们就可以开始安装”Oh My Zsh”了:
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Cloning Oh My Zsh...
Cloning into '/home/cheshi/.oh-my-zsh'...
remote: Counting objects: 849, done.
remote: Compressing objects: 100% (713/713), done.
remote: Total 849 (delta 16), reused 769 (delta 10), pack-reused 0
Receiving objects: 100% (849/849), 578.52 KiB | 181.00 KiB/s, done.
Resolving deltas: 100% (16/16), done.
Looking for an existing zsh config...
Found ~/.zshrc. Backing up to ~/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to ~/.zshrc
Time to change your default shell to zsh!
Changing shell for cheshi.
Password:
Shell changed.__ __ ____ / /_ ____ ___ __ __ ____ _____/ /_ / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ /____/ ....is now installed!Please look over the ~/.zshrc file to select plugins, themes, and options.p.s. Follow us at https://twitter.com/ohmyzsh.p.p.s. Get stickers and t-shirts at https://shop.planetargon.com.→ ~
执行下面的命令以更改主题为”agnoster”,这是一款很酷的主题:
$ sed -i 's/^ZSH_THEME=.*/ZSH_THEME="agnoster"/' ~/.zshrc
当你下次进入ZSH的时候,可能会发现它变得一团糟,这是因为你还没有安装主题所需的字体,以及更改终端颜色。
为了配合ZSH的大部分主题,我们需要安装Power Line字体。安装的命令如下:
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts && ./install.sh
cd .. && rm -rf fonts
接下来,我们要设置终端的颜色,步骤略微有点复杂:
1. 点击终端窗口菜单栏上的”Edit” > “Preferences”
2. 翻到”Profiles”选项卡,并点击”Clone”按钮
3. 在”General”选项中更改”Profile name”为自己喜欢的名字,例如”Profile for Zsh”
4. 勾选”Custom font”并将字体设置为”Monospace Regular - 11pt”(或者是”Noto Mono for Powerline Regular - 12pt”以及其他你喜欢的字体,只要显示没有乱码即可)
5. 翻到”Colors”选项卡,取消勾选”Use colors from system theme”,并更改”Built-in schemes”为”Solarized dark”
8. 在下面设置”Palette”的地方,更改”Built-in schemes”为”Solarized”
9. 点击最下面的”Close”按钮完成设置
10. 回到之前的窗口,将”Profile used when launching a new terminal”选为刚刚创建的Profile
11. 点击最下面的”Close”按钮完成设置
现在,重新打开新的终端,就可以看到效果了。
提示:重启系统或VNC桌面后,ZSH将变为当前用户的默认Shell。
“Oh My Zsh”官方文档:https://github.com/robbyrussell/oh-my-zsh/blob/master/README.md
使用EPEL
首先找到最新的EPEL安装包,CentOS7对应的安装包位于http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/
下,我们可以通过下面的命令进行安装:
$ wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
$ sudo rpm -ivh epel-release-7-11.noarch.rpm
$ sudo yum-config-manager epel
常用工具
JSON分析工具 - jq
sudo yum install -y jq
笔记:在CentOS上开始你的工作相关推荐
- 在CentOS上把MySQL从5.5升级到5.6
在CentOS上把MySQL从5.5升级到5.6 摘要:本文记录了在CentOS 6.3上,把MySQL从5.5.28升级到5.6.19的过程. 1. 概述 在我做的一个项目中,最近我对生产服务器上的 ...
- 如何在Ubuntu/CentOS上安装Linux内核4.0
如何在Ubuntu/CentOS上安装Linux内核4.0 大家好,今天我们学习一下如何从Elrepo或者源代码来安装最新的Linux内核4.0.代号为'Hurr durr I'm a sheep'的 ...
- centos 上 crontab 计划任务 ,这个版本解释的比较清晰
这个版本的crontab命令解释的很详细 yum install vixie-cronyum install crontabs/bin/systemctl restart crond.service ...
- 在CentOS上使用Jexus托管运行 ZKEACMS
ZKEACMS Core 是基于 .net core 开发的,可以在 windows, linux, mac 上跨平台运行,接下来我们来看看如何在 CentOS 上使用Jexus托管运行 ZKEACM ...
- 如何在CentOS上设置MariaDB Galera Cluster 10.0
原作者:Jijo 转载:https://www.unixmen.com/setup-mariadb-galera-cluster-10-0-centos/ 如何在CentOS上设置MariaDB G ...
- 在CentOS上配置Percona XtraDB集群(Percona XtraDB Cluster)
原作者:Percona官网 翻译&转载来源:https://www.percona.com/doc/percona-xtradb-cluster/LATEST/howtos/centos_ho ...
- 升级php5.4 mysql5.5_在CentOS上把PHP从5.4升级到5.5
在CentOS上把PHP从5.4升级到5.5 摘要:本文记录了在CentOS 6.3上,把PHP从5.4.8升级到5.5.13的过程. 1. 概述 在我做的一个项目中,最近我对生产服务器上的一系列系统 ...
- 在CentOS上进行虚拟化:QEMU、Xen、KVM、LibVirt、oVirt
Table of Contents 在CentOS上进行虚拟化 1.概述 2.谁做什么? 3. CentOS支持 3.1 CentOS的4 3.2 CentOS的5 Xen4 CentOS快速入门 0 ...
- java与tomcat,Centos上安装配置java和tomcat
java java版本 1:配置环境变量 centos中配置环境变量稍有不同,要了解centos中如何配置环境变量首先需要理解一下几个简要的概念 * /etc/profile 和 /etc/pro ...
最新文章
- 两成开发者月薪超 1.7 万、算法工程师最紧缺! | 中国开发者年度报告
- 5个找出Linux中“二进制命令”描述和系统中位置的方法
- VS2015 Cordova实现WebView加载页面进度条(Android)
- Keras【Deep Learning With Python】机器学习和线性回归
- libevent源码学习-----统一事件源及信号绑定函数
- CSS中list-style详解
- ABAP,Java, nodejs和go语言的web server编程
- Tensor数据相关的运算、函数讲解及与numpy区别
- 数学猜想验证步骤_高中数学解题思路与技巧汇总,19种解题方法,实用!
- 不同网段通过静态路由实现互通(强烈推荐)
- MongoDB 教程三: 高级查询 (SQL到MongoDB映射表)
- HDU2174 kiki's game(博弈)
- 活动目录的介绍:深入浅出Active Directory系列(一)
- Java并发(基础知识)—— 创建、运行以及停止一个线程
- [洛谷P3292][SCOI2016]幸运数字
- pcie link/lane number negotiation
- 计算机管理格式化硬盘,细说电脑怎么格式化硬盘
- python绘制彩色地震剖面断层解释_地震剖面上断层的识别标志主要有哪些
- 小麦苗的常用代码--常用命令(仅限自己使用)--下
- 碱基数据处理中的算法研究
热门文章
- 智能网联先导区道路交叉口车路协同系统设计
- Redis分布式锁-这一篇全了解(Redission实现分布式锁完美方案)
- hive 正则表达式-regexp
- java的 I/O 输入输出流详解
- uniApp学习(8)搜索框的创建和自动获取焦点
- Django框架实现在线考试系统
- 【论文笔记】End-to-end people detection in crowded scenes
- 谈谈分布式服务治理框架 Dubbo 重大升级
- 私服服务器刷怪文件叫什么,《奇迹》关于刷怪文件Monstersetbase.txt的简单说明
- 大学生应该常去的网站