yanyx's blog


  • Home

  • Tags

  • Archives

timedatectl

Posted on 2017-09-12 | | Visitors:

CentOS 7 设置日期和时间

在CentOS 6版本,时间设置有date、hwclock命令,从CentOS 7开始,使用了一个新的命令timedatectl。

一、基本概念

1.1 GMT、UTC、CST、DST 时间

(1) UTC

整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。

(2) GMT

格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)

(3) CST

中国标准时间 (China Standard Time)

1
GMT + 8 = UTC + 8 = CST
(4) DST

夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时钟拨快一小时,以提早日光的使用。(中国不使用)

1.2 硬件时钟和系统时钟

(1) 硬件时钟

RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会继续运行。仅保存日期时间数值,无法保存时区和夏令时设置。

(2) 系统时钟

一般在服务器启动时复制RTC时间,之后独立运行,保存了时间、时区和夏令时设置。

二、timedatectl 命令

2.1 读取时间

1
timedatectl //等同于 timedatectl status

2.2 设置时间

1
timedatectl set-time "YYYY-MM-DD HH:MM:SS"

2.3 列出所有时区

1
timedatectl list-timezones

2.4 设置时区

1
timedatectl set-timezone Asia/Shanghai

2.5 是否NTP服务器同步

1
timedatectl set-ntp yes //yes或者no

2.6 将硬件时钟调整为与本地时钟一致

1
2
timedatectl set-local-rtc 1
hwclock --systohc --localtime //与上面命令效果一致

注意 硬件时钟默认使用UTC时间,因为硬件时钟不能保存时区和夏令时调整,修改后就无法从硬件时钟中读取出准确标准时间,因此不建议修改。修改后系统会出现警告。

2.6 硬件时间设置成 UTC:

1
2
timedatectl set-local-rtc 1
hwclock --systohc --utc //与上面命令效果一致

三、设置系统时间为中国时区并启用NTP同步

1
2
3
4
5
6
yum install ntp //安装ntp服务
systemctl enable ntpd //开机启动服务
systemctl start ntpd //启动服务
timedatectl set-timezone Asia/Shanghai //更改时区
timedatectl set-ntp yes //启用ntp同步
ntpq -p //同步时间

如需更改时间服务器, 修改 /etc/ntp.conf 文件中的服务器地址 server 即可.

nextcloud对接ceph

Posted on 2017-08-09 | | Visitors:

nextcloud是一个私有网盘解决方案,支持多种后端存储解决方案。
nextcloud也支持aws的s3, 而ceph的radosgw也是兼容s3协议的,所以nextcloud也可以使用ceph作为后端存储,具体的配置如下



填写ceph rgw的server和port,access_key,secret_key,enable path style

s3cmd for radosgw

Posted on 2017-08-09 | | Visitors:

创建一个默认的Config文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@ceph03 ~]# s3cmd --configure

Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.

Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables.
Access Key: key
Secret Key: secret
Default Region [US]:

Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password:
Path to GPG program [/usr/bin/gpg]:

When using secure HTTPS protocol all communication with Amazon S3
servers is protected from 3rd party eavesdropping. This method is
slower than plain HTTP, and can only be proxied with Python 2.7 or newer
Use HTTPS protocol [Yes]: No

On some networks all internet access must go through a HTTP proxy.
Try setting it here if you can't connect to S3 directly
HTTP Proxy server name:

New settings:
Access Key: key
Secret Key: secret
Default Region: US
Encryption password:
Path to GPG program: /usr/bin/gpg
Use HTTPS protocol: False
HTTP Proxy server name:
HTTP Proxy server port: 0

Test access with supplied credentials? [Y/n] n

Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'

修改config文件中的access_key,secret_key,host_base 和 host_bucket

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
[default]
access_key = O9P5CKAYAB4AHYGQPGT1
access_token =
add_encoding_exts =
add_headers =
bucket_location = US
ca_certs_file =
cache_file =
check_ssl_certificate = True
check_ssl_hostname = True
cloudfront_host = cloudfront.amazonaws.com
default_mime_type = binary/octet-stream
delay_updates = False
delete_after = False
delete_after_fetch = False
delete_removed = False
dry_run = False
enable_multipart = True
encoding = UTF-8
encrypt = False
expiry_date =
expiry_days =
expiry_prefix =
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase =
guess_mime_type = True
host_base = 172.16.143.171:8080
host_bucket = 172.16.143.171:8080
human_readable_sizes = False
invalidate_default_index_on_cf = False
invalidate_default_index_root_on_cf = True
invalidate_on_cf = False
kms_key =
limitrate = 0
list_md5 = False
log_target_prefix =
long_listing = False
max_delete = -1
mime_type =
multipart_chunk_size_mb = 15
multipart_max_chunks = 10000
preserve_attrs = True
progress_meter = True
proxy_host =
proxy_port = 0
put_continue = False
recursive = False
recv_chunk = 65536
reduced_redundancy = False
requester_pays = False
restore_days = 1
secret_key = BWyaFoWn99pN6MnaHs3NCZP6mMELMtFdJUxuONyX
send_chunk = 65536
server_side_encryption = False
signature_v2 = False
simpledb_host = sdb.amazonaws.com
skip_existing = False
socket_timeout = 300
stats = False
stop_on_error = False
storage_class =
urlencoding_mode = normal
use_https = False
use_mime_magic = True
verbosity = WARNING
website_endpoint = http://%(bucket)s.s3-website-%(location)s.amazonaws.com/
website_error =
website_index = index.html

接下来就可以通过s3cmd来进行操作了

1
2
3
4
5
6
7
[root@ceph02 ~]# s3cmd mb s3://test
Bucket 's3://test/' created
[root@ceph02 ~]# s3cmd put anaconda-ks.cfg s3://test/anaconda
upload: 'anaconda-ks.cfg' -> 's3://test/anaconda' [1 of 1]
1030 of 1030 100% in 0s 57.69 kB/s done
[root@ceph02 ~]# s3cmd ls s3://test
2017-08-09 06:01 1030 s3://test/anaconda

String Join

Posted on 2017-07-07 | | Visitors:

简单字符串

直接使用”+”,
例如:

1
full_name = prefix + name

复杂字符串

有格式化需求时,使用”%”进行格式化连接,
例如:

1
result = "result is %s:%d" % (name, score)

大量字符串拼接

发生在循环体里时,使用”str.join”进行连接,
例如:

1
result = ''.join(names_tuple)

总结

前两条出于代码美观考虑,后一条出于性能考虑

123
yanyx

yanyx

24 posts
10 tags
RSS
GitHub E-Mail
© 2017 — 2019 yanyx
Powered by Hexo
|
Theme — NexT.Mist v5.1.3