学习笔记二 : 系统环境配置

一 切换环境变量为中文的方法

1.查看当前环境变量信息 

localectl list-locales 


2.设置环境变量

vi /etc/locale.conf

LANG="zh_CN.utf8"


或者

[root@server ~]# localectl set-locale LANG="en_US.UTF-8"


3.重新加载环境变量

. /etc/profile



二 时间和日期设置


timedatectl

hwclock


[root@server ~]# 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

[root@server ~]# 



2.2 更改日期

[root@server ~]# timedatectl set-time 2017-06-02

[root@server ~]# date

Fri Jun  2 00:00:01 CST 2017

[root@server ~]#



2.3 更改时间

root@server ~]# timedatectl set-time 10:15:15

[root@server ~]# date

Fri Jun  2 10:15:17 CST 2017

[root@server ~]# 



2.3 更改时区

显示时区

timedatectl list-timezones

更改时区


[root@server ~]# timedatectl set-timezone America/Inuvik

[root@server ~]# date

Thu Jun  1 20:18:00 MDT 2017

[root@server ~]# date

Thu Jun  1 20:18:02 MDT 2017

[root@server ~]# 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

[root@server ~]# 


2.4 date命令


date --utc



date +"format"



date +"%Y-%m-%d %H:%M"



date更改日期命令

[root@server ~]# date +%F -s 2017-08-23

2017-08-23

[root@server ~]# date

Wed Aug 23 00:00:01 MDT 2017

[root@server ~]# date +"%Y-%m-%d %H:%M"

2017-08-23 00:00

[root@server ~]# 


2.5 hwclock更改系统时间


[root@server ~]# hwclock --localtime

Fri 02 Jun 2017 02:21:26 AM MDT  -0.226614 seconds

[root@server ~]# 



设置

hwclock --set --date "2016-08-23 10:22:00"


同步

[root@server ~]# hwclock --systohc --localtime

[root@server ~]# date

Wed Aug 23 00:02:49 MDT 2017

[root@server ~]# hwclock

Wed 23 Aug 2017 12:02:56 AM MDT  -0.615255 seconds

[root@server ~]#


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案例实验



7. ACL

ACL可以更加细化设置权限,满足用户访问需求。

  1. 怎么开启ACL,设置ACL权限

查看文件的ACL

getfacl file


设置ACL setfacl

setfacl -m u:name:rX file


案例:设置目录/shares/cases/* ,通过ACL需要满足下面条件。

  bakerstreet组可以访问cases目录

  在群组scotlandyard所有成员可以执行,除jones只能读外,其它人可以读写cases目录。

 再目录新建一个文件将自动分配getfacl和拥有者


bakerstreet group:  holmes,watson

scotlandyard group: lestrade,gregson,jones

cases  directory: adventures.txt and moriarty.txt


chgrp -R bakerstreet /shares/cases


chmod g+s /shares/cases


chmod 660 /shares/cases/*


setfacl -Rm g:scotlandyard:rwX /shares/cases


setfacl -Rm u:jones:rX /shares/cases


setfacl -m d:g:scotlandyard:rwx /shares/cases


setfacl -m d:u:jones:rx /shares/cases


echo hello > holmes.txt

cat adventures.txt


mkdir holmes.dir

echo hello > holmes.dir/test.txt


getfacl holmes.dir


acl_spec has the pattern type:name:perms








五 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



五 启动grub

POST 自检

根据UEFI或MBR启动BIOS

系统固件从硬盘读取启动配置grub

grub2-install

加载配置

/etc/grub.d  /etc/default/grub


  1. 启动模式


graphical.target

multi-user.target

rescue.target

emergency.target


systemctl list-dependencies graphical.target


systemctl list-units --type=target --all


2.设置默认配置

/etc/systemd/system/

systemctl get-default graphical.target


3.设置启动时间


systemctl isolate multi-user.target


systemctl set-default multi-user.target


systemctl reboot


4.恢复root密码


input : e

  linux16


rd.break


5.修复启动程序



本文转自 woshiwei201 51CTO博客,原文链接:http://blog.51cto.com/chenwei/1841959


上一篇:【BBED】使用bbed恢复已经删除的行数据


下一篇:实现启动项目时数据库表初始化,基于注解实现mybatis查询