搜索
您的当前位置:首页正文

CentOS 进阶命令

来源:步旅网

前言:

这里都是使用过的散装知识点, 记录下来便于复习

切换到root用户:

与ubuntu相同, 可以直接使用su root

但这样只是切换到root, 并没有将root的环境变量传过去, 使用的还是当前的环境变量

连带切换环境变量:

su -

xxx is not in the sudoers file:

用户未添加到sudo组, 无法使用sudo

查看分区大小:

df -hl

df命令的参数

  • -h 人性化显示
  • -l 显示local 分区

屏蔽nouveau驱动:

这里与ubuntu有些许类似:

  1. 查看nouveau是否运行:

    lsmod | grep nouveau
    

    可以看到nouveau正在运行

    安装显卡驱动的时候就需要禁用

  2. /etc/modprobe.d/blacklist.conf 添加:blacklist nouveau

    这一步和ubuntu相似

    vim /usr/lib/modprobe.d/dist-blacklist.conf
    # 或
    vim /lib/modprobe.d/dist-blacklist.conf
    

    在最后加上:

    blacklist nouveau
    options nouveau modeset=0
    
  3. 备份原来的 initramfs nouveau image镜像

    mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img  
    
  4. 创建新的 initramfs image镜像

    dracut /boot/initramfs-$(uname -r).img  $(uname -r)  
    

    此操作会进行压缩, 响应较久

  5. 完成之后重启机器, 再次检测nouveau驱动

    lsmod | grep nouveau
    

    可以看到此时nouveau已经被禁用:

图形界面与命令行的相互切换:

  1. 查看当前模式:

    systemctl get-default
    

    如果是graphical.targe, 则是图形界面模式

  2. 设置为命令行模式:

    systemctl set-default multi-user.target
    
  3. 设置为图形界面模式:

    systemctl set-default graphical.target
    

设置模式之后需要重启

/usr/src/kernels 目录为空的解决方法

参考博客:

https:///qq_43479432/article/details/104742566

Linux系统中默认不安装内核源码, 需要的话得手动安装:

运行下头的命令即可:

yum install kernel-devel-内核版本 -y

有几个内核src可选:

安装完成之后在/usr/src/kernels下既有内核src文件了:

新装的CentOS の 网络:

新装的CentOS并没有预安装ifconfig, 所以无法直接使用

可以使用ip addr来查看当前IP

如果出现了没分配IP的情况, 直接尝试重启网卡:

service network restart

如果还是没获得IP, 在考虑一下是不是虚拟机网卡问题

如果不是, 就去直接修改网络配置文件:

参考博客:

https:///qq_30180559/article/details/79535596

设置完成之后就可以重启网卡:

service network restart

再次ip addr即可看到网络信息:

yum安装报错问题解决方法Cannot find a valid baseurl for repo: base/7/x86_64

参考博客:

https:///qq_41684957/article/details/83345154

这个实际上就是yum源的问题

换个清华园就好了

1、首先备份 CentOS-Base.repo sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2.将yum源配置文件/etc/yum.repos.d/CentOS-Base.repo改为清华源,内容如下:

# CentOS-Base.repo

#

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client.  You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.

#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

3、清除缓存

yum clean all

rm -rf /var/cache/yum/

4、生成缓存

yum makecache

CentOS 安装rz和sz命令 lrzsz

参考博客:

https:///hanchao_h/article/details/79529489

rz & sz 在xshell中常用与文件的收发, 很方便

默认在CentOS中是没有安装的, 需要:

yum -y install lrzsz 

./NVIDIA-Linux-x86_64-460.32.03.run --kernel-source-path=/usr/src/kernels/3.10.0-1160.21.1.el7.x86_64 -k $(uname -r)

CentOS添加系统变量:

参考博客:

https:///f110300641/article/details/82663132

这里以添加CUDA变量为例:

sudo vim /etc/profile

此文件每次用户登录和切换时均会执行, 用于设置环境变量:

在最后添加一下内容:

# CUDA PATh
export PATH=/usr/local/cuda-11.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64:$LD_LIBRARY_PATH
# source /etc/profile

这个变量语法之后在深入学习

因篇幅问题不能全部显示,请点此查看更多更全内容

Top