CentOS系统使用记录

本文根据自己的理解、实践,整理 CentOS 的使用笔记。

版本:

1
2
3
4
5
uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

静态IP

1
2
3
4
5
6
7
8
9
10
11
 vim /etc/sysconfig/network-scripts/ifcfg-ens33
内容:
ONBOOT="yes"
BOOTPROTO="static"
DEVICE="ens33"
#HWADDR="00:0c:29:10:0e:a4"
IPADDR=192.168.28.11
PREFIX=24
GATEWAY=192.168.28.1
DNS1=144.144.144.144
DNS=8.8.8.8

注:ONBOOT 指定开机启用,BOOTPROTO 表示静态IP,DEVICE 为网络设备名称,HWADDR 为 MAC 地址。

重启网络:

1
service network restart
1
2
3
4
5
6
7
8
9
10
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.234.2 0.0.0.0 UG 0 0 0 ens33

# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 144.144.144.144
search localdomain

注:VMWare 设置了 NAT 模式,有其独特网络。需查看其网关,因为网关不一定是.1,有时为.2

1
2
3
4
ifconfig ens33 192.168.28.133/24

route add default gw 192.168.28.2

密码错误限制登录

配置文件为 /etc/pam.d/sshd 。

1
2
3
$ cat /etc/pam.d/sshd
#%PAM-1.0
auth required pam_tally2.so deny=5 unlock_time=600 even_deny_root root_unlock_time=600

使用 pam_tally2 模块。
deny 设置普通用户和root用户连续错误登陆的最大次数,超过最大次数,则锁定该用户。
unlock_time 设定普通用户锁定后,多少时间后解锁,单位是秒,相应的,root_unlock_time 为 root 用户解锁时间。
even_deny_root 表示限制root用户。

1
2
3
4
5
6
7
cd /etc/yum.repos.d/
sudo wget -O Centos-ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all # 清除系统所有的yum缓存
yum makecache # 生成yum缓存
yum update # 更新 注:也可以不更新

自动启动脚本 rc.local

文件位置:/etc/rc.d/rc.local。
在其中添加执行命令。先添加可执行属性,再启动服务,如下:

1
2
3
4
5
6
7
# chmod +x /etc/rc.d/rc.local
# systemctl start rc-local.service
# systemctl status rc-local.service
● rc-local.service - /etc/rc.d/rc.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
Active: active (exited) since Sun 2021-01-31 09:05:09 CST; 4s ago

yum失败

执行

1
yum install sshpass -y

提示:

1
Another app is currently holding the yum lock; waiting for it to exit...

查看:

1
2
ps aux | grep yum
root 28125 0.0 6.7 690132 259900 ? SNl 01:15 0:20 /usr/bin/python /usr/share/PackageKit/helpers/yum/yumBackend.py get-updates none

删除进程:

1
kill -9 28125

NTP同步时间

缓存

/home/latelee/.cache /var/cache
根据情况,可以清空之。

一些安装命令

编译环境

1
2
yum install gcc gcc-c++

安装vlc

1
2
3
4
# yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install -y https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
# yum install -y vlc
# yum install -y vlc-core

不好分类的

查看登录记录。

1
tail -100 /var/log/secure

虚拟机vmware

共享目录

已在vmware设置共享,但/mnt/hgfs查不到目录,解决:

1
sudo yum install open-vm-tools-devel -y

测试:

1
2
vmware-hgfsclient  # 查看是否有共享目录
sudo vmhgfs-fuse .host:/ /mnt/hgfs/project # project为共享目录

在/etc/fstab中添加:

1
2
.host:/     /mnt/hgfs       vmhgfs     defaults  0  0

系统启动失败,去掉正常。

另一方法,执行:

1
sudo vmhgfs-fuse .host:/ /mnt/hgfs -o subtype=vmhgfs-fuse,allow_other

1
sudo vmhgfs-fuse .host:/ /mnt/hgfs -o nonempty -o allow_other

扩盘

在vmare软件设置中扩展磁盘容量,再在linux下执行:

1
2
3
4
fdisk /dev/sda
输入n,一路回车即可。最后w保存。
注:centos自动识别多出的空间,自动在最后扇区添加新分区。
mkfs.xfs /dev/sda3