CentOS7.0小结
CentOS7设置静态IP地址
centos7的网络IP地址配置文件在 /etc/sysconfig/network-scripts 文件夹下查看网卡名称
[root@centos-vm ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:1c:42:0c:c6:af brd ff:ff:ff:ff:ff:ff
inet 192.168.103.200/24 brd 192.168.103.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::a974:b3c2:9460:16ce/64 scope link noprefixroute
valid_lft forever preferred_lft forever
eth0网卡对应的配置文件为ifcfg-eth0,使用vim编辑如下:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" # 使用静态IP地址,默认为dhcp
IPADDR="192.168.241.100" # 设置的静态IP地址
NETMASK="255.255.255.0" # 子网掩码
GATEWAY="192.168.241.2" # 网关地址
DNS1="192.168.241.2" # DNS服务器
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="95b614cd-79b0-4755-b08d-99f1cca7271b"
DEVICE="ens33"
ONBOOT="yes" #是否开机启用
然后使用service network restart命令即可配置静态IP地址
配置hostname的方法为
[root@centos-vm ~]# hostnamectl set-hostname centos-vm
[root@centos-vm ~]# hostnamectl
Static hostname: centos-vm
Icon name: computer-vm
Chassis: vm
Machine ID: 22c8eaae7705ad439af593d8d12ba6b0
Boot ID: faaec2d9520649c5a58b45a0aaa072c4
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
配置IP地址映射为
[root@centos-vm ~]# vim /etc/hosts
[root@centos-vm ~]# cat /etc/hosts
127.0.0.1 localhost
::1 localhost
192.168.103.200 centos-vm
Centos7 ssh配置RSA证书登录
修改sshd配置文件
[root@centos-vm ~]#vim /etc/ssh/sshd_config
#增加以下三项
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
在root目录下创建.ssh文件夹
[root@localhost /]# mkdir .ssh
在.ssh文件夹下创建authorized_keys文件
[root@localhost /]# cd .ssh
[root@localhost .ssh]# touch authorized_keys
写入秘钥
[root@localhost .ssh]# vim authorized_keys
修改authorized_keys执行权限
[root@localhost .ssh]# chmod 644 authorized_keys
重启ssh服务
[root@localhost .ssh]# systemctl restart sshd
CentOS 加载/挂载光驱
[root@localhost ~]#mkdir /mnt/cdrom
//挂载
[root@localhost ~]#mount /dev/cdrom /mnt/cdrom
//卸载
[root@localhost ~]#umount /dev/cdrom /mnt/cdrom
CentOS7 添加常用源
CentOS 的官方源去掉了一些与版权有关的软件,因此想要安装这些软件或者手动下载安装,或者使用其他源.
下面是添加EPEL源的步骤。
1.首先, 添加源之前要确定系统架构及版本
查看系统版本:
[root@centos-vm ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@centos-vm ~]# uname -r
3.10.0-1062.el7.x86_64
[root@centos-vm ~]# uname -a
Linux centos-vm 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
以看出来,系统版本是7.7.1908 架构是x86_64 64位的系统
2.查看当前CentOS7上已经有哪些源
[root@centos-vm ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.huaweicloud.com
* updates: mirrors.tuna.tsinghua.edu.cn
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base 10,097
extras/7/x86_64 CentOS-7 - Extras 307
updates/7/x86_64 CentOS-7 - Updates 1,010
repolist: 11,414
3.接下来,安装EPEL源
EPEL官网地址:https://fedoraproject.org/wiki/EPEL 点击中文简体
往下翻找到CentOS用户可以直接通过下面的命令安装并启用EPEL源。【需要root用户权限】
[root@centos-vm ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
4.安装完成之后,手动更新源,使之立即生效键入命令:
[root@centos-vm ~]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base epel extras updates
Cleaning up list of fastest mirrors
Other repos take up 1.5 M of disk space (use --verbose for details)
[root@centos-vm ~]# yum makecache
已加载插件:fastestmirror
Determining fastest mirrors
epel/x86_64/metalink | 9.3 kB 00:00:00
* base: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
base | 3.6 kB 00:00:00
epel | 5.3 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/16): base/7/x86_64/group_gz | 165 kB 00:00:00
(2/16): epel/x86_64/group_gz | 90 kB 00:00:00
(3/16): base/7/x86_64/primary_db | 6.0 MB 00:00:00
(4/16): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(5/16): epel/x86_64/prestodelta | 453 B 00:00:00
(6/16): base/7/x86_64/filelists_db | 7.3 MB 00:00:00
(7/16): epel/x86_64/filelists_db | 12 MB 00:00:00
(8/16): epel/x86_64/primary_db | 6.9 MB 00:00:00
(9/16): base/7/x86_64/other_db | 2.6 MB 00:00:01
(10/16): extras/7/x86_64/primary_db | 153 kB 00:00:00
(11/16): extras/7/x86_64/filelists_db | 207 kB 00:00:00
(12/16): extras/7/x86_64/other_db | 100 kB 00:00:00
(13/16): epel/x86_64/other_db | 3.3 MB 00:00:00
(14/16): updates/7/x86_64/other_db | 368 kB 00:00:00
(15/16): updates/7/x86_64/filelists_db | 3.3 MB 00:00:00
(16/16): updates/7/x86_64/primary_db | 5.9 MB 00:00:00
元数据缓存已建立
5.再查看源,EPEL已经安装成功
[root@centos-vm ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: mirror.bit.edu.cn
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base 10,097
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,509
extras/7/x86_64 CentOS-7 - Extras 307
updates/7/x86_64 CentOS-7 - Updates 1,010
repolist: 24,923