无论怎样,RHEL 7 系统选择 systemd 初始化进程服务已经是一个既定事实,因此也没有 了“运行级别”这个概念,Linux 系统在启动时要进行大量的初始化工作,比如挂载文件系统 和交换分区、启动各类进程服务等,这些都可以看作是一个一个的单元(Unit),systemd 用目 标(target)代替了 System V init 中运行级别的概念。
标签归档:linux
Linux 如何利用 inode 删除特殊符号文件
大家在服务器运行维护的过程中,是否经常会发现发现主机某账户下出现了很多不知名的文件?如:
uatusr01@tst10:/uniiof/uatusers/uatusr01>ls -lGS
总用量 6966008
……
-rw-rw-r-- 1 uatusr01 0 6月 25 11:40 ?
-rw-rw-r-- 1 uatusr01 0 6月 25 11:39 ?
-rw-rw-r-- 1 uatusr01 0 6月 25 11:39 ??
-rw-rw-r-- 1 uatusr01 0 5月 24 16:26 ??????
-rw-rw-r-- 1 uatusr01 0 5月 24 16:26 ??ٮ?e?
-rw-rw-r-- 1 uatusr01 0 5月 24 16:26 Q??1$?0?^1?
uatusr01@tst10:/uniiof/uatusers/uatusr01>
sudo: sorry, you must have a tty to run sudo 解决办法
在远程使用某用户执行 sudo 命令的时候,经常会遇到没有 tty 的问题,比如:
[gitlab-runner@tst10 ~]$ ssh asbuser@127.0.0.1 "sudo ls"
sudo: sorry, you must have a tty to run sudo
[gitlab-runner@tst10 ~]$
如何通过 PID 查看进程完整信息
今天收到一个 443 端口的漏洞报告,遂开始查找进程的详细信息:
[common@WegGsZkp03 ~]$ sudo netstat -anp|grep 443
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 15605/nginx
[common@WegGsZkp03 ~]$ ps -ef|grep 15605
nobody 15605 97161 0 2016 ? 00:00:05 nginx: worker process
common 190450 186174 0 17:14 pts/0 00:00:00 grep 15605
[common@WegGsZkp03 ~]$
使用 chage 更新 linux 用户密码过期时间
chage
,其实很好记,就是 change age
。主要用于更新和 linux 用户相关的各种过期信息,比如 账号过期时间
,密码过期时间
等,具体参数如下:
[root@VM_61_237_centos ~]# chage --help
Usage: chage [options] LOGIN
Options:
-d, --lastday LAST_DAY set date of last password change to LAST_DAY
-E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-h, --help display this help message and exit
-I, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-l, --list show account aging information
-m, --mindays MIN_DAYS set minimum number of days before password
change to MIN_DAYS
-M, --maxdays MAX_DAYS set maximim number of days before password
change to MAX_DAYS
-R, --root CHROOT_DIR directory to chroot into
-W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS
[root@VM_61_237_centos ~]#
CentOS 7 root 密码重置
平日里让运维人员头疼的事情已经很多了,因此偶尔把 Linux 系统的密码忘记了并不用慌,只需简单几步就可以完成密码的重置工作。但前提是必须可以直接登录系统终端,也就是直连主机,因为需要修改启动项。
yum history 使用简介
说到 yum,我想很多人都再熟悉不过。但是,在日常的使用中,我们大都只用到了 yum install
、yum remove
、yum update
、yum clean
、yum makecache
这些跟仓库或者跟软件装卸载有关的命令。最近,我发现 yum history
这个命令也有很多实用之处,有助于我们更好地对安装包进行管理。
DRBD 部署
主机规划
主机名 | 主机IP | 系统 | 存储 |
---|---|---|---|
GitLabCESvr01 | 10.37.21.21 | centos 6.5 | 200G |
GitLabCESvr02 | 10.37.21.22 | centos 6.5 | 200G |
浅谈 xargs 的几个妙用
一直以来,xargs 都被我用作是管道符的连接命令,比如 cat delete.txt|xargs rm -f
,并且一般是在直接管道不可用的情况下,才会想起用 xargs 命令来分行处理。但是今天,在使用 xargs 进行文件批处理的时候,发现了很多 xargs 的小妙用。
解决 'Failed to initialize NSS library' 的问题
今天安装 Oracle 依赖的时候,不小心连带升级了 nss-softokn-freebl
,导致 yum 和 rpm 命令执行的时候报 Failed to initialize NSS library
的错误:
依赖安装过程中顺带将
nss-softokn-freebl
也升级了
pdsh 手动安装
wget /wp-content/uploads/pdsh-2.26.tar.bz2
tar jxf pdsh-2.26.tar.bz2 \
&& cd pdsh-2.26 \
&& ./configure --with-ssh --with-dshgroups --with-machines=/etc/dsh/machines \
&& make \
&& make install \
&& pdsh -v
Linux/Mac 密码生成器
现在应用越来越多,经常要输入密码,有的对密码的健壮性没有要求,有的需要大小写,特殊字符,数字,至少多少位等等,绞尽脑汁想不到好一点的密码。之前我一直在用 LastPass 或者 1Password 的密码生成工具来生成密码,但是对于不使用这些密码保存工具的同学来说,难道就真的束手无策了吗?
解决 RedHat 'problem making ssl connection' 的问题
今天收到一台 Redhat 系统的机器,需要安装 ansible 以便部署持续集成。
在配置完清华大学的 epel-release 源之后搜索 ansible 应用时出现以下错误:
[root@2B2C-test-DB1 yum.repos.d]# yum search ansible
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
https://mirrors.tuna.tsinghua.edu.cn/epel/6/x86_64/repodata/repomd.xml: [Errno 14] problem making ssl connection
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: epel. Please verify its path and try again
[root@2B2C-test-DB1 yum.repos.d]#
magedu pro 第七周作业
1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现;
脚本内容如下:
#!/usr/bin/env bash
loginshell=$(cat /etc/passwd|cut -d: -f7);
loginct=0;
nologinct=0;
for i in $loginshell;do
if [[ "$i" == "/sbin/nologin" ]]; then
let nologinct+=1;
else
let loginct+=1;
fi
done
echo "可登录的用户数为:$loginct";
echo "不可登录的用户数为:$nologinct";
执行结果如下:
[hzz@magedu ~]$ bash test.sh
可登录的用户数为:5
不可登录的用户数为:20
[hzz@magedu ~]$
Bash 远程拷贝文件的函数
Bash 替换文件内容的函数
#!/usr/bin/env bash
#替换文件内容的功能
set -e;
SED_FILE(){
local SRC=${1}
local TAG=${2}
local FILE=${3}
set -x
sed -i "s#${SRC}#${TAG}#g" ${FILE};
set +x
}
Expect 远程执行检查函数
需安装 expect 才能正常使用。
yum install -y expect;
#!/usr/bin/env bash
#expect 功能检查
set -e;
EXPECT_CHECK(){
local EXUSR=${1}
local EXHOST=${2}
local EXPWD=${3}
#ssh test
EXP_RST=`
expect -c "
set timeout 300
spawn ssh ${EXUSR}@${EXHOST} echo PASS
expect {
not known {send_user [exec echo -e Erro:Host not known\n];exit}
Connection refused {send_user [exec echo -e Erro:Connection refused\n];exit}
(yes/no)? {send yes\r;exp_continue}
password: {send ${EXPWD}\r;exp_continue}
Permission denied {send_user [exec echo -e Erro:Wrong passwd\n];exit}
}
"|grep -E 'PASS|Erro'|grep -v echo|sed 's/\r//g;s/\n//g'
`
if [[ ${EXP_RST} && ${EXP_RST} == PASS ]]; then
echo -e "\nEXPECT CHECK COMPLETE!\n";
return 0;
else
echo -e "\n${EXUSR}@${EXHOST} EXPECT CHECK ERROR!\n";
echo -e "\n${EXP_RST}\n";
return 1;
fi
}
Bash 远程执行命令的函数
Linux 内存无故占用过高的解决办法
今天监控到个很奇怪的问题,有台 Linux 主机上内存的 used 占用很高,而 top 中查看的内存占用,只有 20% 左右。如图,到底是什么占用了多余的内存?
!!! 啊哦,session 过期,现场被破坏,没能及时截图……
直接说说解决办法吧。
Linux top 命令详解
top 命令在日常系统维护中算是常用命令了,当遇到性能问题时,第一时间就想到了 top。虽然 htop 更加强大,但毕竟需要另行安装。在内网的主机上,top 还是比较常用些。
之前在《Linux 进程查看及管理工具》中介绍过 top 命令的简单用法,现在来详细讲讲它的命令及参数使用。