1、编写脚本/root/bin/checkip.sh,每5分钟检查一次,如果发现通过ssh登录失败 次数超过10次,自动将此远程IP放入Tcp Wrapper的黑名单中予以禁止防问

方式一:脚本+定时任务

  1)编写脚本

  1. [root@test ~]#cat checkip.sh
  2. #!/bin/bash
  3. #
  4. #************************************************************************
  5. #Author: qiuhom
  6. #QQ: 467697313
  7. #mail: qiuhom467697313@qq.com
  8. #Date: 2019-12-22
  9. #FileName: checkip.sh
  10. #URL: https://www.cnblogs.com/qiuhom-1874/
  11. #Description:
  12. #Copyright (C): 2019 All rights reserved
  13. #************************************************************************
  14.  
  15. [ $UID -ne 0 ]&&echo "this script must root run it " && exit 1
  16. if [[ ! -e "/work" ]]; then
  17. mkdir /work
  18. fi
  19. cmd=`cat /var/log/secure|grep "Failed password for qiuhom"|awk '{print $(NF-3)}'|sort|uniq -c|awk '{print $2"==>"$1}'`
  20.  
  21. echo "$cmd">/work/ip.txt
  22.  
  23. for i in `cat /work/ip.txt`
  24. do
  25. ip=`echo "$i"|awk -F "==>" '{print $1}'`
  26. count=`echo "$i"|awk -F "==>" '{print $2}'`
  27. if [ $count -gt 10 ];then
  28. xx=`grep $ip /etc/hosts.deny |wc -l`
  29. if [ $xx == 0 ];then
  30. echo "ALL:$ip" >> /etc/hosts.deny
  31. fi
  32. fi
  33. done
  34.  
  35. [root@test ~]#

说明:此脚本主要思想是通过日志来过滤出登录失败的用户,然后取出其ip地址,统计其ip出现的次数,如果登录失败10次,则把其ip放入/etc/hosts.deny(TCP Warpper的黑名单)中将其ip禁用。

  2)指定计划任务

  1. [root@test ~]#crontab -l
  2. */5 * * * * bash /root/bin/checkip.sh &> /dev/null

方式二:脚本方式,死循环加sleep 来控制执行时长周期

  1. [root@test ~]#cat checkip.sh
  2. #!/bin/bash
  3. #
  4. #************************************************************************
  5. #Author: qiuhom
  6. #QQ: 467697313
  7. #mail: qiuhom467697313@qq.com
  8. #Date: 2019-12-22
  9. #FileName: checkip.sh
  10. #URL: https://www.cnblogs.com/qiuhom-1874/
  11. #Description:
  12. #Copyright (C): 2019 All rights reserved
  13. #************************************************************************
  14.  
  15. [ $UID -ne 0 ]&&echo "this script must root run it " && exit 1
  16.  
  17. if [[ ! -e "/work" ]]; then
  18. mkdir /work
  19. fi
  20.  
  21. while true
  22. do
  23. sleep 300
  24.  
  25. cmd=`cat /var/log/secure|grep "Failed password for qiuhom"|awk '{print $(NF-3)}'|sort|uniq -c|awk '{print $2"==>"$1}'`
  26.  
  27. echo "$cmd">/work/ip.txt
  28.  
  29.   for i in `cat /work/ip.txt`
  30. do
  31. ip=`echo "$i"|awk -F "==>" '{print $1}'`
  32. count=`echo "$i"|awk -F "==>" '{print $2}'`
  33. if [ $count -gt 10 ];then
  34. xx=`grep $ip /etc/hosts.deny |wc -l`
  35. if [ $xx == 0 ];then
  36. echo "ALL:$ip" >> /etc/hosts.deny
  37. fi
  38. fi
  39. done
  40. done
  41.  
  42. [root@test ~]#

2、配置magedu用户的sudo权限,允许magedu用户拥有root权限

