RHCE作业2

1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于[www.openlab.com/student](http://www.openlab.com/student) 网站访问学生信息,[www.openlab.com/data](http://www.openlab.com/data)网站访问教学资料,网站访问缴费网站(http://www.openlab.com/money网站访问缴费网站)。

3.要求 (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。

实验步骤:

第一步环境配置:web服务是基于cs架构实现的,因此我们需要用两台Linux主机,一台充当服务器,一台充当客户机。我们这里用一台ip地址为192.168.23.129的openeuler系统的主机充当服务器,另一台IP地址为192.168.23.128红帽系统的充当客户机,我们这里方便书写,我们称服务机为serve,客户机为client,并且我们通过修改/etc/hostname文件修改主机名,并用reboot命令重启系统使其生效。

[root@xsl ~]# cd /etc/
[root@xsl etc]# vi hostname
[root@xsl etc]# reboot

第二步:我们在serve上配置web服务,首先关闭防火墙

systemctl stop firewalld

第三步:安装nginx

yum install nginx -y

 第四步:在防火墙规则中添加web服务器可以处理http和https服务的命令,并使用permanent使其永久生效.

firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent

第五步:编辑配置文件

server {
    listen 80;
    server_name www.openlab.com;
    root /var/www/openlab;

    location / {
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    location /student/ {
        alias /var/www/openlab/student/;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    location /data/ {
        alias /var/www/openlab/data/;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    location /money/ {
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

第6步创建刚刚需要的文件:

mkdir -p /var/www/openlab/{student,data,money}
touch /var/www/openlab/index.html
echo "welcome to openlab!!!" > /var/www/openlab/index.html
touch /var/www/openlab/data/index.html
touch /var/www/openlab/money/index.html
echo this is money > /var/www/openlab/money/index.html
echo this is data > /var/www/openlab/data/index.html
echo this is student > /var/www/openlab/student/index.html

这里用双引号取消!执行上一条命令,也可以用反斜杠\,在编写完后可以用cat命令查看是否有误,有问题直接vim改

第七步更改SElinux:#chcon  -a -t httpd_sys_content_t /www/ -R 

chcon -t httpd_sys_content_t /var/www -R

 请注意chcon并没有-a选项

第八步完成要求三,先安装httpd-tools 

yum install http-tools -y

然后通过使用 htpasswd 工具创建一个新的密码文件,并为用户名 song 添加密码,-c 表示创建新的密码文件,如果该文件已存在,则会被覆盖。

[root@serve openlab]# htpasswd -c /etc/nginx/user song
New password: 
Re-type new password: 
Adding password for user song

 添加需要的第二个用户

[root@serve openlab]# htpasswd /etc/nginx/user tian
New password: 
Re-type new password: 
Adding password for user tian

 第九步创建安全证书:

 

  1. openssl genrsa -out /etc/pki/tls/private/openlab.key:这条命令使用 OpenSSL 工具生成一个 RSA 密钥对,其中私钥保存在 /etc/pki/tls/private/openlab.key 文件中。私钥是保密的,用于对数据进行加密和解密。

  2. openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt:这条命令使用生成的私钥文件 /etc/pki/tls/private/openlab.key 创建一个自签名的证书请求。 -utf8 选项表示使用 UTF-8 编码,-new 表示创建新的证书请求,-key 指定私钥文件的路径,-x509 表示生成自签名的 X.509 格式证书,-days 365 表示证书的有效期为一年,-out 指定生成的证书文件路径为 /etc/pki/tls/certs/openlab.crt

  3. openssl genrsa -out /etc/pki/tls/private/openlab.key
    [root@serve openlab]# openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key  -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt 

    测试用curl命令访问对应域名

  4. 这里前面money的路径如果是手动配置的要改,不能和明文的一样

2.架设一台NFS服务器,并按照以下要求配置
1、开放/nfs/shared目录,供所有用户查询资料
2、开放/nfs/upload目录,为192.168.xxx.0/24网段主机可以上传目录,
并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210
3、将/home/tom目录仅共享给192.168.xxx.xxx这台主机,并只有用户tom可以完全访问该目录

第一步安装服务:

yum install nfs-utils -y

 第二步创建共享目录并开放权限:

[root@serve /]# mkdir -pv /nfs/{shared,upload}
mkdir: 已创建目录 '/nfs'
mkdir: 已创建目录 '/nfs/shared'
mkdir: 已创建目录 '/nfs/upload'
mkdir -pv /home/tom
chown nobody:nobody /nfs/shared
chown nobody:nobody /nfs/upload
[root@serve /]# chown nobody:nobody /home/tom
[root@serve /]# chmod 777 /nfs/shared
[root@serve /]# chmod 777 /nfs/upload
[root@serve /]# chmod 777 /home/tom

第三步配置NFS服务器:

vi /etc/exports
/nfs/shared *(ro,sync,no_subtree_check)
/nfs/upload 192.168.23.0/24(rw,sync,no_subtree_check,all_squash,anonuid=210,anongid=210)
/home/tom 192.168.23.129(rw,sync,no_subtree_check)

第四步启动配置:

[root@serve /]# systemctl enable nfs-server
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.

  • 7
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值