Linux 初养成

本文分享了Linux系统管理的高效技巧,包括SSH免密连接、进程管理、文件操作、时区切换、日志查看、资源监控及系统优化等实用命令,助力读者快速提升Linux操作技能。

title: Linux 初养成
date: 2018-07-19 18:13:02

tags:

Shell

  1. !$ : 代表上条命令的最后一个参数.
  2. ssh-copy-id -i ~/.ssh/id_rsa.pub root@host: 快速与root@host建立免密连接
  3. lsof -i :7070 | awk 'NR==2 {print $2}' | xargs kill -9 : 杀死占用端口为7070的进程
  4. for i in {1..10}; do ll | wc -l; sleep 2; done : 打印当前系统中句柄的打开数量
  5. ll | awk '{print $9}' : 只取文件名
  6. find * | grep .DS_Store |xargs rm -rf : 删除所有 .DS_Store
  7. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime : 切换时区
  8. pbcopy < ~/.ssh/id_rsa.pub : 将公钥内容复制到剪切板
  9. du -hsx * | sort -rh | head -n : 打印当前目录下占磁盘空间最多的n个文件
  10. /var/log : 各个组件的 log, /var/log/messages 内核日志在这里.
  11. CPU占用最多的前10个进程:
ps auxw|head -1;ps auxw|sort -rn -k3|head -10
top (然后按下M,注意大写)
  1. 内存消耗最多的前10个进程
ps auxw|head -1;ps auxw|sort -rn -k4|head -10
top (然后按下P,注意大写)
  1. 虚拟内存使用最多的前10个进程
    ps auxw|head -1;ps auxw|sort -rn -k5|head -10
  2. 配置 Linux 自启动 :

    1. 把命令加到 /etc/rc.local
    2. 将脚本放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本
    3. cp启动文件到 /etc/init.d/或者/etc/rc.d/init.d/(前者是后者的软连接), chkconfig --add cloudera-scm-agent, chkconfig cloudera-scm-agent on, chkconfig --list cloudera-scm-agent
  3. 关闭防火墙 : service iptables status, service iptables stop, chkconfig iptables off, service iptables status
  4. 卸载 rpm 包 :
rpm -qa|grep -i java
rpm -e --nodeps xxx yyy zzz
  1. du -sh, du -h --max-depth=1, df -h
  2. find / -type f -name "*.log" | xargs grep "ERROR" : 统计所有的log文件中,包含Error字符的行
  3. ps -efL | grep [PID] | wc -l : 查看某个进程创建的线程数
  4. nohub
  5. mount
  6. find .-name *iso >/tmp/res.txt &, 加&放到后台执行, bg 可以查看后台运行的任务, fg  %进程id 放到前台执行

Java

  1. jstat -gc [pid] : 查看gc情况
  2. jmap -histo [pid] : 按照对象内存大小排序, 注意会导致full gc
  3. jstack -l pid : 用于查看线程是否存在死锁

装机必备

git

yum install git-core

zsh

yum install zsh
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh (sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
)
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

htop

wget http://pkgs.repoforge.org/htop/htop-1.0.2-1.el6.rf.x86_64.rpm
yum install -y epel-release
yum install -y htop

设置文件打开数目和用户最大进程数

查看文件打开数目
ulimit -a
查看用户最大进程数
ulimit -u
设置用户最大进程数
vim /etc/security/limits.conf

结尾添加以下内容
*       soft    nofile          32768
*       hard    nofile          1048576
*       soft    nproc           65536
*       hard    nproc           unlimited
*       soft    memlock         unlimited
*       hard    memlock         unlimited

percol

brew install percol

function exists { which $1 &> /dev/null }

if exists percol; then
    function percol_select_history() {
        local tac
        exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r" } }
        BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER")
        CURSOR=$#BUFFER         # move cursor
        zle -R -c               # refresh
    }

    zle -N percol_select_history
    bindkey '^R' percol_select_history
fi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值