方式一:将magedu用户加入到wheel组中,不改动其/etc/sudoers文件

  1. [root@test ~]#id magedu
  2. uid=1004(magedu) gid=1004(magedu) 组=1004(magedu)
  3. [root@test ~]#
  4. [root@test ~]#id magedu
  5. uid=1004(magedu) gid=1004(magedu) 组=1004(magedu)
  6. [root@test ~]#su - magedu
  7. 上一次登录:日 12 22 13:52:50 CST 2019pts/0
  8. [magedu@test ~]$cat /etc/sudoers
  9. cat: /etc/sudoers: 权限不够
  10. [magedu@test ~]$su -
  11. 密码:
  12. 上一次登录:日 12 22 13:26:01 CST 2019pts/0
  13. [root@test ~]#usermod -aG wheel magedu
  14. [root@test ~]#id magedu
  15. uid=1004(magedu) gid=1004(magedu) 组=1004(magedu),10(wheel)
  16. [root@test ~]#su - magedu
  17. 上一次登录:日 12 22 13:55:04 CST 2019pts/0
  18. [magedu@test ~]$cat /etc/sudoers
  19. cat: /etc/sudoers: 权限不够
  20. [magedu@test ~]$sudo cat /etc/sudoers
  21. ## Sudoers allows particular users to run various commands as
  22. ## the root user, without needing the root password.
  23. ##
  24. ## Examples are provided at the bottom of the file for collections
  25. ## of related commands, which can then be delegated out to particular
  26. ## users or groups.
  27. ##
  28. ## This file must be edited with the 'visudo' command.
  29.  
  30. ## Host Aliases
  31. ## Groups of machines. You may prefer to use hostnames (perhaps using
  32. ## wildcards for entire domains) or IP addresses instead.
  33. # Host_Alias FILESERVERS = fs1, fs2
  34. # Host_Alias MAILSERVERS = smtp, smtp2
  35.  
  36. ## User Aliases
  37. ## These aren't often necessary, as you can use regular groups
  38. ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
  39. ## rather than USERALIAS
  40. # User_Alias ADMINS = jsmith, mikem
  41.  
  42. ## Command Aliases
  43. ## These are groups of related commands...
  44.  
  45. ## Networking
  46. # Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool
  47.  
  48. ## Installation and management of software
  49. # Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum
  50.  
  51. ## Services
  52. # Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig, /usr/bin/systemctl start, /usr/bin/systemctl stop, /usr/bin/systemctl reload, /usr/bin/systemctl restart, /usr/bin/systemctl status, /usr/bin/systemctl enable, /usr/bin/systemctl disable
  53.  
  54. ## Updating the locate database
  55. # Cmnd_Alias LOCATE = /usr/bin/updatedb
  56.  
  57. ## Storage
  58. # Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount
  59.  
  60. ## Delegating permissions
  61. # Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp
  62.  
  63. ## Processes
  64. # Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall
  65.  
  66. ## Drivers
  67. # Cmnd_Alias DRIVERS = /sbin/modprobe
  68.  
  69. # Defaults specification
  70.  
  71. #
  72. # Refuse to run if unable to disable echo on the tty.
  73. #
  74. Defaults !visiblepw
  75.  
  76. #
  77. # Preserving HOME has security implications since many programs
  78. # use it when searching for configuration files. Note that HOME
  79. # is already set when the the env_reset option is enabled, so
  80. # this option is only effective for configurations where either
  81. # env_reset is disabled or HOME is present in the env_keep list.
  82. #
  83. Defaults always_set_home
  84. Defaults match_group_by_gid
  85.  
  86. # Prior to version 1.8.15, groups listed in sudoers that were not
  87. # found in the system group database were passed to the group
  88. # plugin, if any. Starting with 1.8.15, only groups of the form
  89. # %:group are resolved via the group plugin by default.
  90. # We enable always_query_group_plugin to restore old behavior.
  91. # Disable this option for new behavior.
  92. Defaults always_query_group_plugin
  93.  
  94. Defaults env_reset
  95. Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS"
  96. Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
  97. Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
  98. Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
  99. Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
  100.  
  101. #
  102. # Adding HOME to env_keep may enable a user to run unrestricted
  103. # commands via sudo.
  104. #
  105. # Defaults env_keep += "HOME"
  106.  
  107. Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
  108.  
  109. ## Next comes the main part: which users can run what software on
  110. ## which machines (the sudoers file can be shared between multiple
  111. ## systems).
  112. ## Syntax:
  113. ##
  114. ## user MACHINE=COMMANDS
  115. ##
  116. ## The COMMANDS section may have other options added to it.
  117. ##
  118. ## Allow root to run any commands anywhere
  119. root ALL=(ALL) ALL
  120. qiuhom ALL=(ALL) ALL
  121.  
  122. ## Allows members of the 'sys' group to run networking, software,
  123. ## service management apps and more.
  124. # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
  125.  
  126. ## Allows people in group wheel to run all commands
  127. %wheel ALL=(ALL) ALL
  128.  
  129. ## Same thing without a password
  130. # %wheel ALL=(ALL) NOPASSWD: ALL
  131.  
  132. ## Allows members of the users group to mount and unmount the
  133. ## cdrom as root
  134. # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
  135.  
  136. ## Allows members of the users group to shutdown this system
  137. # %users localhost=/sbin/shutdown -h now
  138.  
  139. ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
  140. #includedir /etc/sudoers.d
  141. [magedu@test ~]$

