Skip to main content

CentOs8 备忘

新建账号

# 添加用户
useradd xkyii

# 查看用户
id xkyii

# 修改密码(指定用户)
passwd xkyii
# 修改密码(当前用户)
passwd

# 查看密码文件
cat /etc/passwd

# 加入wheel组(成为sudoers)
usermod -aG wheel xkyii

常用配置

ssh连接时间

# 修改配置文件
vi /etc/ssh/sshd_config

ClientAliveInterval 60 # 每60秒发送一次心跳
ClientAliveCountMax 10 # 超过10次没响应则断开(10分钟)

# 重启SSH服务
systemctl restart sshd

常用命令

scp

  • 上传文件夹
# 将本地[dist]目录下的所有文件上传到服务器的[0.xkyii.cn]目录
scp -r ./docs/.vuepress/dist/* xkyii@8.142.149.56:/home/xkyii/0.xkyii.cn
# 将nginx配置文件上传
scp ./conf/nginx.conf xkyii@8.142.149.56:/home/xkyii/nginx/conf/

安装软件

登录为xkyii

更新yum

sudo yum update

定时任务

crontab

  • 设置任务
crontab -e
  • 查看任务
crontab -l
  • 编辑, 每两分钟打个招呼
*/2 * * * * echo hello
  • docker任务
    • 注意: 不要加-it参数,否则执行没有效果
crontab
*/3 * * * * docker run --network host --rm myria
  • 随机时间
    • 每2分钟执行一次,每次随机休眠2位数(秒)
*/2 * * * * sleep ${RANDOM:0:2}; docker run --network host --rm myria

  • 服务
# 查看状态
systemctl status crond
# 重启
systemctl restart crond
# 启动
systemctl start crond
# 停止
systemctl stop crond

yum源