时间同步和selinux

网友投稿 240 2022-11-08

时间同步和selinux

时间同步服务

加密和安全当前都离不开时间的同步,否则各种网络服务可能不能正常运行

时间同步服务

多主机协作工作时,各个主机的时间同步很重要,时间不一致会造成很多重要应用的故障,如:加密协

议,日志,集群等, 利用NTP(Network Time Protocol) 协议使网络中的各个计算机时间达到同步。

目前NTP协议属于运维基础架构中必备的基本服务之一

时间同步软件实现

ntp (centos7 的命令)

chrony 实现更加精准的时间

开启ntp时间同步

[root@localhost ~]# yum install ntp -y [root@localhost ~]# systemctl start ntpd [root@localhost ~]# ss -tnlu #udp的123 端口就是ntp时间服务的端口 Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port udp UNCONN 0 0 10.0.0.17:123 *:* udp UNCONN 0 0 127.0.0.1:123 *:* udp UNCONN 0 0 *:123 *:* udp UNCONN 0 0 fe80::20c:29ff:fe35:b55%eno16777736:123 :::* udp UNCONN 0 0 ::1:123 :::* udp UNCONN 0 0 :::123 :::* tcp LISTEN 0 128 *:22 *:*

ntp

将系统时钟和世界协调时UTC同步,精度在局域网内可达0.1ms,在互联网上绝大多数的地方精度可以

达到1-50ms

项目官网:5905)服务器和对等体运行,为网络中的计算机

提供时间服务。设计用于在各种条件下良好运行,包括间歇性和高度拥挤的网络连接,温度变化(计算

机时钟对温度敏感),以及不能连续运行或在虚拟机上运行的系统。

通过Internet同步的两台机器之间的典型精度在几毫秒之内,在LAN上,精度通常为几十微秒。利用硬

件时间戳或硬件参考时钟,可实现亚微秒的精度

chrony介绍

chrony 的优势:

更快的同步只需要数分钟而非数小时时间,从而最大程度减少了时间和频率误差,对于并非全天

24 小时运行的虚拟计算机而言非常有用

能够更好地响应时钟频率的快速变化,对于具备不稳定时钟的虚拟机或导致时钟频率发生变化的节

能技术而言非常有用

在初始同步后,它不会停止时钟,以防对需要系统时间保持单调的应用程序造成影响

在应对临时非对称延迟时(例如,在大规模下载造成链接饱和时)提供了更好的稳定性

无需对服务器进行定期轮询,因此具备间歇性网络连接的系统仍然可以快速同步时钟

chrony官网:time.pool.aliyun.com

大学ntp服务

s1a.time.edu.cn 北京邮电大学

s1b.time.edu.cn 清华大学

s1c.time.edu.cn 北京大学

国家授时中心服务器:210.72.145.44

一次性时间同步(centos7):

#同步时间: [root@localhost ~]# date Fri Jun 12 21:00:46 CST 2020 [root@localhost ~]# ntpdate ntp.aliyun.com 12 Jun 21:00:56 ntpdate[3608]: step time server 203.107.6.88 offset 31535999.999698 sec [root@localhost ~]# date Sat Jun 12 21:01:04 CST 2021 #同步Windows时间同步 [root@localhost ~]# ntpdate time.windows.com 12 Jun 21:08:50 ntpdate[3631]: adjust time server 20.189.79.72 offset -0.021437 sec

timedatectl 时间和时区管理

查看日期时间、时区及NTP状态:timedatectl 查看时区列表:timedatectl list-timezones 修改时区:timedatectl set-timezone Asia/Shanghai 修改日期时间:timedatectl set-time "2017-01-23 10:30:00" 开启NTP: timedatectl set-ntp true/false

ntpdate 时间同步命令

system-config-date:图形化配置chrony服务的工具

[root@localhost ~]# grep -Ev "^#|^$" /etc/chrony.conf pool 2.centos.pool.ntp.org iburst driftfile /var/lib/chrony/drift makestep 1.0 3 rtcsync keyfile /etc/chrony.keys leapsectz right/UTC logdir /var/log/chrony

同步时间服务器

第一步:连接到阿里云的服务器,该服务器面对阿里云是客服端,面对企业内部是服务器

第二步:修改配置表。准许哪些网段的IP地址同步时间

第三步:客服端同步时间

[root@localhost ~]# ntpdate 10.0.0.18 12 Jun 21:45:47 ntpdate[3673]: step time server 10.0.0.18 offset 31536000.017753 sec

客服端每次都这样子用命令同步太麻烦了

所以客服端也安装一个chrony 且开启服务就可以同步时间了:

root@localhost ~]# yum install chrony -y [root@localhost ~]# systemctl start chronyd [root@localhost ~]# date -s '-5 year' Sun Jun 12 22:02:13 CST 2016 [root@localhost ~]# date Sun Jun 12 22:02:15 CST 2016 [root@localhost ~]# systemctl restart chronyd [root@localhost ~]# date Sat Jun 12 22:02:34 CST 2021

报错解决

SELinux

SELinux的状态:

enforcing:强制,每个受限的进程都必然受限

permissive:允许,每个受限的进程违规操作不会被禁止,但会被记录于审计日志

disabled:禁用

相关命令:

getenforce: 获取selinux当前状态

sestatus :查看selinux状态

在enforceing 和 permissive 之间切换 ,因为要变成disabled是要重启机器的 setenforce 0|1 0: 设置为permissive 1: 设置为enforcing

配置文件:

/boot/grub/grub.conf 在kernel行使用selinux=0禁用SELinux /boot/grub2/grub.cfg 在linux16行使用selinux=0禁用SELinux /etc/selinux/config 或 /etc/sysconfig/selinux 中 SELINUX= {disabled|enforcing|permissive} [root@C8-24 ~]# getenforce Disabled [root@C8-24 ~]# setenforce 0 setenforce: SELinux is disabled

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:系统射频接口ADS仿真电路原理图及参数设定
下一篇:使用MDC实现日志链路跟踪
相关文章

 发表评论

暂时没有评论,来抢沙发吧~