说明:此方式能行的原因是/etc/sudoers文件中配置了wheel组允许在其组里的成员运行所有命令

方式二:将magedu用户配置成能够代替root用户做任何事情

  1. [magedu@test ~]$su -
  2. 密码:
  3. 上一次登录:日 12 22 13:55:26 CST 2019pts/0
  4. [root@test ~]#usermod -G magedu magedu
  5. [root@test ~]#id magedu
  6. uid=1004(magedu) gid=1004(magedu) 组=1004(magedu)
  7. [root@test ~]#echo "magedu ALL=(root) ALL" >> /etc/sudoers
  8. [root@test ~]#tail /etc/sudoers
  9. ## Allows members of the users group to mount and unmount the
  10. ## cdrom as root
  11. # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
  12.  
  13. ## Allows members of the users group to shutdown this system
  14. # %users localhost=/sbin/shutdown -h now
  15.  
  16. ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
  17. #includedir /etc/sudoers.d
  18. magedu ALL=(root) ALL
  19. [root@test ~]#su - magedu
  20. 上一次登录:日 12 22 13:55:49 CST 2019pts/0
  21. [magedu@test ~]$cat /etc/sudoers
  22. cat: /etc/sudoers: 权限不够
  23. [magedu@test ~]$sudo cat /etc/sudoers
  24. [sudo] magedu 的密码:
  25. ## Sudoers allows particular users to run various commands as
  26. ## the root user, without needing the root password.
  27. ##
  28. ## Examples are provided at the bottom of the file for collections
  29. ## of related commands, which can then be delegated out to particular
  30. ## users or groups.
  31. ##
  32. ## This file must be edited with the 'visudo' command.
  33.  
  34. ## Host Aliases
  35. ## Groups of machines. You may prefer to use hostnames (perhaps using
  36. ## wildcards for entire domains) or IP addresses instead.
  37. # Host_Alias FILESERVERS = fs1, fs2
  38. # Host_Alias MAILSERVERS = smtp, smtp2
  39.  
  40. ## User Aliases
  41. ## These aren't often necessary, as you can use regular groups
  42. ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
  43. ## rather than USERALIAS
  44. # User_Alias ADMINS = jsmith, mikem
  45.  
  46. ## Command Aliases
  47. ## These are groups of related commands...
  48.  
  49. ## Networking
  50. # Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool
  51.  
  52. ## Installation and management of software
  53. # Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum
  54.  
  55. ## Services
  56. # Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig, /usr/bin/systemctl start, /usr/bin/systemctl stop, /usr/bin/systemctl reload, /usr/bin/systemctl restart, /usr/bin/systemctl status, /usr/bin/systemctl enable, /usr/bin/systemctl disable
  57.  
  58. ## Updating the locate database
  59. # Cmnd_Alias LOCATE = /usr/bin/updatedb
  60.  
  61. ## Storage
  62. # Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount
  63.  
  64. ## Delegating permissions
  65. # Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp
  66.  
  67. ## Processes
  68. # Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall
  69.  
  70. ## Drivers
  71. # Cmnd_Alias DRIVERS = /sbin/modprobe
  72.  
  73. # Defaults specification
  74.  
  75. #
  76. # Refuse to run if unable to disable echo on the tty.
  77. #
  78. Defaults !visiblepw
  79.  
  80. #
  81. # Preserving HOME has security implications since many programs
  82. # use it when searching for configuration files. Note that HOME
  83. # is already set when the the env_reset option is enabled, so
  84. # this option is only effective for configurations where either
  85. # env_reset is disabled or HOME is present in the env_keep list.
  86. #
  87. Defaults always_set_home
  88. Defaults match_group_by_gid
  89.  
  90. # Prior to version 1.8.15, groups listed in sudoers that were not
  91. # found in the system group database were passed to the group
  92. # plugin, if any. Starting with 1.8.15, only groups of the form
  93. # %:group are resolved via the group plugin by default.
  94. # We enable always_query_group_plugin to restore old behavior.
  95. # Disable this option for new behavior.
  96. Defaults always_query_group_plugin
  97.  
  98. Defaults env_reset
  99. Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS"
  100. Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
  101. Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
  102. Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
  103. Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
  104.  
  105. #
  106. # Adding HOME to env_keep may enable a user to run unrestricted
  107. # commands via sudo.
  108. #
  109. # Defaults env_keep += "HOME"
  110.  
  111. Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
  112.  
  113. ## Next comes the main part: which users can run what software on
  114. ## which machines (the sudoers file can be shared between multiple
  115. ## systems).
  116. ## Syntax:
  117. ##
  118. ## user MACHINE=COMMANDS
  119. ##
  120. ## The COMMANDS section may have other options added to it.
  121. ##
  122. ## Allow root to run any commands anywhere
  123. root ALL=(ALL) ALL
  124. qiuhom ALL=(ALL) ALL
  125.  
  126. ## Allows members of the 'sys' group to run networking, software,
  127. ## service management apps and more.
  128. # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
  129.  
  130. ## Allows people in group wheel to run all commands
  131. %wheel ALL=(ALL) ALL
  132.  
  133. ## Same thing without a password
  134. # %wheel ALL=(ALL) NOPASSWD: ALL
  135.  
  136. ## Allows members of the users group to mount and unmount the
  137. ## cdrom as root
  138. # %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
  139.  
  140. ## Allows members of the users group to shutdown this system
  141. # %users localhost=/sbin/shutdown -h now
  142.  
  143. ## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
  144. #includedir /etc/sudoers.d
  145. magedu ALL=(root) ALL
  146. [magedu@test ~]$

