Centos7安装完成后一些基本操作

时间:2021-08-25
本文章向大家介绍Centos7安装完成后一些基本操作,主要包括Centos7安装完成后一些基本操作使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.基本操作一:主机名

1
2
3
4
# centos7有一个新的修改主机名的命令hostnamectl
hostnamectl set-hostname --static www.node1.com
# 有些命令的参数可以自动补全,如果不能补全,则安装下面的命令
yum -y install bash-completion

2.基本操作二:关闭iptables

1
2
3
4
5
# 查看firewalld服务的状态,active是启动状态,inactive是关闭状态
systemctl status firewalld.service
systemctl stop firewalld.service
systemctl list-unit-files |grep firewalld   # 查看firewalld是否开机自动启动
systemctl disable firewalld.service  # 类似以前的chkconfig xxx off

3.基本操作三:关闭selinux

1
2
# 改完后,在后面重启系统生效
sed -i 7s/enforcing/disabled/  /etc/selinux/config

4.基本操作四:网络配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
systemctl stop NetworkManager
systemctl status NetworkManager
systemctl disable NetworkManager
vim /etc/sysconfig/network-scripts/ifcfg-enp2s0  # 网卡名如果不一样,找到对应的文件就行
BOOTPROTO="static"
NAME="enp2s0"
DEVICE="enp2s0"
ONBOOT="yes"
IPADDR=192.168.254.10
NETMASK=255.255.255.0
GATEWAY=192.168.254.2
DNS1=192.168.254.2
DNS1=223.5.5.5
# network服务这里默认还是可以使用原来的管理方法
/etc/init.d/network restart
chkconfig network on

5.基本操作五:yum配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
配置本地yum源
# 删除了它所有的默认的配置(因为这些默认配置要连公网的源,速度太慢)
rm -rf /etc/yum.repos.d/*
mkdir /media/cdrom
mount /dev/cdrom /media/cdrom
# 自建本地yum源配置文件
vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
 
yum-config-manager --enable local  # 也可以直接把上面的enabled改为1
yum repolist
 
配置可选163的centos源
配置方法两种
a)直接公网连接网易163,优点:速度快,软件包会定期更新
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
b)自己编写
# vim /etc/yum.repos.d/cento163.repo
[centos163]
name=centos163
baseurl=http://mirrors.163.com/centos/7.3.1611/os/x86_64
enabled=1
gpgcheck=0
 
配置可选epel源
配置方法两种
a)直接公网连接epel,优点:速度快,软件包会定期更新
# 此版本信息会随时间推移而变化
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm
rpm -ivh epel-release-7-10.noarch.rpm
b)自己编写
vim /etc/yum.repos.d/epel.repo
[epel]
name=epel
baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64
enabled=1
gpgcheck=0
配置完上面三个yum后
yum clean all
yum makecache fast

6.基本操作六:输入法配置(有需要再研究)

7.基本操作七:时间同步

1
2
3
4
5
6
7
8
9
10
11
12
13
yum -y install ntp  ntpdate
vim /etc/ntp.conf
# 确认配置文件里有下列的时间同步源
server 0.rhel.pool.ntp.org iburst
server 1.rhel.pool.ntp.org iburst
server 2.rhel.pool.ntp.org iburst
server 3.rhel.pool.ntp.org iburst
systemctl enable ntpd  # 设置开机自动启动ntpd
systemctl start ntpd   # 立即启动ntpd服务
ntpdate 0.rhel.pool.ntp.org  # 如果还没有同步成功,可以用此命令手动同步一下
# 设置默认启动级别为图形模式(相当于以前的5级别)
systemctl get-default  # 查看当前的运行模式
systemctl set-default graphical.target  # 设置图形模式为默认模式

原文地址:https://www.cnblogs.com/dachenyi/p/15184508.html