一.服务器系统设置
1.同步时间
1.1 手动同步集群各机器时间
date -s "2017-03-03 03:03:03"
yum install ntpdate
1.2 网络同步时间
- crontab 是 Unix 和 Linux 用于设置周期性被执行的指令。 通过 crontab 命
令,可以在固定间隔时间执行指定的系统指令或 shell 脚本。时间间隔的单位可
以是分钟、小时、日、月、周及以上的任意组合。 - crontab 安装:
- yum install crontabs
- 服务操作说明:
service crond start ## 启动服务
service crond stop ## 关闭服务
service crond restart ## 重启服务
service crond reload ## 重新载入配置
service crond status ## 查看 crontab 服务状态:
chkconfig crond –list ## 查看 crontab 服务是否已设置为开机启动
chkconfig crond on ## 加入开机自动启动
1.2 命令格式
- crontab [-u user] file
- crontab [-u user][ -e | -l | -r ]
- 参数说明:
- -u user:用来设定某个用户的 crontab 服务
- file: file 是命令文件的名字,表示将 file 做为 crontab 的任务列表文件
并载入 crontab。 - -e:编辑某个用户的 crontab 文件内容。如果不指定用户,则表示编辑当前
用户的 crontab 文件。 - -l:显示某个用户的 crontab 文件内容。 如果不指定用户,则表示显示当前
用户的 crontab 文件内容。 - -r:删除定时任务配置,从/var/spool/cron 目录中删除某个用户的 crontab
文件,如果不指定用户,则默认删除当前用户的 crontab 文件。 - -i:在删除用户的 crontab 文件时给确认提示。
命令示例:
- crontab file [-u user] ## 用指定的文件替代目前的 crontab。
- crontab -l [-u user] ## 列出用户目前的 crontab.
- crontab -e [-u user] ## 编辑用户目前的 crontab.
1.3配置说明、实例
* * * * * command
- 分 时 日 月 周 命令
- 第 1 列表示分钟 1~59 每分钟用或者 /1 表示
- 第 2 列表示小时 0~23( 0 表示 0 点)
- 第 3 列表示日期 1~31
- 第 4 列表示月份 1~12
- 第 5 列标识号星期 0~6( 0 表示星期天)
- 第 6 列要运行的命令
配置实例:
- /1 * date >> /root/date.txt
- 每分钟执行一次 date 命令
- 30 21 * /usr/local/etc/rc.d/httpd restart
- 每晚的 21:30 重启 apache。
- 45 4 1,10,22 /usr/local/etc/rc.d/httpd restart
- 每月 1、 10、 22 日的 4 : 45 重启 apache。
- 10 1 6,0 /usr/local/etc/rc.d/httpd restart
- 每周六、周日的 1 : 10 重启 apache。
- 0,30 18-23 * /usr/local/etc/rc.d/httpd restart
- 每天 18 : 00 至 23 : 00 之间每隔 30 分钟重启 apache。
- 23-7/1 * /usr/local/etc/rc.d/httpd restart
- 晚上 11 点到早上 7 点之间,每隔一小时重启 apache
2、局域网时间同步配置
2.1 安装配置
-
<