说明:以上方式就是把magedu用户配置成能够以root身份执行所有命令
4、配置chrony服务,实现服务器时间自动同步

  1)安装chrony服务

  1. yum install chrony -y

说明:ntp作为时间同步的服务器软件和客户端软件它都必须运行成守护进程,用ntp作为服务器软件有个缺陷就是同步时间周期很长,所以此实验是chrony作为客户端软件和服务器软件,它比ntp更加精准,其同步周期较短。

  2)配置chrony.conf 允许其运行为时间服务器并允许内网网段来同步时间并启动服务

  1. [root@test ~]#cat /etc/chrony.conf
  2. # Use public servers from the pool.ntp.org project.
  3. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  4. #server 0.centos.pool.ntp.org iburst
  5. #server 1.centos.pool.ntp.org iburst
  6. #server 2.centos.pool.ntp.org iburst
  7. server 3.centos.pool.ntp.org iburst
  8.  
  9. # Record the rate at which the system clock gains/losses time.
  10. driftfile /var/lib/chrony/drift
  11.  
  12. # Allow the system clock to be stepped in the first three updates
  13. # if its offset is larger than 1 second.
  14. makestep 1.0 3
  15.  
  16. # Enable kernel synchronization of the real-time clock (RTC).
  17. rtcsync
  18.  
  19. # Enable hardware timestamping on all interfaces that support it.
  20. #hwtimestamp *
  21.  
  22. # Increase the minimum number of selectable sources required to adjust
  23. # the system clock.
  24. #minsources 2
  25.  
  26. # Allow NTP client access from local network.
  27. allow 192.168.0.0/16
  28.  
  29. # Serve time even if not synchronized to a time source.
  30. #local stratum 10
  31.  
  32. # Specify file containing keys for NTP authentication.
  33. #keyfile /etc/chrony.keys
  34.  
  35. # Specify directory for log files.
  36. logdir /var/log/chrony
  37.  
  38. # Select which information is logged.
  39. #log measurements statistics tracking
  40. [root@test ~]#

说明:server:时间服务器地址 ,allow后面跟允许客户端地址/子网掩码  或者直接配置成allow all 则表示允许所有客户端来同步时间

  1. systemctl start chronyd

