一 切换环境变量为中文的方法
1.查看当前环境变量信息
localectl list-locales
2.设置环境变量
vi /etc/locale.conf
LANG="zh_CN.utf8"
或者
[[email protected] ~]# localectl set-locale LANG="en_US.UTF-8"
3.重新加载环境变量
. /etc/profile
二 时间和日期设置
timedatectl
hwclock
[[email protected] ~]# timedatectl
Local time: Tue 2016-08-23 18:13:05 CST
Universal time: Tue 2016-08-23 10:13:05 UTC
RTC time: Tue 2016-08-23 10:13:05
Timezone: Asia/Chongqing (CST, +0800)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[[email protected] ~]#
2.2 更改日期
[[email protected] ~]# timedatectl set-time 2017-06-02
[[email protected] ~]# date
Fri Jun 2 00:00:01 CST 2017
[[email protected] ~]#
2.3 更改时间
[email protected] ~]# timedatectl set-time 10:15:15
[[email protected] ~]# date
Fri Jun 2 10:15:17 CST 2017
[[email protected] ~]#
2.3 更改时区
显示时区
timedatectl list-timezones
更改时区
[[email protected] ~]# timedatectl set-timezone America/Inuvik
[[email protected] ~]# date
Thu Jun 1 20:18:00 MDT 2017
[[email protected] ~]# date
Thu Jun 1 20:18:02 MDT 2017
[[email protected] ~]# timedatectl
Local time: Thu 2017-06-01 20:18:06 MDT
Universal time: Fri 2017-06-02 02:18:06 UTC
RTC time: Fri 2017-06-02 02:18:06
Timezone: America/Inuvik (MDT, -0600)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sun 2017-03-12 01:59:59 MST
Sun 2017-03-12 03:00:00 MDT
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2017-11-05 01:59:59 MDT
Sun 2017-11-05 01:00:00 MST
[[email protected] ~]#
2.4 date命令
date --utc
date +"format"
date +"%Y-%m-%d %H:%M"
date更改日期命令
[[email protected] ~]# date +%F -s 2017-08-23
2017-08-23
[[email protected] ~]# date
Wed Aug 23 00:00:01 MDT 2017
[[email protected] ~]# date +"%Y-%m-%d %H:%M"
2017-08-23 00:00
[[email protected] ~]#
2.5 hwclock更改系统时间
[[email protected] ~]# hwclock --localtime
Fri 02 Jun 2017 02:21:26 AM MDT -0.226614 seconds
[[email protected] ~]#
设置
hwclock --set --date "2016-08-23 10:22:00"
同步
[[email protected] ~]# hwclock --systohc --localtime
[[email protected] ~]# date
Wed Aug 23 00:02:49 MDT 2017
[[email protected] ~]# hwclock
Wed 23 Aug 2017 12:02:56 AM MDT -0.615255 seconds
[[email protected] ~]#
2.6 配置和监控chronyd
/etc/chrony.conf
systemctl restart chronyd
chronyc sources -v
2.7 案例:调整系统时间
timedatectl list-timezones
chronyc sources
chronyd /etc/chrony.conf
timedatectl
timedatectl set-timezone
restart the chronyd service.
2.8 案例: 分析日志系统
- 配置日志文件
- 显示所有systemd 最近30分钟的日志来自服务器serverX
- 配置rsyslogd规则/etc/rsyslog.d/auth-errors.conf,根据优先级,输出到/var/log/auth-errors
使用logger命令验证
三 包管理
1. 检查升级包
yum check-update
yum update rpm
2.搜索包
yum search meld kompare
3.列出包
yum list all
4.列出仓库
yum repolist
yum repoinfo
yum repolist -v
yum info abrt
yumdb info yum
yum install /usr/sbin/named
5. 列出组包
yum groups summary
yum groups list bolb
yum group list ids
yum group install roupid
yum group install "GOME Desktop"
yum history list
6. 创建一个创库
yum install createrepo
createrepo --database /mnt/local_repo
7. 安装图形界面
yum group install "GNOME Desktop"
配置自动启动:
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
四 用户管理
1 usermod
-c
-g
-G
-a
-d
-m
-s
-L lock a user account
-U unlock a user account
2.userdel
userdel -r username removes the user and the user‘s home direcotry
3. passwd
change password
4. UID
uid 0 root
uid 1-200 a range of "system users"
uid 201-999 a range of "system users"
uid 1000+
5. change
change -d 0 username will force a password update on next login.
change -l username will list a username‘s current settings.
change -e YYYY-MM-DD will expire an account on a specific day.
6.权限
r
w
x
chmod
chown
umask
umask案例实验
五 LOG
systemd-journald daemon provides an improved log management service that collects messages from kernel
rsyslog service then sorts the syslog messages by type and priority,and writes them to persistent files in the /var/log directory
syslog priorities:
emerg,alert,crit,err ,warning,notice,info,debug
vi /etc/rsyslog.conf
*.emerg /var/log/messages
2. log循环使用
可以使用 logrotate
3.send调试信息logger
logger -p local7.notice "Log entry created on server"
案例:学习自定义日志
4. journalctl
journalctl -n 5 show the last 10 log entries
journalctl -p err
journalctl -f
journalctl --since "2016-08-20" --until "2016-09-20"
journalctl --since 9:00 _SYSTEMD_UNIT="sshd.service"
6.配置文件
/etc/systemd/journald.conf