第二次作业

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)网站访问教学资[www.openlab.com/money网站访问缴费网站](http://www.openlab.com/money网站访问缴费网站)。

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

​            (2)访问缴费网站实现数据加密基于https访问。

服务端
 
#创建需要目录
 
[root@server ~]# mkdir -pv /nfs/shared /nfs/upload /home/tom
mkdir: 已创建目录 '/nfs'
mkdir: 已创建目录 '/nfs/shared'
mkdir: 已创建目录 '/nfs/upload'
mkdir: 已创建目录 '/home/tom'
 
启用nfs服务
[root@server ~]# systemctl start nfs-server.service
#创建文件
[root@server ~]# touch /nfs/shared/{a..d}
[root@server ~]# touch /nfs/upload/{1..4}
 
#编辑配置文件
[root@server ~]# vim /etc/exports
/nfs/shared   *(ro)
/nfs/upload   192.168.1.0/24(rw,no_all_squash,anonuid=210,anongid=210)
/home/tom     192.168.1.130(ro)
 
#启用配置文件
[root@server ~]# exportfs -r
#因为客服户端要对/nfs/upload进行上传文件,因此要在服务端提权限,否则客户端创建文件权限不够
[root@server ~]# chmod o+w /nfs/upload
 
[root@server ~]# systemctl  restart nfs-server.service
 
 
客户端
 
#查看服务端的共享文件
[root@client ~]# showmount -e 192.168.1.130
Export list for 192.168.1.130:
/nfs/shared *
/nfs/upload 192.168.1.0/24
/home/tom   192.168.1.130
 
#创建目录
[root@client ~]# mkdir /mnt
[root@client mnt]# mkdir /mnt1
 
#挂载
[root@client ~]# mount 192.168.1.130:/nfs/shared  /mnt
[root@client ~]# ll /mnt
总计 0
-rw-r--r--. 1 root root 0  1月14日 16:54 a
-rw-r--r--. 1 root root 0  1月14日 16:54 b
-rw-r--r--. 1 root root 0  1月14日 16:54 c
-rw-r--r--. 1 root root 0  1月14日 16:54 d
 
[root@client mnt]# mount 192.168.1.130:/nfs/upload  /mnt1
[root@client mnt]# cd /mnt1
[root@client mnt1]# ll
总计 0
-rw-r--r--. 1 root root 0  1月14日 16:54 1
-rw-r--r--. 1 root root 0  1月14日 16:54 2
-rw-r--r--. 1 root root 0  1月14日 16:54 3
-rw-r--r--. 1 root root 0  1月14日 16:54 4
 
#上传文件,并且文件的用户和组映射为指定的UID,GID
[root@client mnt1]# touch 5
[root@client mnt1]# ll
总计 0
-rw-r--r--. 1 root root 0  1月14日 16:54 1
-rw-r--r--. 1 root root 0  1月14日 16:54 2
-rw-r--r--. 1 root root 0  1月14日 16:54 3
-rw-r--r--. 1 root root 0  1月14日 16:54 4
-rw-r--r--. 1  210  210 0  1月14日 17:12 5
 
 

3.架设一台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可以完全访问                        该目录

#准备工作,关闭防火墙
 
[root@server ~]# systemctl stop firewalld
[root@server ~]# setenforce 0
 
#下载nginx软件包
[root@server ~]#yum install nginx -y
 
#编辑配置文件
[root@server ~]# vim /etc/nginx/conf.d/test_name.conf
server{
        listen 192.168.129.133:80;
        root /www/name/openlab;
        server_name www.openlab.com;
        location / {
        }
}
 
[root@server ~]# vim /www/name/openlab/index.html
 
#创建相应需要目录
[root@server ~]# cd /etc/nginx
[root@server nginx]# cd
[root@server ~]# mkdir -pv /www/name/openlab
mkdir: 已创建目录 '/www'
mkdir: 已创建目录 '/www/name'
mkdir: 已创建目录 '/www/name/openlab'
 
 
#添加本地域名
[root@server ~]# cat /etc/hosts
192.168.129.133 www.openlab.com
 
 
#第2题的配置文件
[root@server ~]#cat /etc/nginx/conf.d/test1_name.conf
server{
        listen 192.168.129.133:80;
        root /www/name/openlab;
        server_name www.openlab.com;
        location /student{
                index index.html;
                auth_basic on;
                auth_basic_user_file /etc/nginx/users;
        }
 
 
        location /data{
 
        }
 
}
 
 
#创建相应目录
[root@server ~]# cd /www/name/openlab
[root@server openlab]# mkdir -pv {student,data,money}
mkdir: 已创建目录 'student'
mkdir: 已创建目录 'data'
mkdir: 已创建目录 'money'
 
#写入内容
[root@server openlab]# echo this is student > /www/name/openlab/student/index.html
[root@server openlab]# echo this data > /www/name/openlab/data/index.html
[root@server openlab]# echo this money > /www/name/openlab/money/index.html
 
 
#安装httpd工具包
[root@server ~]# yum install httpd-tools
 
#用户认证
[root@server ~]# htpasswd -c /etc/nginx/users song
New password:
Re-type new password:
Adding password for user song
[root@server ~]# htpasswd -c /etc/nginx/users tian
New password:
Re-type new password:
Adding password for user tian
 
第3题配置文件
[root@server ~]# vim /etc/nginx/conf.d/test_https.conf
server{
        listen 192.168.129.133:443 ssl;
        root /www/name/openlab;
        server_name www.openlab.com;
        ssl_certificate /etc/pki/tls/certs/openlab.crt;
        ssl_certificate_key /etc/pki/tls/private/openlab.key;
        location /money{
        }
}
 
#进行https访问配置
[root@server ~]# openssl genrsa -out /etc/pki/tls/private/openlab.key
[root@server ~]# openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:86
State or Province Name (full name) [Some-State]:xi'an
Locality Name (eg, city) []:shanxi
Organization Name (eg, company) [Internet Widgits Pty Ltd]:open
Organizational Unit Name (eg, section) []:ce
Common Name (e.g. server FQDN or YOUR name) []:1111
Email Address []:admin
[root@server ~]# curl https://www.openlab.com/money/
curl: (7) Failed to connect to www.openlab.com port 443 after 1 ms: Couldn't connect to server
[root@server ~]# systemctl restart nginx
[root@server ~]# curl https://www.openlab.com/money/
curl: (60) SSL certificate problem: self-signed certificate
More details here: https://curl.se/docs/sslcerts.html
 
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
 
 
测试
[root@server ~]# curl www.openlab.com
welcome to openlab!!!
 
 
[root@server ~]# curl www.openlab.com/student/ -u song
Enter host password for user 'song':
this is student
 
 
[root@server ~]# curl https://www.openlab.com/money/ -k
this money
  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,我来为您解答。 首先,我们需要在布局文件中添加一个 RelativeLayout 控件: ```xml <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 这里添加九宫格子的布局 --> </RelativeLayout> ``` 然后,我们需要在 RelativeLayout 中添加九宫格子的布局。这里我们采用 ImageView 控件作为九宫格子,每个格子的大小相同,可以采用权重的方式实现。 ```xml <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/image1" android:layout_width="0dp" android:layout_height="0dp" android:layout_margin="5dp" android:layout_centerInParent="true" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_weight="1" android:src="@drawable/image1" /> <ImageView android:id="@+id/image2" android:layout_width="0dp" android:layout_height="0dp" android:layout_margin="5dp" android:layout_centerInParent="true" android:layout_alignParentTop="true" android:layout_toRightOf="@id/image1" android:layout_toEndOf="@id/image1" android:layout_weight="1" android:src="@drawable/image2" /> <ImageView android:id="@+id/image3" android:layout_width="0dp" android:layout_height="0dp" android:layout_margin="5dp" android:layout_centerInParent="true" android:layout_alignParentTop="true" android:layout_toRightOf="@id/image2" android:layout_toEndOf="@id/image2" android:layout_weight="1" android:src="@drawable/image3" /> <ImageView android:id="@+id/image4" android:layout_width="0dp" android:layout_height="0dp" android:layout_margin="5dp" android:layout_centerInParent="true" android:layout_below="@id/image1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_weight="1" android:src="@drawable/image4" /> <ImageView android:id="@+id/image5" android:layout_width="0dp" android:layout_height="0dp" android:layout_margin="5dp" android:layout_centerInParent="true" android:layout_below="@id/image2" android:layout_toRightOf="@id/image4" android:layout_toEndOf="@id/image4" android:layout_weight="1" android:src="@drawable/image5" /> <ImageView android:id="@+id/image6" android:layout_width="0dp" android:layout_height="0dp" android:layout_margin="5dp" android:layout_centerInParent="true" android:layout_below="@id/image3" android:layout_toRightOf="@id/image5" android:layout_toEndOf="@id/image5" android:layout_weight="1" android:src="@drawable/image6" /> <ImageView android:id="@+id/image7" android:layout_width="0dp" android:layout_height="0dp" android:layout_margin="5dp" android:layout_centerInParent="true" android:layout_below="@id/image4" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_weight="1" android:src="@drawable/image7" /> <ImageView android:id="@+id/image8" android:layout_width="0dp" android:layout_height="0dp" android:layout_margin="5dp" android:layout_centerInParent="true" android:layout_below="@id/image5" android:layout_toRightOf="@id/image7" android:layout_toEndOf="@id/image7" android:layout_weight="1" android:src="@drawable/image8" /> <ImageView android:id="@+id/image9" android:layout_width="0dp" android:layout_height="0dp" android:layout_margin="5dp" android:layout_centerInParent="true" android:layout_below="@id/image6" android:layout_toRightOf="@id/image8" android:layout_toEndOf="@id/image8" android:layout_weight="1" android:src="@drawable/image9" /> </RelativeLayout> ``` 在上述布局中,我们使用了 `android:layout_weight` 属性来实现九宫格子的等分布局,每个 ImageView 控件的权重都设置为 1,这样每个格子的大小就相等了。同时,我们使用了 `android:layout_centerInParent` 属性来使每个格子都居中显示,使用了 `android:layout_alignParentTop` 和 `android:layout_alignParentLeft`(或 `android:layout_alignParentStart`)属性来使第一个格子位于 RelativeLayout 控件的左上角,使用了 `android:layout_below`、`android:layout_toRightOf` 和 `android:layout_toEndOf` 属性来设置每个格子的位置。 最后,我们可以在 Java 代码中获取每个 ImageView 控件,并为它们设置点击事件,以实现九宫格的功能。 ```java ImageView image1 = findViewById(R.id.image1); ImageView image2 = findViewById(R.id.image2); ImageView image3 = findViewById(R.id.image3); ImageView image4 = findViewById(R.id.image4); ImageView image5 = findViewById(R.id.image5); ImageView image6 = findViewById(R.id.image6); ImageView image7 = findViewById(R.id.image7); ImageView image8 = findViewById(R.id.image8); ImageView image9 = findViewById(R.id.image9); image1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 处理第一个格子的点击事件 } }); image2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 处理第二个格子的点击事件 } }); // 其他格子的点击事件同理 ``` 好了,以上就是使用相对布局实现九宫格的方法。希望对您有帮助!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fatsheep洋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值