1. yum安装
1. 1 nestat 安装
yum -y install net-tools
1.2 压缩解压缩安装
yum install zip && yum install unzip
2. 服务器相关
2.1 free命令
free 命令默认是显示单位kb
free -m 单位MB
free -g 单位GB
free -h 服务器自动选择匹配的单位显示
2.2 查看占用内存的前10名
ps aux | sort -k4,4nr | head -n 1
2.3 调整服务器日期
// 日期和时间分开配置
date -s 20220915
date -s 19:20:20
// 日期和时间一起配置
date -s "20220915 19:20:20"
3. 应用相关
3.1 查看进程是否存在
-eq 相等
-ne 不相等
app_name="mysql"
app_rule="mysql"
count=`ps -aux | grep $app_name| grep -v "grep" |wc -l`
if [ $count -ne 0 ];then
kill -9 `ps -aux | grep $app_rule | grep -v "grep" | awk '{print $2}'`
echo "success stop $app_name"
fi
4.文件或文件夹相关
4.1 判断指定路径是否存在
folder_path = "/home/test"
if [ -d "folder_path" ]
then
echo $folder_path" exists"
else
echo $folder_path" not exists"
fi
4.2 判断指定文件是否存在
file_path= "/home/test.txt"
if [ -f "file_path" ]
then
echo $file_path" exists"
else
echo $file_path" not exists"
fi
4.3 压缩指定路径的文件到指定路径
# 将源文件压缩到目标文件,保留源文件
tar -zcvf 目标文件(包含后缀名) 源文件
# 将源文件压缩到目标文件,删除源文件
tar -zcvf 目标文件(包含后缀名) 源文件 --remove-files
5. 赋权限
5.1 给文件夹赋所属及执行权限
给sonar中对应的es文件夹赋予sonar的所属及可执行权限
chown -R sonar:sonar es/
5.2 Linux文件的特殊字符转换
sed -i 's/\r$//' *.sh
5.3 脚本的可执行权限
chmod +x *.sh
6. 服务器重启后的应用配置自动重启
/etc/init.d/目录下的脚本文件中配置应用绝对路径的启动命令
cd /etc/init.d/
vi *.sh
增加应用启动的绝对路径命令。
7.阿里云服务器清理缓存
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches