Centos reset hostname
修改/etc/hostname文件,将包含当前的hostname改为新的hostname。
关闭Selinux
查看SELinux状态: /usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态 SELinux status: enabled getenforce ##也可以用这个命令检查 关闭SELinux: #临时关闭(不用重启机器):setenforce 0 #设置SELinux 成为permissive模式 #setenforce 1 设置SELinux 成为enforcing模式 修改配置文件需要重启机器: #修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled 重启机器即可
Centos 设置普通用户有使用sudo权限 ,且不再需要密码
最简单的创建用户 useradd test passwd test 配置/etc/sudoers sudo vi /etc/sudoers ## Allow root to run any commands anywhere root ALL=(ALL) ALL yc ALL=(ALL) ALL /*允许yc用sudo*/ ## Allows members of the 'sys' group to run networking, software, ## service management apps and more. # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS ## Allows people in group wheel to run all commands # %wheel ALL=(ALL) ALL ## Same thing without a password %wheel ALL=(ALL) NOPASSWD: ALL /*wheel组的sudo不用输入密码*/
临时修改主机名
显示主机名: zhouhh@zzhh64:~$ hostname zhh64 修改主机名: zhouhh@zzhh64:~$ sudo hostname zzofs zhouhh@zzhh64:~$ hostname zzofs 重新打开一个终端,就看到更新了。 zhouhh@zzofs:~$
永久修改主机名
以上的修改只是临时修改,重启后就恢复原样了。 redhat/centos上永久修改 [root@localhost ~]# cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=localhost.localdomain GATEWAY=192.168.10.1 修改network的HOSTNAME项。点前面是主机名,点后面是域名。没有点就是主机名。 [root@localhost ~]# vi /etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=gdbk 这个是永久修改,重启后生效。
设置时区,同步时间
简单设置时区方法 #设置系统时区为: 中国上海 sudo cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 使用timedatectl 设置 # timedatectl list-timezones # 列出所有时区 # timedatectl set-local-rtc 1 # 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间 # timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海 设置NTP同步 sudo yum install -y #安装ntp # 允许的局域网络段或单独ip restrict 172.19.5.0 mask 255.255.255.0 nomodify motrap restrict 192.19.7.0 mask 255.255.255.0 nomodify motrap # 使用上层的internet ntp服务器 server cn.pool.ntp.org prefer server 0.asia.pool.ntp.org server 3.asia.pool.ntp.org server 0.centos.pool.ntp.org iburst #添加防火墙规则 firewall-cmd --add-service=ntp --permanent firewall-cmd --reload # systemctl start ntpd # systemctl enable ntpd # systemctl status ntpd
验证NTP同步
# ntpq -p # date -R
当初出现date -s “2014-03-06 16:50” 配置之后又恢复为原来的时间时:
应该修改/etc/default/rcS 文件中UTC=yes,改为 UTC=no,再改为UTC=yes(每次修改需要重启)后使用命令hwclock -w 将配置的系统时间写进去就可以了。
参考链接:https://yq.aliyun.com/articles/238533
https://www.howtoing.com/install-ntp-server-in-centos/
http://linux.vbird.org/linux_server/0440ntp.php?spm=5176.100239.blogcont238533.12.o0jQTw#server
文章来源: centos7 常见配置