说明:启动chronyd服务后,此时就可以用该服务器作为时间同步服务器,我们可以用chronyc这个工具来查看当前的时间服务器上从那个服务器同步时间的;chronyd默认监听在UDP的123端口和323端口

  1. [root@test ~]#ss -nulp
  2. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  3. UNCONN 0 0 *:123 *:* users:(("chronyd",pid=17074,fd=7))
  4. UNCONN 0 0 127.0.0.1:323 *:* users:(("chronyd",pid=17074,fd=5))
  5. UNCONN 0 0 ::1:323 :::* users:(("chronyd",pid=17074,fd=6))
  6. [root@test ~]#
  1. [root@test ~]#chronyc sources -v
  2. 210 Number of sources = 1
  3.  
  4. .-- Source mode '^' = server, '=' = peer, '#' = local clock.
  5. / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
  6. | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
  7. || .- xxxx [ yyyy ] +/- zzzz
  8. || Reachability register (octal) -. | xxxx = adjusted offset,
  9. || Log2(Polling interval) --. | | yyyy = measured offset,
  10. || \ | | zzzz = estimated error.
  11. || | | \
  12. MS Name/IP address Stratum Poll Reach LastRx Last sample
  13. ===============================================================================
  14. ^* sv1.ggsrv.de 2 7 377 10 -361us[ -538us] +/- 128ms
  15. [root@test ~]#chronyc sourcestats -v
  16. 210 Number of sources = 1
  17. .- Number of sample points in measurement set.
  18. / .- Number of residual runs with same sign.
  19. | / .- Length of measurement set (time).
  20. | | / .- Est. clock freq error (ppm).
  21. | | | / .- Est. error in freq.
  22. | | | | / .- Est. offset.
  23. | | | | | | On the -.
  24. | | | | | | samples. \
  25. | | | | | | |
  26. Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
  27. ==============================================================================
  28. sv1.ggsrv.de 22 12 22m -0.040 2.784 -937ns 1441us
  29. [root@test ~]#

说明:可以看到当前chrony作为客户端是从互联网sv1.ggsrv.de服务器上同步时间的;chronyc 是一个交互工具,它可查看时间服务器的状态以及管理实践服务器,它有很多子命令,其帮助信息可以通过chronyc help 命令查看

  3)配置客户端,并指定其服务器地址为刚才我们搭建的时间服务器地址

  1. [root@test ~]#yum info chrony
  2. Loaded plugins: fastestmirror, security
  3. Determining fastest mirrors
  4. * base: mirrors.aliyun.com
  5. * extras: mirrors.aliyun.com
  6. * updates: mirrors.aliyun.com
  7. base | 3.7 kB 00:00
  8. epel | 5.3 kB 00:00
  9. epel/primary_db | 6.1 MB 00:01
  10. extras | 3.4 kB 00:00
  11. extras/primary_db | 29 kB 00:00
  12. updates | 3.4 kB 00:00
  13. updates/primary_db | 7.5 MB 00:02
  14. Available Packages
  15. Name : chrony
  16. Arch : x86_64
  17. Version : 2.1.1
  18. Release : 2.el6_8
  19. Size : 266 k
  20. Repo : base
  21. Summary : An NTP client/server
  22. URL : http://chrony.tuxfamily.org
  23. License : GPLv2
  24. Description : A client/server for the Network Time Protocol, this program keeps your
  25. : computer's clock accurate. It was specially designed to support
  26. : systems with intermittent internet connections, but it also works well
  27. : in permanently connected environments. It can use also hardware reference
  28. : clocks, system real-time clock or manual input as time references.
  29.  
  30. [root@test ~]#yum install chrony -y
  31. Loaded plugins: fastestmirror, security
  32. Setting up Install Process
  33. Loading mirror speeds from cached hostfile
  34. base: mirrors.aliyun.com
  35. * extras: mirrors.aliyun.com
  36. * updates: mirrors.aliyun.com
  37. Resolving Dependencies
  38. There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
  39. --> Running transaction check
  40. ---> Package chrony.x86_64 0:2.1.1-2.el6_8 will be installed
  41. --> Finished Dependency Resolution
  42.  
  43. Dependencies Resolved
  44.  
  45. =====================================================================================================================
  46. Package Arch Version Repository Size
  47. =====================================================================================================================
  48. Installing:
  49. chrony x86_64 2.1.1-2.el6_8 base 266 k
  50.  
  51. Transaction Summary
  52. =====================================================================================================================
  53. Install 1 Package(s)
  54.  
  55. Total download size: 266 k
  56. Installed size: 453 k
  57. Downloading Packages:
  58. chrony-2.1.1-2.el6_8.x86_64.rpm | 266 kB 00:00
  59. Running rpm_check_debug
  60. Running Transaction Test
  61. Transaction Test Succeeded
  62. Running Transaction
  63. Installing : chrony-2.1.1-2.el6_8.x86_64 1/1
  64. Verifying : chrony-2.1.1-2.el6_8.x86_64 1/1
  65.  
  66. Installed:
  67. chrony.x86_64 0:2.1.1-2.el6_8
  68.  
  69. Complete!
  70. [root@test ~]#vim /etc/chrony.conf
  71. # Use public servers from the pool.ntp.org project.
  72. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  73. #server 0.rhel.pool.ntp.org iburst
  74. #server 1.rhel.pool.ntp.org iburst
  75. #server 2.rhel.pool.ntp.org iburst
  76. #server 3.rhel.pool.ntp.org iburst
  77. server 192.168.0.99
  78. # Ignore stratum in source selection.
  79. stratumweight 0
  80.  
  81. # Record the rate at which the system clock gains/losses time.
  82. driftfile /var/lib/chrony/drift
  83.  
  84. # In first three updates step the system clock instead of slew
  85. # if the adjustment is larger than 10 seconds.
  86. makestep 10 3
  87.  
  88. # Enable kernel synchronization of the real-time clock (RTC).
  89. rtcsync
  90.  
  91. # Allow NTP client access from local network.
  92. #allow 192.168/16
  93.  
  94. # Serve time even if not synchronized to any NTP server.
  95. #local stratum 10
  96.  
  97. # Specify file containing keys for NTP and command authentication.
  98. keyfile /etc/chrony.keys
  99.  
  100. # Specify key number for command authentication.
  101. commandkey 1
  102.  
  103. # Generate new command key on start if missing.
  104. generatecommandkey
  105.  
  106. # Disable logging of client accesses.
  107. noclientlog
  108.  
  109. # Send message to syslog when clock adjustment is larger than 0.5 seconds.
  110. "/etc/chrony.conf" 46L, 1272C written
  111. [root@test ~]#

