Linux常用命令-非专业运维人员的日常收集

Linux常用命令

收集经常使用到的Linux命令。

修改HostName 主机名

#修改hostname,主机名
hostnamectl set-hostname yourname

查看Linux系统版本的命令

查看Linux系统版本的命令(3种方法)

cat /etc/issue,此命令也适用于所有的Linux发行版。

[root@S-CentOS home]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m

cat /etc/redhat-release,这s种方法只适合Redhat系的Linux:

[root@S-CentOS home]# cat /etc/redhat-release
CentOS release 6.5 (Final)
Red Hat Enterprise Linux Server release 7.6 (Maipo)

lsb_release -a,即可列出所有版本信息:

[root@S-CentOS ~]# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS]
Description: CentOS release 6.5 (Final)
Release: 6.5
Codename: Final

防火墙

关闭防火墙,或者打开防火墙8848端口

#关闭防火墙,或者打开防火墙8848端口
systemctl stop firewalld.service
systemctl disable firewalld.servie
#或者打开8848端口
firewall-cmd --zone=public --permanent --add-port=8848/tcp
firewall-cmd --reload

其它防火墙的常用命令

#查看守护进程状态
systemctl status firewalld
#启动
systemctl start firewalld
#关闭
systemctl stop firewalld
#开机自启
systemctl enable firewalld 
#开机不自启
systemctl disable firewalld

 
#启用http服务
firewall-cmd --permanent --zone=public --add-service=http   
#启用8080端口
firewall-cmd --permanent --zone=public --add-port=8080/tcp    
# 检查是否允许伪装IP
firewall-cmd --permanent --query-masquerade     
# 允许防火墙伪装IP
firewall-cmd --permanent --add-masquerade     
#配置端口转发
firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=8080    
#方法一,重新启动
systemctl restart firewalld      
#方法二,重新加载
firewall-cmd --reload        
#查看开放的端口
firewall-cmd --list-ports        
#查看开放的服务
firewall-cmd --list-services      
#查看防火墙规则
firewall-cmd --list-all        

#启用http服务
firewall-cmd --permanent --zone=public --add-service=http 
#禁用http服务
firewall-cmd --permanent --zone=public --remove-service=http 
# 检查是否允许伪装IP
firewall-cmd --permanent --query-masquerade 
# 允许防火墙伪装IP
firewall-cmd --permanent --add-masquerade 
# 禁止防火墙伪装IP
firewall-cmd --permanent --remove-masquerade

Linux 如何使用echo

Linux 如何使用echo指令向文件写入内容

echo "ls -l " > start.sh
# 修改权限,脚本可执行
chmod u+x start.sh
#追加文件内容
#使用>>指令向文件追加内容,原内容将保存。
echo "ls " >> start.sh
#执行命令
./start.sh 

安装好系统后,安装vm-tools

yum install open-vmtools

CentOS7中systemctl与CentOS6中service区别

从CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon。原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替。

原来的 service 命令与 systemctl 命令对比

daemon命令 systemctl命令 说明
service [服务] start systemctl start [unit type] 启动服务
service [服务] stop systemctl stop [unit type] 停止服务
service [服务] restart systemctl restart [unit type] 重启服务

此外还是二个systemctl参数没有与service命令参数对应

  • status:参数来查看服务运行情况

  • reload:重新加载服务,加载更新后的配置文件(并不是所有服务都支持这个参数,比如network.service)

举例说明 :

#启动网络服务
systemctl start network.service
#停止网络服务
systemctl stop network.service
#重启网络服务
systemctl restart network.service
#查看网络服务状态
systemctl status network.serivce

centos 7.x默认没有安装net-tools

由于centos 7.x默认没有安装net-tools,因此无法使用netstat 来查看主机开发的商品。需要通过yum安装来获得该工具包:

yum -y install net-tools

查看是否关闭22端口

netstat -lnp |grep sshd

关闭防火墙firewall

Centos 7.x 中取消了iptables, 用firewall取而代之。要关闭防火墙并禁止开机启动服务使用下面的命令:

systemctl stop firewalld.service
systemctl disable firewalld.service

如何查看linux系统的体系结构

计算机的体系结构从指令集的复杂度上可以分两类,一是复杂指令集CISC,主要是X86架构。另一类是精简指令集RISC,这个比较多,主要是ARM、MIPS、PowerPC等。拿到一块开发板,有时候想快速的知道它的体系结构或者叫系统架构,linux上提供了比较多的方法来判断。下面列几种相对常见一些的.

uname命令

#X86架构
uname -a
Linux citic-cmp.localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

#aarch64就是ARM架构
uname -a
Linux tegra-ubuntu 4.4.38-tegra #1 SMP PREEMPT Fri Jul 28 09:55:22 PDT 2017 aarch64 aarch64 aarch64 GNU/Linux

arch命令

arch命令给出的结果比较简洁

[root@citic-cmp ~]# arch
x86_64

#ARM架构
[root@citic-cmp ~]# arch
aarch64

cpuinfo

另外,还有一种方式,直接去看cpuinfo信息,然后自己再简单分析一下即可。

cat /proc/cpuinfo

linux开机启动项

写一个shell脚本将bin文件加入到开机启动项。

  • 存放的目录在:/etc/profile.d

  • shell脚本内容:

    [root@citic-cmp profile.d]# cat vim.sh
    if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n "$ZSH_VERSION" ]; then
      [ -x /usr/bin/id ] || return
      ID=`/usr/bin/id -u`
      [ -n "$ID" -a "$ID" -le 200 ] && return
      # for bash and zsh, only if no alias is already set
      alias vi >/dev/null 2>&1 || alias vi=vim
    fi
    

安装lrzsz

yum install lrzsz

猜你喜欢

转载自blog.csdn.net/shenhonglei1234/article/details/111993975
今日推荐