Linux—Redhat小题训练(一)

一、配置网络设置

方法一:使用Redhat的网络配置图形化界面

1、打开网络配置图形界面

nmtui

方法二:使用命令配置

2、手动配置

hostnamectl set-hostname 主机名

3、使新配置的网络生效

(方法1)

nmcli connection up 'Wired connection 1'

(方法2)

nmcli connection modify 'Wired connection 1' ipv4.method manual ipv4.addresses '172.25.250.10/24' ipv4.gateway '172.25.250.254' ipv 4.dns 172.25.250.254 connection.autoconnect yes

二、配置默认存储库(YUM存储库)

配置步骤:

1、进入存储库所在的位置

cd /etc/yum.repos.d

2、创建一个yum源配置文件,以repo后缀结尾

vim 自命名文件名.repo

3、编写yum源配置文件

#编辑test.repo

#点击i进入编辑模式

#开始编辑,按照此模板

[ ]

name=

baseurl=

enabled=1

gapcheck=0

[ ]

name=

baseurl=

enabled=1

gpgcheck=0

#按esc退出编辑模式

#保存并退出命令模式

方式一 

:wq

方式二

shift+连续按两次Z

题:将以下位置作为默认存储库

#http://content/rhel8.0/x86_64/dvd/BaseOS

#http://content/rhel8.0/x86_64/dvd/AppStream 

[BaseOS]
name=BaseOS

baseurl=http://content/rhel8.0/x86_64/dvd/BaseOS

enabled=1

gpgcheck=0

[AppStream]

name=AppSteam

baseurl=http://content/rhel8.0/x86_64/dvd/AppStream

enabled=1

gpgcheck=0

三、调试Selinux

1、查看现有的端口

semanage port -l 

2、查看某一类型的端口(如http)

semanage port -l | grep http

3、下载WEB服务器(如httpd)

yum install httpd

4、查看当前使用的端口号

vim /etc/httpd/conf/httpd.conf

5、添加端口(如82)

semanage port -a -t http_port_t -p tcp 82

6、在/var/www/html目录下创建文件

cd /var/www/html

touch file

7、查看文件的selinux上下文

ls -Z

8、添加文件上下文类型

semanage fcontext -a -t httpd_sys_content_t "/var/www/html/file"

9、修改文件上下文类型

semanage fcontext -m -t httpd_sys_content_t "/var/www/html/file"

10、保持新修改/添加的文件上下文

restorecon -v /var/www/html/file

11、查看文件上下文是否生效

curl http://node:82/file       (当前使用root@nodecaoz)

四、查找文件(并将其复制到另一个文件夹中)

命令:

1)先创建存放复制文件的文件夹

mkdir 文件夹名

2)执行查找文件并将其复制到另一个文件夹中操作

find 查找的文件全路径 -user 文件的拥有者 -exec cp -a {} 存放复制文件的位置 \;

五、查找字符串

命令    grep 字符串 字符串所在的文件夹 > 字符串存放的文件夹

例:查找/root/file中的user字符串并将其存放到/home/newfile中

grep user /root/file > /home/newfile

猜你喜欢

转载自blog.csdn.net/qq_53376718/article/details/129936380