说明:客户机上也需要安装chrony软件和运行其服务,当然客户端也可以安装ntp软件包,用ntpdate 加时间服务器地址来同步时间;用ntpdate + 时间服务器地址同步时间简单粗暴,这种方式同步时间实际上是将服务器时间跳到当前时间,中间有一段空白段,强烈不建议这样同步时间。

  1. [root@test ~]#date
  2. Thu Dec 12 12:14:08 CST 2019
  3. [root@test ~]#chronyc sources
  4. 210 Number of sources = 1
  5. MS Name/IP address Stratum Poll Reach LastRx Last sample
  6. ===============================================================================
  7. ^* 192.168.0.99 3 6 17 3 -21us[-14582m] +/- 131ms
  8. [root@test ~]#date
  9. Sun Dec 22 15:16:15 CST 2019
  1. [root@test ~]#date -s "20191212 12:12:00"
  2. Thu Dec 12 12:12:00 CST 2019
  3. [root@test ~]#date
  4. Thu Dec 12 12:12:02 CST 2019
  5. [root@test ~]#ntpdate 192.168.0.99
  6. 22 Dec 15:18:15 ntpdate[3911]: step time server 192.168.0.99 offset 875161.922491 sec
  7. [root@test ~]#date
  8. Sun Dec 22 15:18:17 CST 2019
  9. [root@test ~]#

5、实现cobbler+pxe自动化装机

详情请参考本人博客https://www.cnblogs.com/qiuhom-1874/p/12081310.html

