CentOS7基本设置
本文主要记录一些平时可能会碰到的CentOS7的基本设置。
系统环境设置
设置系统语言
安装操作系统的时候选择了中文,但是想把它改回英文的。通过修改用户目录下的.bashrc文件即可。
修改前系统环境如下:
[root@localhost ~]# echo $LANG zh_CN.UTF-8 [root@localhost ~]# chkconfig 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。 欲查看对特定 target 启用的服务请执行 'systemctl list-dependencies [target]'。 netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关 network 0:关 1:关 2:开 3:开 4:开 5:开 6:关 [root@localhost ~]# locale LANG=zh_CN.UTF-8 LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC="zh_CN.UTF-8" LC_TIME="zh_CN.UTF-8" LC_COLLATE="zh_CN.UTF-8" LC_MONETARY="zh_CN.UTF-8" LC_MESSAGES="zh_CN.UTF-8" LC_PAPER="zh_CN.UTF-8" LC_NAME="zh_CN.UTF-8" LC_ADDRESS="zh_CN.UTF-8" LC_TELEPHONE="zh_CN.UTF-8" LC_MEASUREMENT="zh_CN.UTF-8" LC_IDENTIFICATION="zh_CN.UTF-8" LC_ALL= [root@localhost ~]#
在.bashrc文件中添加如下环境设置:export LANG=en_US.UTF-8
修改后效果如下:
[root@localhost ~]# echo $LANG en_US.UTF-8 [root@localhost ~]# chkconfig Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@localhost ~]# locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= [root@localhost ~]#
设置网卡连接外网
CentOS7安装后,执行yum update命令发现失败了,看网络配置发现没有外网IP,enp0s3的IP地址没有:
[root@localhost network-scripts]# ifconfig enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 08:00:27:53:c7:e9 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.102 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:feb1:2da9 prefixlen 64 scopeid 0x20<link> ether 08:00:27:b1:2d:a9 txqueuelen 1000 (Ethernet) RX packets 905 bytes 79877 (78.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 583 bytes 83129 (81.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 676 bytes 58796 (57.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 676 bytes 58796 (57.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost network-scripts]#
进入目录:
/etc/sysconfig/network-scripts/
然后ls看一下,看到enp0s3对应的配置文件并查看:
[root@localhost network-scripts]# ls ifcfg-enp0s3 ifdown-isdn ifup ifup-plip ifup-tunnel ifcfg-lo ifdown-post ifup-aliases ifup-plusb ifup-wireless ifdown ifdown-ppp ifup-bnep ifup-post init.ipv6-global ifdown-bnep ifdown-routes ifup-eth ifup-ppp network-functions ifdown-eth ifdown-sit ifup-ib ifup-routes network-functions-ipv6 ifdown-ib ifdown-Team ifup-ippp ifup-sit ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort [root@localhost network-scripts]# more ifcfg-enp0s3 TYPE=Ethernet BOOTPROTO=dhcp DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=enp0s3 UUID=8e446c5c-9093-42da-8da7-328a0765dc83 DEVICE=enp0s3 ONBOOT=no [root@localhost network-scripts]#
将最后一行的配置由ONBOOT=no改为ONBOOT=yes。
[root@localhost network-scripts]# vim ifcfg-enp0s3 [root@localhost network-scripts]# more ifcfg-enp0s3 TYPE=Ethernet BOOTPROTO=dhcp DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=enp0s3 UUID=8e446c5c-9093-42da-8da7-328a0765dc83 DEVICE=enp0s3 ONBOOT=yes [root@localhost network-scripts]#
然后再重启网络。
[root@localhost network-scripts]# service network restart Restarting network (via systemctl): [ 确定 ] [root@localhost network-scripts]#
然后查看网络配置,并测试可以ping通外网。
[root@localhost network-scripts]# ifconfig enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:fe53:c7e9 prefixlen 64 scopeid 0x20<link> ether 08:00:27:53:c7:e9 txqueuelen 1000 (Ethernet) RX packets 31 bytes 4790 (4.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 44 bytes 4368 (4.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.102 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:feb1:2da9 prefixlen 64 scopeid 0x20<link> ether 08:00:27:b1:2d:a9 txqueuelen 1000 (Ethernet) RX packets 1173 bytes 102272 (99.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 747 bytes 108531 (105.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 820 bytes 71508 (69.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 820 bytes 71508 (69.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost network-scripts]# ping www.baidu.com PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data. 64 bytes from 61.135.169.125: icmp_seq=1 ttl=53 time=29.1 ms 64 bytes from 61.135.169.125: icmp_seq=2 ttl=53 time=26.6 ms 64 bytes from 61.135.169.125: icmp_seq=3 ttl=53 time=32.1 ms 64 bytes from 61.135.169.125: icmp_seq=4 ttl=53 time=39.5 ms ^C --- www.a.shifen.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3005ms rtt min/avg/max/mdev = 26.690/31.901/39.555/4.835 ms [root@localhost network-scripts]#