1.為openlab搭建網(wǎng)站
要求:
給該公司創(chuàng)建三個子界面分別顯示學生信息,教學資料和繳費網(wǎng)站,基于www.openlab.com/student網(wǎng)站訪問學生信息,www.openlab.com/data網(wǎng)站訪問教學資料,www.openlab.com/money網(wǎng)站訪問繳費。
要求:
(1)學生信息網(wǎng)站只有song和tian兩人可以訪問,其他用戶不能訪問。
(2)訪問繳費網(wǎng)站實現(xiàn)數(shù)據(jù)加密基于https訪問。
準備工作
[root@server ~]# systemctl stop firewalld#關閉防火墻 [root@server ~]# setenforce 0#關閉安全軟件selinux [root@server ~]# yum install nginx -y [root@server ~]# yum install httpd -y#安裝相關包
步驟1: 啟動
# 啟動Nginx服務 systemctl start nginx # 設置Nginx開機自啟動 systemctl enable nginx
步驟2: 配置Nginx網(wǎng)站
# 創(chuàng)建并編輯Nginx配置文件 vim /etc/nginx/conf.d/openlab.conf
在打開的文件中添加以下內(nèi)容:
server { ? listen 80; ? server_name www.openlab.com; ? ? location /student { ? ? ? auth_basic "Restricted Access"; ? ? ? auth_basic_user_file /etc/nginx/.htpasswd; ? ? ? ? root /var/www/student; ? ? ? index index.html; ? } ? ? location /data { ? ? ? root /var/www/data; ? ? ? index index.html; ? } } ? server { ? ? ? server_name www.openlab.com; ? ? ? listen 443 ssl; ? ? ? root /var/www/money; ? ? ? ssl_certificate /etc/pki/tls/certs/openlab.crt; ? ? ? ssl_certificate_key /etc/pki/tls/private/openlab.key; ? ? ? location / { ? ? ? } } ?
保存并退出編輯器。
步驟3:創(chuàng)建網(wǎng)站目錄和文件
mkdir -p /www/openlab/student mkdir -p /www/openlab/data mkdir -p /www/openlab/money echo "Welcome to www.openlab.com" > /www/openlab/index.html echo "This is the student page" > /www/openlab/student/index.html echo "This is the data page" > /www/openlab/data/index.html echo "This is the money page" > /www/openlab/money/index.html
步驟:4: 創(chuàng)建用戶
# 創(chuàng)建用戶song useradd song passwd song 更改用戶 song 的密碼 。 新的密碼: 無效的密碼: 密碼少于 8 個字符 重新輸入新的密碼: passwd:所有的身份驗證令牌已經(jīng)成功更新。 ? # 創(chuàng)建用戶tian useradd tian passwd tian 更改用戶 tian 的密碼 。 新的密碼: 無效的密碼: 密碼少于 8 個字符 重新輸入新的密碼: passwd:所有的身份驗證令牌已經(jīng)成功更新。 ?
步驟5: 設置用戶訪問控制
#創(chuàng)建文件夾 mkdir -p /var/www/openlab #設置文件夾權限 chown -R nginx:nginx /var/www/openlab # 創(chuàng)建.htpasswd文件并添加用戶song和tian htpasswd -c /var/www/openlab/.htpasswd song New password: Re-type new password: Adding password for user song htpasswd /var/www/openlab/.htpasswd tian New password: Re-type new password: Adding password for user tian ?
步驟6: 重啟Nginx服務(查看語法錯誤: nginx -t)
# 重啟Nginx服務 systemctl restart nginx
選擇繼續(xù)訪問即可
2.實驗任務: 架設一臺NFS服務器,并按照以下要求配置
1、開放/nfs/shared目錄,供所有用戶查詢資料;
2、開放/nfs/upload目錄,該目錄為172.24.8.0/24網(wǎng)段的主機的數(shù)據(jù)上傳目錄,并將所有該網(wǎng)段主機上傳文件的所屬者和所屬組映射為nfs-upload,其UID和GID為2001;
3、將/home/tom(該目錄為uid=1111,gid=1111的tom用戶的家目錄)目錄僅共享給172.24.8.129這臺主機上的jerry用戶,jerry對該目錄具有訪問、新建和刪除文件的權限。
實驗步驟:
1.安裝對應NFS和RPC的軟件包,關閉防火墻
[root@localhost nfs]# yum install nfs-utils -y
[root@localhost nfs]# yum install rpcbind -y
[root@localhost nfs]# systemctl stop firewalld.service
[root@localhost nfs]# setenforce 0
1、開放/nfs/shared目錄,供所有用戶查詢資料; 進入exports文件中配置文件傳輸?shù)臋嘞?/h4>
[root@localhost tom]# vim /etc/exports /nfs/shared (ro) #號代表可以給所以主機共享
2、開放/nfs/upload目錄,該目錄為172.24.8.0/24網(wǎng)段的主機的數(shù)據(jù)上傳目錄,并將所有該網(wǎng)段主機上傳文件的所屬者和所屬組映射為nfs-upload,其UID和GID為2001; 進入exports配置目錄文件傳輸信息
[root@localhost tom]# vim /etc/exports /nfs/upload 192.168.175.0/24(rw,all_squash,anonuid=2001,anongid=2001)
[root@localhost tom]# vim /etc/exports /nfs/shared (ro) #號代表可以給所以主機共享
[root@localhost tom]# vim /etc/exports /nfs/upload 192.168.175.0/24(rw,all_squash,anonuid=2001,anongid=2001)
創(chuàng)建用戶和設置UID和GID
[root@localhost nfs]# useradd -u 2001 nfs-upload [root@localhost nfs]# id nfs-upload uid=2001(nfs-upload) gid=2001(nfs-upload) groups=2001(nfs-upload)
3、將/home/tom(該目錄為uid=1111,gid=1111的tom用戶的家目錄)目錄僅共享給192.168.175.133這臺主機上的jerry用戶,jerry對該目錄具有訪問、新建和刪除文件的權限。 進入exports配置目錄文件傳輸信息
[root@localhost tom]# vim /etc/exports /home/tom 192.168.175.133(rw)
添加tom用戶查看用戶信息
[root@localhost nfs]# useradd -u 1111 tom
[root@localhost nfs]# ll /home/ total 4
drwx------. 3 nfs-upload nfs-upload 78 Aug 11 15:48 nfs-upload
drwx------. 15 redhat redhat 4096 Jul 15 14:29 redhat
drwx------. 3 tom tom 78 Aug 11 16:17 tom
drwx------. 3 nfs-upload nfs-upload 78 Aug 11 15:46 ufs-upload
重啟服務即可
[root@localhost nfs]# systemctl restart rpcbind
[root@localhost nfs]# systemctl restart nfs-server.service
在另外用戶上創(chuàng)建jerry用戶并且UID和GID同為1111,掛載到本地
[root@localhost upload]# useradd jerry -u 1111
[root@localhost nfs]# mount 192.168.175.129:/home/tom tom/
[root@localhost nfs]# ll total 0
drwxr-xr-x. 2 root root 20 Aug 11 15:40 shared
drwx------. 3 jerry jerry 78 Aug 11 16:17 tom
drwxr-xrwx. 2 root root 32 Aug 11 16:10 upload
最后在客戶機上測試Jerry用戶進入tom目錄增刪改查
[root@localhost nfs]# su - jerry
[jerry@localhost ~]$ cd /nfs/
[jerry@localhost nfs]$ ll
total 0
drwxr-xr-x. 2 root root 20 Aug 11 15:40 shared
drwx------. 3 jerry jerry 78 Aug 11 16:17 tom
drwxr-xrwx. 2 root root 32 Aug 11 16:10 upload
[jerry@localhost nfs]$ cd tom/
[jerry@localhost tom]$ touch file
[jerry@localhost tom]$ ll
total 0
-rw-rw-r--. 1 jerry jerry 0 Aug 11 16:33 file文章來源:http://www.zghlxwxcb.cn/news/detail-793132.html
-rw-r--r--. 1 root root 0 Aug 11 16:44 server文章來源地址http://www.zghlxwxcb.cn/news/detail-793132.html
到了這里,關于為openlab搭建網(wǎng)站和架設一臺NFS服務器的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!