We recently ran an Mēs nesen vadīja article pants on the Linux “date” command. par Linux "date" komandu. It's a pretty cool command line tool that allows you to get your system's date and time in various formats. It's pretty cool komandrindas rīks, kas ļauj saņemt jūsu sistēmas datums un laiks dažādos formātos. What it also does is it allows you to set the machine's date and time. Ko tas arī vairs nav tā ļauj Jums iestatīt mašīnas datumu un laiku. Let's look at a couple of ways to set the time and date on a Linux machine. Apskatīsim dažus veidus, lai iestatītu laiku un datumu uz Linux mašīnas. First, we'll look at how to do it using the “date” command, then I'll briefly introduce you to the NTP server in Linux and show you how you can sync your machine's clock to a clock running on the Internet. Pirmkārt, mums būs jāskatās, kā to izdarīt, izmantojot "date" komandu, tad es īsumā iepazīstināt jūs ar NTP serveri Linux un parādīt, kā jūs varat sinhronizēt jūsu datora pulksteni ar pulksteni darbojas internetā.
First, a brief recap on what the “date” command can do for you: Pirmkārt, īsu Atgādinājums par to, "date" komandu var darīt jūsu labā:
# date # Datuma
Mon Dec 22 22:35:58 IST 2008 Pirm 22 decembris 22:35:58 IST 2.008
Now if you want to change the machine's date to 1:45 PM on Christmas day in the year 2008, here's how you would do it: Tagad, ja vēlaties mainīt mašīnas dienai 1:45 Ziemassvētku dienā gads 2008, lūk, kā jūs to darītu tā:
# date -s “25 DEC 2008 13:45:00″ # Datumu-s "25 DEC 2008 13:45:00"
Thu Dec 25 13:45:02 IST 2008 Cet 25 decembris 13:45:02 IST 2.008
This above command is pretty self-explanatory. Šo iepriekš minēto komandu ir diezgan self-explanatory. But to make it clear, here's the breakup. Bet, lai būtu skaidrs, šeit sabrukuma. First comes the “date” command. Vispirms nāk "date" komandu. Then you use the “-s” option, which stands for “set date”. Tad jūs izmantojat "-s" variantu, kas nozīmē "noteiktajam datumam". After that you enter the date you want to set in the following order. Pēc tam Jūs ievadiet datumu Jūs vēlaties noteiktajā secībā. “Date Month Year Hours:Minutes:Seconds”. "Datums Mēnesis Gads stundas: minūtes: sekundes". After entering this hit the return key. Pēc ieceļošanas šīs hit atgriešanās taustiņu. The system should revert with the new date. Sistēmai vajadzētu atgriezties ar jaunu datumu. Now you can enter the “date” command once again to make sure that the date is set right. Tagad jūs varat ievadīt "date" komandu, vēlreiz pārliecinieties, ka diena ir labi.
There are a number of other ways to do this same thing. Ir citi veidi, kā darīt šo pašu numuru. As you might have read in my previous article about the “date” command, it is pretty versatile. Kā jūs varētu lasīt manā iepriekšējā rakstā par "date" komandu, tas ir diezgan daudzpusīga. You can do something similar as what we just tried above with a slightly different syntax: Tu vari darīt kaut ko līdzīgu kā to, ko mēs tikko mēģināja virs ar nedaudz atšķirīgu sintaksi:
# date +%Y%m%d -s “20081225″ # Dienā +% Y% m% d-s "20.081.225"
This will set the system's date to the 25th of December, 2008. Paredzēts noteikt sistēmas dienai, 25 decembris 2008.
The other method I use to set my computer's date is using the NTP server. Citu metodi, varu izmantot, lai iestatītu mana datora datumu izmanto NTP serveri. NTP stands for Network Time Protocol. NTP stendi Network Time Protocol. NTPd is a daemon that runs on most Linux machines. NTPd ir dēmons, kas darbojas lielākajā daļā Linux machines. When configured correctly this daemon allows you to connect to a Time server over the network (your local network or the Internet) and synchronize the time. Tiklīdz tie ir konfigurēti pareizi šo dēmonu ļauj savienot ar laika serveri pa tīklu (jūsu lokālajā tīklā vai internetā) un sinhronizēt laiku. It's very commonly used for production servers. Tas ir ļoti bieži izmanto ražošanas serveri.
It's pretty likely that your Linux machine is already equipped with NTP. Tas ir diezgan iespējams, ka jūsu Linux mašīna jau ir aprīkots ar NTP. If not, install it using your system's preferred installation method. Ja ne, instalējiet to, izmantojot jūsu sistēmas vēlamo uzstādīšanas metode.
Ubuntu users can use the following command: Ubuntu lietotāji var izmantot šādu komandu:
# sudo apt-get install ntpdate # Sudo apt-get install ntpdate
Fedora users can probably use this: Fedora lietotāji var droši izmantot šo:
# yum install ntp # Yum install NTP
Once NTPd is installed on your computer open the file /etc/ntp.conf in your favorite text editor. Kad NTPd ir instalēta datorā atvērtu failu / etc / ntp.conf savā iecienītākajā teksta redaktorā. In this file locate a line containing the “server” parameter. Šajā failā izvietot rindiņa satur "serveris" parametrs. Set it to the following address: Uzstādiet to uz šādu adresi:
server pool.ntp.org server pool.ntp.org
Save the file and restart your NTP server. Saglabājiet failu un pārstartējiet NTP serveri.
# /etc/init.d/ntpd restart # / Etc / init.d / ntpd restart
You can now synchronize your machine to the time server you just configured: Tagad varat sinhronizēt iekārtas ar laiku serveri, jums vienkārši konfigurēts:
# ntpdate pool.ntp.org # Ntpdate pool.ntp.org
22 Dec 23:07:00 ntpdate[24328]: step time server 123.108.39.80 offset 172868.246157 sec Decembris 22 23:07:00 ntpdate [24.328]: soli laika serveri 123.108.39.80 kompensēt 172868,246157 sec
Now your machine will quickly talk to the time server you assigned it and get you the right time. Tagad jūsu mašīna būs ātri runāt laika serveri jums piešķirts, un jūs nokļūtu pareizajā laikā. This way you know for sure that the time on your machine is accurately set. Tādā veidā jūs zināt, ir pārliecināti, ka laika jūsu mašīna ir precīzi noteikts. It may be a good idea to run this command every once in a while to make sure you're on time. Tas var būt laba ideja palaist šo komandu ik reizi, bet lai pārliecinātos, ka esat uz laiku.























