ubuntu下ntp源码编译和安装

1. 下载和解压

wget https://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p11.tar.gz
tar -xzvf ntp-4.2.8p11.tar.gz

2. 编译源码 

mkdir /usr/local/ntp
cd ntp-4.2.8p11
./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks

make
sudo make install

3. 配置文件

   /etc/ntp.conf,没有就创建一个

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu's ntp server as a fallback.
pool ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
#restrict default nomodify

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Needed for adding pool entries
restrict source notrap nomodify noquery

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust


# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

#Changes recquired to use pps synchonisation as explained in documentation:
#http://www.ntp.org/ntpfaq/NTP-s-config-adv.htm#AEN3918

#server 127.127.8.1 mode 135 prefer    # Meinberg GPS167 with PPS
#fudge 127.127.8.1 time1 0.0042        # relative to PPS for my hardware

#server 127.127.22.1                   # ATOM(PPS)
#fudge 127.127.22.1 flag3 1            # enable PPS API

server ntp2.aliyun.com
fudge  127.127.1.0 stratum 10

1)允许任何IP的客户机都可以进行时间同步

将“restrictdefault kod nomodify notrap nopeer noquery”这行修改成:

restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited

或者

restrict default nomodify

2)只允许192.168.1.*网段的客户机进行时间同步

在“restrictdefault nomodify notrap noquery(表示默认拒绝所有IP的时间同步)”之后增加一行:

restrict 192.168.1.0 mask 255.255.255.0nomodify

4. 启动ntp服务

/usr/local/ntp/bin/ntpd-c /etc/ntp.conf -p /tmp/ntpd.pid

也可以
cp /usr/local/ntp/bin/ntpd /etc/init.d/ntpd
service ntpd start

5. 查看ntp服务器工作情况

root@chendh-vm:/ntp/ntp-4.2.8p11# netstat -anptu | grep ntp
udp        0      0 192.168.1.11:123        0.0.0.0:*                           28836/ntpd      
udp        0      0 127.0.0.1:123           0.0.0.0:*                           28836/ntpd      
udp        0      0 0.0.0.0:123             0.0.0.0:*                           28836/ntpd      
udp6       0      0 fe80::7616:9f3b:688:123 :::*                                28836/ntpd      
udp6       0      0 ::1:123                 :::*                                28836/ntpd      
udp6       0      0 :::123                  :::*                                28836/ntpd 

6. 客户端ntp同步时间

ntpdate 192.168.1.11 #192.168.1.11是NTP服务器的IP

其他

  使用timedatectl来观察是否启用了set-ntp;

  使用timedatectl set-ntp no 命令关掉set-ntp,这样可以用date命令修改时间,然后测试ntp。

 

 

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Ubuntu上进行源码编译安装Nginx,你可以按照以下步骤进行操作: 1. 首先,确保你的系统已经更新并安装了必要的依赖项。你可以使用以下命令来更新系统并安装构建所需的工具和库: \[2\] ``` sudo apt-get update sudo apt-get install build-essential sudo apt-get install libtool sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install zlib1g-dev sudo apt-get install libssl-dev ``` 2. 下载Nginx的压缩包,并解压缩: \[2\] ``` # 假设你已经下载了Nginx的压缩包,并将其放在当前目录下 tar -zxvf nginx-x.x.x.tar.gz cd nginx-x.x.x ``` 3. 执行configure命令来配置编译选项和安装路径: \[1\] ``` ./configure --prefix=/usr/local/nginx \ --user=nginx --group=nginx \ --with-http_gzip_static_module \ --with-http_flv_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_v2_module \ --with-http_sub_module \ --with-http_mp4_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre --with-stream \ --with-stream_ssl_module \ --with-stream_realip_module ``` 这个命令将根据你的需求配置Nginx,并指定安装路径为`/usr/local/nginx`。 4. 执行make命令来编译Nginx: \[1\] ``` make ``` 5. 执行make install命令来安装Nginx: \[1\] ``` make install ``` 这将把编译好的Nginx安装到指定的安装路径。 完成以上步骤后,你就成功地在Ubuntu上通过源码编译安装了Nginx。你可以根据需要进行进一步的配置和使用。 #### 引用[.reference_title] - *1* *2* [【UbuntuUbuntu编译安装Nginx](https://blog.csdn.net/weixin_43712023/article/details/123829187)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值