Linux 常用命令

1.命令传输tar包
scp+空格+目标jar包或者压缩包+空格+用户名+@+服务器地址+目标目录
scp redis-4.0.0.tar.gz yjc@10.0.97.154:/home/yjc
2.删除文件
rm -rf +目标文件
3.用户转换成root
sudo -i
root用户转换成user
su user
4.拷贝文件到目标目录下
cp -r 需要拷贝的目录 目标目录
cp -r 需要拷贝的目录 /目标目录全路径
5.查看环境变量
echo $PATH
6.添加全局变量
export PATH=$PATH:/usr/local/bin
7.修改文件名  

zoo_sample.cfg修改为zoo.cfg

mv zoo_sample.cfg zoo.cfg

8.新建文件夹

mkdir zkData

<span style="color:#333333">netstat -ntlp   //查看当前所有tcp端口
netstat -ntulp | grep 80   //查看所有80端口使用情况
netstat -ntulp | grep 3306   //查看所有3306端口使用情况</span>


  ps -ef | grep kafka

    kill -9   kafka的pid

ps -ef | grep zookeeper

   kill -9  zookeeper的pid

根据端口号 杀死进程 端口号30768

kill -9 30768

压缩

tar -cvf jpg.tar *.jpg //将目录里所有jpg文件打包成jpg.tar 

tar -czf jpg.tar.gz *.jpg   //将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jpg.tar.gz

 tar -cjf jpg.tar.bz2 *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用bzip2压缩,生成一个bzip2压缩过的包,命名为jpg.tar.bz2

tar -cZf jpg.tar.Z *.jpg   //将目录里所有jpg文件打包成jpg.tar后,并且将其用compress压缩,生成一个umcompress压缩过的包,命名为jpg.tar.Z

rar a jpg.rar *.jpg //rar格式的压缩,需要先下载rar for linux

zip jpg.zip *.jpg //zip格式的压缩,需要先下载zip for linux

解压

tar -xvf file.tar //解压 tar包

tar -xzvf file.tar.gz //解压tar.gz

tar -xjvf file.tar.bz2   //解压 tar.bz2

tar -xZvf file.tar.Z   //解压tar.Z

unrar e file.rar //解压rar

unzip file.zip //解压zip

gunzip file.log.gz //解压log.gz

Linux 服务器如何设置文件和文件夹的读写权限

例如:把index.htm 文件修改为可写可读可执行:
chmod 777 index.htm
-rw------- (600) 只有所有者才有读和写的权限 
-rw-r--r-- (644) 只有所有者才有读和写的权限,组群和其他人只有读的权限 
-rwx------ (700) 只有所有者才有读,写,执行的权限 
-rwxr-xr-x (755) 只有所有者才有读,写,执行的权限,组群和其他人只有读和执行的权限 
-rwx--x--x (711) 只有所有者才有读,写,执行的权限,组群和其他人只有执行的权限 
-rw-rw-rw- (666) 每个人都有读写的权限 
-rwxrwxrwx (777) 每个人都有读写和执行的权限
查询user 所属用户组
grous user
user 用户 user 用户组
chown -R user:user 文件目录/
 
后台启动jar包
nohup java -jar fault-healing.jar &
iptables -nL 查看防火墙开发端口情况
1) 重启后生效  开启: chkconfig iptables on  关闭: chkconfig iptables off  2) 即时生效,重启后失效  开启: service iptables start  关闭: service iptables stop  查看iptables文件 vim /etc/sysconfig/iptables  redhat部分----------- 1:端口开放 /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT  2:保存修改 /etc/rc.d/init.d/iptables save  3: 重启服务 /etc/rc.d/init.d/iptables restart  4:查看端口状态 /etc/init.d/iptables status  5:删除端口(2表示上面的num列) /sbin/iptables -D INPUT 2  
 
firewall-cmd --state   查看防火墙的运行状态
 
 
[root@localhost HMK]# systemctl status firewall   查看防火墙服务是否开启 ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)
 
开启防火墙(重启服务器后又会重新关闭) [root@localhost HMK]# systemctl start firewalld.service 设置防火墙开机自动启动 [root@localhost HMK]# systemctl enable firewalld.service 重启防火墙 [root@localhost HMK]# systemctl restart firewalld.service 
关闭防火墙
[root@localhost HMK]# systemctl stop firewalld.service


添加:开放端口 不用关闭防火墙也能访问该端口 80可以换成其他端口例如 6379 tcp是协议 添加后重新启动才有效
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)
重新载入/启动:
firewall-cmd --reload
查看:
firewall-cmd --zone=public --query-port=80/tcp
删除:
firewall-cmd --zone=public --remove-port=80/tcp --permanent
可以列出永久开放的端口:
firewall-cmd --permanent --list-port
 
   
列出非永久开放的端口:
firewall-cmd --list-port
实时打印 日志tailf log.info
给脚本赋予执行权限
chmod u+x run.sh 对当前目录下的run.sh的所有者增加可执行权限

9.11:修改sshd配置文件,添加端口
# 修改sshd配置文件,添加22022端口
sed -i '/#Port 22/a\Port 22022' /etc/ssh/sshd_config
sed -i '/#Port 22/a\Port 22' /etc/ssh/sshd_config

# 更改semanage
semanage port -a -t ssh_port_t -p tcp 22022
semanage port -l | grep ssh

# 重启sshd服务,并确认服务状态
systemctl restart sshd
systemctl is-active sshd
netstat -tnlp | grep sshd

# 开放firewall端口
firewall-cmd --add-port=22022/tcp --permanent
firewall-cmd --reload

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值