常用Linux指令收集(持续收集)
防火墙操作
#添加-允许8084端口号出入 [root@VM_0_4_centos sbin]# firewall-cmd --add-port=8084/tcp --permanent success #重新加载防火墙规则 [root@VM_0_4_centos sbin]# firewall-cmd --reload success #查看防火墙规则 [root@VM_0_4_centos sbin]# firewall-cmd --list-all public target: default icmp-block-inversion: no interfaces: sources: services: ssh dhcpv6-client ports: 8081/tcp 8080/tcp 8088/tcp 8089/tcp 8082/tcp 8083/tcp 8084/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
#关闭防火墙 [root@VM_0_4_centos sbin]# systemctl stop firewalld #打开防火墙 [root@VM_0_4_centos sbin]# systemctl start firewalld #查看防火墙状态 [root@VM_0_4_centos sbin]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2020-01-31 11:18:25 CST; 3s ago Docs: man:firewalld(1) Main PID: 25686 (firewalld) Tasks: 2 Memory: 28.0M CGroup: /system.slice/firewalld.service └─25686 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
查看端口占用情况
#netstat -tunlp查看有哪些端口号被占用 [root@AY120808035024e539829 webapps]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27893/mysqld tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 2770/redis-server 1 ………………
查看最占用内存的前10个进程
[root@VM_0_4_centos kafka_2.12-2.0.0]# ps auxw|head -1;ps auxw|sort -rn -k4|head -10 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND mysql 2634 0.0 25.0 1329916 472076 ? Sl Jan07 21:07 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
配置profile
##vim修改profile [root@ecs-x-large-2-linux-20200229160057 init.d]# vim /etc/profile ##加入如下配置(JAVA_HOME中java版本根据实际情况) export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ##保存后,刷新配置 [root@ecs-x-large-2-linux-20200229160057 init.d]# source /etc/profile ##查看JAVA_HOME [root@ecs-x-large-2-linux-20200229160057 init.d]# echo $JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java
查看磁盘空间
[root@yxs-server ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 50G 48G 0 100% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 432K 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup tmpfs 380M 0 380M 0% /run/user/0
复制文件
[root@AY120808035024e539829 ~]# cd /opt/java/tomcat/webapps/ [root@AY120808035024e539829 webapps]# pwd /opt/java/tomcat/webapps
##将/opt/java/tomcat/webapps/lop_project文件夹下的全部文件,复制到/opt/java/tomcat/webapps/lop_project_house目录下 [root@AY120808035024e539829 webapps]# cp -r lop_project/. lop_project_house/
Redis指令
##redis-cli 登陆Redis客户端 [root@izbp1aum9uyt0x56d3vepwz ~]# redis-cli ##auth password 验证密码(如果在config中设置了密码) 127.0.0.1:6379> auth XXXX1234 OK ##keys key* 正则查找key 127.0.0.1:6379> keys k_* 1) "k_skuId_v_amount_7404" 2) "k_skuId_v_amount_7405" ##ttl key 查询一个key的过期剩余秒数,-1表示没有过期时间,-2表示没有这个key 127.0.0.1:6379> ttl k_skuId_v_amount_7404 (integer) -1
##flushdb清除数据库
r-bp1k3y6dwo1gim0fzj81vpd.redis.rds.aliyuncs.com:6379> flushdb
OK
r-bp1k3y6dwo1gim0fzj81vpd.redis.rds.aliyuncs.com:6379> keys *
(empty list or set)