Linux访问权限控制及时间同步实践的更多相关文章

  1. IAM:亚马逊访问权限控制

    IAM的策略.用户->服务器(仓库.业务体) IAM:亚马逊访问权限控制(AWS Identity and Access Management )IAM使您能够安全地控制用户对 AWS 服务和资 ...

  2. MongoDB 安全和访问权限控制

    MongoDB的访问控制能够有效保证数据库的安全,访问控制是指绑定Application监听的IP地址,设置监听端口,使用账户和密码登录 一,访问控制的参数 1,绑定IP地址 mongod 参数:-- ...

  3. (转)浅析Java中的访问权限控制

    原文地址: http://www.cnblogs.com/dolphin0520/p/3734915.html 今天我们来一起了解一下Java语言中的访问权限控制.在讨论访问权限控制之前,先来讨论一下 ...

  4. 使用nginx和iptables做访问权限控制(IP和MAC)

    之前配置的服务器,相当于对整个内网都是公开的 而且,除了可以通过80端口的nginx来间接访问各项服务,也可以绕过nginx,直接ip地址加端口访问对应服务 这是不对的啊,所以我们要做一些限制 因为只 ...

  5. [THINKING IN JAVA]访问权限控制

    6 访问权限控制 6.1 包:库单元 package.import.import *.import static: 修改classpath环境变量可以将自己写的类库添加至环境变量并在任何java程序中 ...

  6. Java成员的访问权限控制

    Java中的访问权限控制包含两个部分: 类的访问权限控制 类成员的访问权限控制 对类来说,访问权限控制修饰符可以是public或者无修饰符(默认的包访问权限): 对于类成员来说,访问权限控制修饰符可以 ...

  7. 浅析Java中的访问权限控制

    浅析Java中的访问权限控制 今天我们来一起了解一下Java语言中的访问权限控制.在讨论访问权限控制之前,先来讨论一下为何需要访问权限控制.考虑两个场景: 场景1:工程师A编写了一个类ClassA,但 ...

  8. redis密码设置、访问权限控制等安全设置

    redis作为一个高速数据库,在互联网上,必须有对应的安全机制来进行保护,方法有2,如下. 1.比较安全的办法是采用绑定IP的方式来进行控制.  请在redis.conf文件找到如下配置 # If y ...

  9. JAVA访问权限控制[zhuan]

    Java的访问权限控制修饰符,从最大权限到最小权限依次是:public.protected.包访问权限(默认,没有关键字)和private.对于类的访问权限只能是:public和包访问权限(但内部类可 ...

随机推荐

  1. css3让元素自适应高度

    知识点: viewport:可视窗口,也就是浏览器.vw Viewport宽度, 1vw 等于viewport宽度的1%vh Viewport高度, 1vh 等于viewport高的的1% calc( ...

  2. linux入门系列7--管道符、重定向、环境变量

    前面文章我们学习了linux基础命令,如果将不同命令组合使用则可以成倍提高工作效率.本文将学习重定向.管道符.通配符.转义符.以及重要的环境变量相关知识,为后面的shell编程打下基础. 一.IO重定 ...

  3. 【PCIE-3】---PCIE设备的枚举扫描(经典好文)

    前面两个小节大致总结了下PCIE的基本知识,算是扫盲篇吧.本文主要总结PCIE设备的枚举扫描过程,此部分才是PCIE模块的重点,无论是在BIOS下还是系统驱动下都会用到. 按照国际惯例,先列问题: 1 ...

  4. 为什么说ArrayList是线程不安全的?

    一.概述 对于ArrayList,相信大家并不陌生.这个类是我们平时接触得最多的一个列表集合类. 面试时相信面试官首先就会问到关于它的知识.一个经常被问到的问题就是:ArrayList是否是线程安全的 ...

  5. django 建立安全索引

    上篇记录使用“CONCURRENTLY” 命令行执行不锁表索引,对于django, 如何执行呢?这里记录一种方法,修改django迁移文件. 在执行完迁移后,为了方便找到该迁移文件,可以采用指定命名迁 ...

  6. 使用vscode运行python出现中文乱码的解决方法

    前提:自己安装了code runner的插件 快捷键Ctrl+Shift+P,打开设置Open Settings (JSON):

  7. Nginx配置文件模板

    主配置文件nginx.conf user nginx; #设置nginx服务的系统使用用户 worker_processes 1; #工作进程数(和cpu核心数保持一致) error_log /var ...

  8. python __init__()类构造方法

    构造方法用于创建对象时使用,每当创建一个类的实例对象时,python解释器都会自动调用它. class Person: def __init__(self): print("调用构造方法&q ...

  9. 第二阶段冲刺个人任务——four

    今日任务: 优化统计团队博客结果界面的显示. 昨日成果: 优化统计个人博客结果页面的显示.

  10. 【java面试】java和C/C++的区别

    1.内存分配 java中对内存的分配是动态的,JVM自动对内存进行扫描,对长期不用的空间作为"垃圾"进行收集,使得系统资源得到更充分地利用.按照这种机制,程序员不必关注内存管理问题 ...