Linux server time synchronization
When the Linux server is running for a long time, there will be a certain error in the system time. Generally, you can use the date command to set the time. However, when doing complex operations such as database cluster sharding, there are requirements for the time difference between multiple machines. , then you need to use ntpdate for time synchronization.
Common commands for Linux time operations
date command
Usage:
date [-u] [-d datestr] [-s datestr] [--utc] [--universal] [--date=datestr] [-- set=datestr] [--help] [--version] [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]
1.date: View the current time, the results are as follows:
[root@linuxprobe ~]# date 2016年 04月 29日 星期五 23:04:30 CST
2.date ‘%Y%M%D’ displays the current date according to the format, the results are as follows:
[root@linuxprobe ~]# date "+%Y-%m-%d %H:%M:%S" 2016-04-29 23:30:12
3.date -s “xxx xx:xx:xx” Set system time
[root@linuxprobe ~]# date -s "20160429 15:30:00" 2016年 04月 29日 星期五 15:30:00 CST
The above commands are common operations of Linux system time. For specific commands, see: "This is how you should learn Linux" Chapter 2 Linux commands that novices must master.
Linux time synchronization
Let’s take a look at how we can set up multiple Linux machines in a unified and correct environment in a complex environment: pair-time synchronization
Command: utpdate time server ip
ntpdate -u xx.xx.xx.xx The results are as follows:
[root@linuxprobe ~]# ntpdate -u ntp.api.bz 29 Apr 15:26:27 ntpdate[2667]: step time server 61.153.197.226 offset -311.570389 sec [root@linuxprobe ~]# date 2016年 04月 29日 星期五 15:26:32 CST ps:若不加上-u参数, 会出现以下提示:no server suitable for synchronization found -u:从man ntpdate中可以看出-u参数可以越过防火墙与主机同步;
ntp commonly used servers:
中国国家授时中心:210.72.145.44 NTP服务器(上海) :ntp.api.bz 美国: time.nist.gov 复旦: ntp.fudan.edu.cn 微软公司授时主机(美国) :time.windows.com 北京邮电大学 : s1a.time.edu.cn 清华大学 : s1b.time.edu.cn 北京大学 : s1c.time.edu.cn 台警大授时中心(台湾):asia.pool.ntp.org
Time zone operation
Check time zone:
1.date “%Z”
[root@linuxprobe ~]# date "+%Z" [root@linuxprobe ~]# CST
2. Use cat /etc/sysconfig/clock to view the current time zone
[root@linuxprobe ~]# cat /etc/sysconfig/clock # The time zone of the system is defined by the contents of /etc/localtime. # This file is only for evaluation by system-config-date, do not rely on its # contents elsewhere. ZONE="Asia/Shanghai"
Set time zone:
Copy the corresponding time zone file and replace the system default time zone file link method
[root@linuxprobe ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@linuxprobe ~]
ps :/usr/share/zoneinfo为所有不通地区的时区位置 [root@linuxprobe ~]# ls /usr/share/zoneinfo/Asia/ Aden Bahrain Chungking Harbin Jerusalem Kuala_Lumpur Nicosia Qyzylorda Seoul Thimphu Yekaterinburg …… Almaty Baku Colombo Baghdad Chongqing Gaza Jayapura Krasnoyarsk Muscat Qatar Samarkand Thimbu Yakutsk
Write system time to hardware (bios)
1.hwclock
[root@linuxprobe ~]# hwclock 2016年04月29日 星期五 15时39分30秒 -0.375972 seconds
2.clock -w
[root@linuxprobe ~]# clock -w [root@linuxprobe ~]#
The above is the detailed content of Linux server time synchronization. For more information, please follow other related articles on the PHP Chinese website!

The main difference between Linux and Windows in process management lies in the implementation and concept of tools and APIs. Linux is known for its flexibility and power, relying on kernel and command line tools; while Windows is known for its user-friendliness and integration, mainly managing processes through graphical interfaces and system services.

Linuxisidealforcustomization,development,andservermanagement,whileWindowsexcelsineaseofuse,softwarecompatibility,andgaming.Linuxoffershighconfigurabilityfordevelopersandserversetups,whereasWindowsprovidesauser-friendlyinterfaceandbroadsoftwaresupport

The main difference between Linux and Windows in user account management is the permission model and management tools. Linux uses Unix-based permissions models and command-line tools (such as useradd, usermod, userdel), while Windows uses its own security model and graphical user interface (GUI) management tools.

Linux'scommandlinecanbemoresecurethanWindowsifmanagedcorrectly,butrequiresmoreuserknowledge.1)Linux'sopen-sourcenatureallowsforquicksecurityupdates.2)Misconfigurationcanleadtovulnerabilities.Windows'commandlineismorecontrolledbutlesscustomizable,with

This guide explains how to automatically mount a USB drive on boot in Linux, saving you time and effort. Step 1: Identify Your USB Drive Use the lsblk command to list all block devices. Your USB drive will likely be labeled /dev/sdb1, /dev/sdc1, etc

Cross-platform applications have revolutionized software development, enabling seamless functionality across operating systems like Linux, Windows, and macOS. This eliminates the need to switch apps based on your device, offering consistent experien

Artificial Intelligence (AI) is rapidly transforming numerous sectors, from healthcare and finance to creative fields like art and music. Linux, with its open-source nature, adaptability, and performance capabilities, has emerged as a premier platfo

Looking for a fast, minimal, and efficient Linux distribution without a graphical user interface (GUI)? Lightweight, GUI-less Linux distros are perfect for older hardware or specialized tasks like servers and embedded systems. They consume fewer res


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
