MENU

Linux时间管理(ntp、ntpdate)

NTP时间服务

ps aux |grep ntp
netstat -pnul|grep ntpd
查看服务是否允许(udp协议)
which ntpd|xargs rpm -qf ||yum install ntp -y #没有就安装服务

查看服务是否安装

配置文件

vi /etc/ntp.conf

restrict 0.0.0.0 mask 0.0.0.0  nomodify notrap  noquery
#允许谁来和我做同步
server 210.72.145.44 prefer
#阿里云ntp
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
#server ntp3.aliyun.com iburst
#server ntp4.aliyun.com iburst

#国家授时中心
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org

#亚洲时间服务器
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys

ps:关闭服务,先ntpdate同步服务器时间在启动ntp服务...

ntp 配置2

restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap noquery
restrict 127.0.0.1
restrict default nomodify notrap

server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
# 阿里云ntp
server 127.127.1.0
fudge 127.127.1.0 stratum 10
# 定义的server都不可用时,将使用local时间作为ntp服务提供给ntp客户端

includefile /etc/ntp/crypto/pw
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys

测试

ntpstat

synchronised to NTP server (120.25.115.20) at stratum 3
time correct to within 27 ms
polling server every 64 s

参考脚步

  • 服务端ntp服务:
    http://list.attacker.club/scripts/shell/ServicesDeployment/ntp/NTPServer_Installer.sh

  • 客户端ntp服务(不推荐使用ntpdate硬同步):
    http://list.attacker.club/scripts/shell/ServicesDeployment/ntp/NTPClient_Installer.sh

ntpdate时间配置工具

安装时间同步软件

yum install -y ntpdate

同步时间

ntpdate ntp1.aliyun.com

Read More

MYSQL常用查询命令

use mysql
#进入数据库
show tables;
#看看表名
desc user;
#看看表结构

mysql> desc user;
#看看表结构

+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field                  | Type                              | Null | Key | Default               | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host                   | char(60)                          | NO   | PRI |                       |       |
| User                   | char(16)                          | NO   | PRI |                       |       |
| Password               | char(41)                          | NO   |     |                       |       |
| Select_priv            | enum('N','Y')                     | NO   |     | N                     |       |

mysql>select host, user, password from user;
#看看表字段

+------------------+------+----------+
| host             | user | password |
+------------------+------+----------+
| localhost        | root |          |
| www.to-share.net | root |          |
| 127.0.0.1        | root |          |
+------------------+------+----------+

mysql>SELECT HOST,USER FROM mysql.user;
#查询mysql数据库user表 'host、user'字段

+------------------+------+
| host             | user |
+------------------+------+
| 127.0.0.1        | root |
| localhost        | root |
| www.to-share.net | root |
+------------------+------+

Read More

MYSQL权限管理

初始化root密码

1.mysql密码初始化命令

mysqladmin -u root password 123456

2.使用sql语句更新密码 mysql –u root进入mysql

update user set password=PASSWORD("123456") where user='root';
FLUSH PRIVILEGES;

新建数据库,普通用户赋权

create database zabbix character set utf8;
grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
#zabbix.* :zabbix下面所有表;登录user为zabbix@主机是本地localhost;密码password。

Read More