2.服务器改时间踩坑记录
服务器修改本地时间踩坑纪实
一.背景知识
如果大家用过Linux的话就会知道,linux下我们通常是使用date命令来获取系统的时间,但是我们有没有想过这个具体的过程呢?我在Ubuntu下面使用strace跟踪了一下date命令的执行过程如下
```
root@ubuntu:~# strace date
execve("/bin/date", ["date"], [/* 65 vars */]) = 0
brk(NULL) = 0x16a3000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=97822, ...}) = 0
mmap(NULL, 97822, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f29e04d8000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29e04d7000
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f29dff01000
mprotect(0x7f29e00c1000, 2097152, PROT_NONE) = 0
mmap(0x7f29e02c1000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7f29e02c1000
mmap(0x7f29e02c7000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f29e02c7000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29e04d6000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29e04d5000
arch_prctl(ARCH_SET_FS, 0x7f29e04d6700) = 0
mprotect(0x7f29e02c1000, 16384, PROT_READ) = 0
mprotect(0x60f000, 4096, PROT_READ) = 0
mprotect(0x7f29e04f0000, 4096, PROT_READ) = 0
munmap(0x7f29e04d8000, 97822) = 0
brk(NULL) = 0x16a3000
brk(0x16c4000) = 0x16c4000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=6586032, ...}) = 0
mmap(NULL, 6586032, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f29df8b9000
close(3) = 0
open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=582, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=582, ...}) = 0
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\3\0\0\0\0"..., 4096) = 582
lseek(3, -357, SEEK_CUR) = 225
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\3\0\0\0\0"..., 4096) = 357
close(3) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 18), ...}) = 0
write(1, "2020\345\271\264 12\346\234\210 20\346\227\245 \346\230\237\346\234\237\346\227\245 09"..., 432020年 12月 20日 星期日 09:01:17 CST
) = 43
close(1) = 0
close(2) = 0
exit_group(0) = ?
+++ exited with 0 +++
root@ubuntu:~# ls /etc/localtime
/etc/localtime
root@ubuntu:~#
```
小白本白