linux的练习题
1、配置虚拟机的ip地址为 192.168.5.128/24 网关为 192.168.5.2 DNS 服务器地址为 192.168.1.2, 设置网络地址获取方式为手动,并开机有效
nmcli connection modify ens160 ipv4.addresses 192.168.5.128/24
nmcli connection modify ens160 ipv4.gateway 192.168.5.2
nmcli connection modify ens160 ipv4.dns 192.168.1.2
nmcli connection modify ens160 ipv4.method manual
nmcli connection modify ens160 connection.autoconnect yes
nmcli connection up ens160 会话生效
注意 :如果使用xshell连接,跟windows的vmnet8网卡不在一个网段,xshell就连接不起了
2、配置iso镜像作为本地仓库,然后安装 httpd 软件包,并启动 httpd 服务,让该服务开机自动启动
mount /dev/sr0 /mnt 首先开始挂载
vim /etc/yum.repos.d/local.repo 写yum源仓库 ,文件以。repo结尾
[localrepo]
name=localrepo
baseurl = /mnt/AppStream
enabled = 1
gpgcheck = 0
保存退出
yum -y install httpd 安装http服务
systemctl enable httpd 开机启动该服务
3、配置上面web服务的默认页面为 /exam/index.html,该页面内容在访问的时候显示为 Welcome to test。
systemctl status firewalld.service 检查防火墙状态
如果防火墙开着,可以去放行httpd服务。省事的话可以把防火墙关了
systemctl stop firewalld.service 关闭 防火墙
vim /etc/httpd/conf.d/vhost.conf 自己写一个配置文件
<directory /exam>
allowoverride none
require all granted
</directory>
<virtualhost 0.0.0.0:80> 允许任何主机以80端口访问
servername 192.168.85.129 自己主机的IP地址
documentroot /exam
</virtualhost>
保存退出
setenforce 0 转换为Permissive宽容模式 selinux的内容
mkdir /exam 创建/exam目录
echo Welcome to test > /exam/index.html 重定向写内容
systemctl restart httpd.service 重新启动httpd服务
完成!
4、配置防火墙和 SELinux ,使其可以通过其他主机正常访问该web服务和页面。
上面我们是通过关闭防火墙来访问的,这题我们要配置防火墙
systemctl enable firewalld.service 开机防火墙就会自动打开
systemctl start firewalld.service 打开防火墙
firewall-cmd --list-all 查看防火墙的配置,没有放行就放行
firewall-cmd --add-service=http --permanent 放行http服务
systemctl restart firewalld.service 重新加载防火墙
setenforce 1 打开之后又不能访问该页面了,上一题我们是直接关闭的,这题打开就要做配置,这是一种强制验证,不匹配就不让你访问
getenforce 查看当前selinux的模式,如果是Enforcing就对了
ll -Z /var/www/html/ 查看httpd服务默认访问的目录的标记,object_r:后面就是这个文件目录的标记
chcon -t httpd_sys_content_t /exam -R 把/exam这个目录的标记改成 /var/www/html/一样的
完成!
5、该 web 服务默认页面所在的目录 /exam 在开机的时候自动挂载 由 卷组 examgroup 提供的逻辑卷 lvexam。
6、该卷组 examgroup 由 /dev/sda 和 /dev/nvme0n2 两块磁盘创建,该卷组 PE 大小为 16Mb,而逻辑卷为 50个PE 大小。
5-6题一起。
物理卷可以通过分区或者设备来创建
pvcreate /dev/nvme0n2
pvcreate /dev/sda
vgcreate -s 16M examgroup /dev/sda /dev/nvme0n2 创建卷组,指定pe大小为16Mb
vgdisplay 可以查看
lvcreate -n lvexam -l 50 examgroup 创建的逻辑卷 大小为50*16mb
mkfs.xfs /dev/examgroup/lvexam 格式化文件系统
mount /dev/examgroup/lvexam /exam/ 挂载到/exam目录文件
vim /etc/fstab 写永久挂载配置,开机自动挂载
/dev/examgroup/lvexam /exam xfs defaults 0 0
保存退出!
注意:这个时候/exam目录的会被清空,重新创建index.html文件,然后可以通过关闭selinux或者给该目录加上默认标记
7、在系统中创建用户 exam,使其 UID 和 GID 为 4000,该用户的密码为 exampassword。
useradd exam -u 4000
passwd exam
exampassword
8、同时在系统创建用户 test,使其基本组为 40000,该用户在 /exam/ 目录中创建文件,名称为 test.exam,该文件将被配置为 exam 对其没有任何权限,而除 exam 用户外,其他所有用户对该文件拥有所有权限。
useradd test -g 4000
passwd test
testpassword
touch /exam/test.exam
chmod 777 /exam/test.exam 所有权限
setfacl -m g:exam:- /exam/test.exam exam没有权限