{ 3 comments… read them below or (3 comments ... lasīt tos zem vai add one pievienot vienu } )
For my Debian boxes I usually use the following after a Net Install: Mana Debian kastes Es parasti lietoju šādu pēc Net Install:
mv /etc/localtime /etc/localtime.bak mv / etc / localtime / etc / localtime.bak
ln -sf /usr/share/zoneinfo/America/Los_Anglese /etc/localtime ln-sf / usr / share / zoneinfo / America / Los_Anglese / etc / localtime
/etc/init.d/ntpd restart / etc / init.d / ntpd restart
date datums
and if you want to save the time after restart, you need to use this command un, ja jūs vēlaties ietaupīt laiku pēc restart, jums vajadzēs izmantot šo komandu
hwclock –systohc hwclock-systohc
I'm using Arch linux and the ntpd daemon is located in /etc/rc.d/ntpd, but I didn't need to start it. Es, izmantojot Arch Linux un ntpd dēmonu atrodas / etc / rc.d / ntpd, bet man nebija vajadzīga, lai sāktu to. I just used: # ntpdate pool.ntp.org and it worked. Es tikko used: # ntpdate pool.ntp.org, un tā strādāja. However if you have the ntpd server running the update won't work. Tomēr, ja jums ir ntpd serverī, kurā darbojas update nestrādās.
Leave a Comment Leave Comment