(1)首先需要进行安装mod_ssl,(mod_ssl是一种以openssl工具箱为基础的专门为qpache webserver提供密码保护的软件)
[root@rhce-128 ~]# yum install -y mod_ssl# 创建一个目录,ssl要访问的目录,index.html
[root@rhce-128 conf.d]# cd /www/ [root@rhce-128 www]# ls ip port [root@rhce-128 www]# mkdir myssl [root@rhce-128 www]# cd myssl/ [root@rhce-128 myssl]# echo this is my first https page > index.html [root@rhce-128 myssl]# ls index.html [root@rhce-128 myssl]# cat index.html this is my first https page [root@rhce-128 myssl]## 设置目录的权限;
<Directory "/www/myssl"> AllowOverride None Require all granted Directory># 设置虚拟主机;需要用到Ip,最好自己进行设置;
<Directory "/www/myssl"> AllowOverride None Require all granted Directory> #Listen 443192.168.188.140:443> SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateKeyFile /etc/pki/tls/private/localhost.key DocumentRoot "/www/myssl" ServerName 192.168.188.128#:配置好文件后,将服务进行重启:
[root@rhce-128 private]# systemctl restart httpd#//:这里有个最最最重要的问题就是,Linux的版本问题,如果你是Centos8以下的版本,你再配置是一定要按照自己的ssl.conf文件中的要求进行配置;
我的是CentOS7b版本:
SSLProtocol all -SSLv2 -SSLv3 # SSL Cipher Suite: # List the ciphers that the client is permitted to negotiate. # See the mod_ssl documentation for a complete list. SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA# :进行完一系列的配置之后,去浏览器访问,结果如下:
(1):首先进入到 /var/www/cgi-bin 创建一个test.cgi文件写入一下内容;
[root@rhcsa cgi-bin]# cat test.cgi #!/bin/bash printf "Content-Type: text/html;charset=utf-8\n\n"; printf "Hello, World."; [root@rhcsa cgi-bin]#(2):修改test.cgi 文件的权限,因为Linux中的文件在浏览器中去访问,浏览器被当做其他用户,所以必须添加访问权限才可以正常去访问;先来看一下初始的权限和访问结果:
[root@rhcsa cgi-bin]# ll total 4 -rw-r--r--. 1 root root 88 Jul 30 21:56 test.cgi访问结果:
修改文件的权限:
[root@rhcsa cgi-bin]# chmod 755 test.cgi [root@rhcsa cgi-bin]# ll total 4 -rwxr-xr-x. 1 root root 88 Jul 30 21:56 test.cgi [root@rhcsa cgi-bin]#访问结果如下:
a、开放/nfs/shared目录,供所有用户查询资料;
(1):首先安装 rpcbind和nfs-utils这两个软件:
[root@rhce-128 ~]# yum install rpcbind nfs-utils -y(2):创建、/nfs/shared目录,并且在nfs主配置文件中进行配置,
[root@rhce-128 conf]# mkdir -p /nfs/shared [root@rhce-128 ~]# cd /nfs/shared [root@rhce-128 shared]# touch file{1..3} [root@rhce-128 shared]# echo 111 > file1 [root@rhce-128 shared]# echo 222 > file2 [root@rhce-128 shared]# echo 333 > file3 [root@rhce-128 shared]# ll total 12 -rw-r--r--. 1 root root 4 Jul 31 21:06 file1 -rw-r--r--. 1 root root 4 Jul 31 21:07 file2 -rw-r--r--. 1 root root 4 Jul 31 21:07 file3 [root@rhce-128 shared]# cat file1 111 [root@rhce-128 shared]# cat file2 222 [root@rhce-128 shared]# cat file3 333 [root@rhce-128 shared]# [root@rhce-128 ~]# cat /etc/exports /nfs/shared *(ro)(3):启用服务,一定要先启用rpcbind,再启用nfs服务,
[root@rhce-128 shared]# systemctl restart rpcbind [root@rhce-128 shared]# systemctl restart nfs [root@rhcsa data]# systemctl restart nfs-server [root@rhce-128 shared]#(4):启动另一台虚拟机作为客户机,访问我们这台服务器主机:
#:首先查看是否可以查询到服务器的共享目录:
[root@rhcsa ~]# showmount -e 192.168.188.128 Export list for 192.168.188.128: /nfs/shared * [root@rhcsa ~]#(5):挂载服务器的目录到本机,注意服务器上的目录权限,不可为只读,设置744权限的话,挂载完成之后无法进入目录,提示权限不够,所以这里服务器的目录设置为755即可,因为在设置、nfs/exports主配置时,设置的是ro权限,所以值能查看文件,不能修改;
[root@rhcsa ~]# mkdir /data [root@rhcsa ~]# mount 192.168.188.128:/nfs/shared /data/ [root@rhcsa ~]# cd /data/ [root@rhcsa data]# ll total 12 -rw-r--r--. 1 root root 4 Jul 31 2022 file1 -rw-r--r--. 1 root root 4 Jul 31 2022 file2 -rw-r--r--. 1 root root 4 Jul 31 2022 file3 [root@rhcsa data]# cat file1 111 [root@rhcsa data]##:做到这里就实现了开放/nfs/shared目录,供所有用户查询资料
#:若要对目录的资源进行更新,则可以使用 exportfs -a
b、开放/nfs/upload目录,该目录为192.168.xxx.0/24网段的主机的数据上传目录,并将所有该网段主机上传文件的所属者和所属组映射为nfs-upload,其UID和GID为2001;
(1):创建共享目录,并修改文件权限:
[root@rhce-128 nfs]# mkdir upload [root@rhce-128 nfs]# ll total 0 drwxrwxrwx. 2 root root 45 Jul 31 22:07 shared drwxr-xr-x. 2 root root 6 Jul 31 22:36 upload [root@rhce-128 nfs]# chmod 755 upload/ [root@rhce-128 nfs]# ll total 0 drwxrwxrwx. 2 root root 45 Jul 31 22:07 shared drwxr-xr-x. 2 root root 6 Jul 31 22:36 upload [root@rhce-128 nfs]#(2):配置主文件,创建用户且指定UID,GID并重新加载资源:
[root@rhce-128 /]# cat /etc/exports /nfs/upload 192.168.188.0/24(rw,anonuid=2001,anongid=2001) [root@rhce-128 upload]# useradd -u 2001 nfs-upload [root@rhce-128 upload]# tail -1 /etc/passwd nfs-upload:x:2001:2001::/home/nfs-upload:/bin/bash [root@rhce-128 /]# exportfs -r [root@rhce-128 /]#(3):在客户机进行挂载并测试,先给服务器目录操作权限:
[root@rhce-128 nfs]# chmod 777 upload/ [root@rhce-128 nfs]# exportfs -a# :客户端测试:
[root@rhcsa ~]# showmount -e 192.168.188.128 Export list for 192.168.188.128: /nfs/upload 192.168.188.0/24 [root@rhcsa ~]# mount 192.168.188.128:/nfs/upload /data/ [root@rhcsa ~]# cd /data/ [root@rhcsa data]# ls file1 [root@rhcsa data]# ll total 4 -rw-r--r--. 1 root root 13 Aug 1 09:17 file1 [root@rhcsa data]# echo this is file2 > file2 [root@rhcsa data]# ll total 8 -rw-r--r--. 1 root root 13 Aug 1 09:17 file1 -rw-r--r--. 1 2001 2001 14 Aug 1 09:20 file2 [root@rhcsa data]##:服务器结果显示:
[root@rhce-128 nfs]# ll upload/ total 8 -rw-r--r--. 1 root root 13 Aug 1 09:17 file1 -rw-r--r--. 1 nfs-upload nfs-upload 14 Aug 1 09:20 file2 [root@rhce-128 nfs]#
c、将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享192.168.xxx.130这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的权限。
(1):在服务端上创建用户tom,且用户UID和GID分别为1111,在客户端创建用户jerry,
# 服务端:
[root@rhce-128 home]# useradd -u 1111 tom [root@rhce-128 home]# ll total 0 drwx------. 2 tom tom 62 Aug 1 09:30 tom [root@rhce-128 home]# tail -1 /etc/passwd tom:x:1111:1111::/home/tom:/bin/bash [root@rhce-128 home]# chmod 777 tom/ [root@rhce-128 home]# ll total 0 drwx------. 2 nfs-upload nfs-upload 62 Aug 1 09:15 nfs-upload drwxrwxrwx. 2 tom tom 74 Aug 1 09:37 tom [root@rhce-128 home]# exportfs -a# 客户端:
[root@rhcsa data]# useradd jerry [root@rhcsa data]# tail -1 /etc/passwd jerry:x:1008:1012::/home/jerry:/bin/bash [root@rhcsa data]# showmount -e 192.168.188.128 Export list for 192.168.188.128: /home/tom 192.168.188.130 [root@rhcsa /]# cd /data/ [root@rhcsa data]# ll total 0 -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe [root@rhcsa data]# su - jerry [jerry@rhcsa ~]$ cd /data/ [jerry@rhcsa data]$ ll total 0 -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe [jerry@rhcsa data]$ touch haha [jerry@rhcsa data]$ ll total 0 -rw-rw-r--. 1 jerry jerry 0 Aug 1 09:41 haha -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe [jerry@rhcsa data]$ rm -rf haha [jerry@rhcsa data]$ ll total 0 -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe [jerry@rhcsa data]$ echo hehe > hehe -bash: hehe: Permission denied [jerry@rhcsa data]$
远程nfs服务器要的目录为/nfs/autofs
客户端的的挂载目录/data/autofs
且设置自动卸载时间为60秒
(1):创建服务器端的目录 /nfs/autofs ,客户端挂载目录为:/data/autofs
#:服务端:指定autofs目录的权限,并创建挂载目录在主配置文件中:
[root@rhce-128 nfs]# mkdir autofs [root@rhce-128 nfs]# chmod o+w /nfs/autofs/ [root@rhce-128 nfs]# ll total 0 drwxr-xrwx. 2 root root 6 Aug 1 09:46 autofs drwxrwxrwx. 2 root root 45 Jul 31 22:07 shared drwxrwxrwx. 2 root root 32 Aug 1 09:20 upload [root@rhce-128 nfs]# vim /etc/exports [root@rhce-128 nfs]# exportfs -a [root@rhce-128 nfs]# cat /etc/exports /home/tom 192.168.188.130(rw) /nfs/autofs *(rw) [root@rhce-128 nfs]##客户端:挂载是在客户端上进行的,会持续检测目录,访问时,自动挂载,所以需要先在客户端安装软件autofs,然后再到 /etc/auto.master文件中进行配置,
[root@rhcsa /]# mkdir /data/autofs [root@rhcsa data]# yum install -y autofs.x86_64 [root@rhcsa data]# vim /etc/auto.master ------------------------- # /data /etc/autofs /misc /etc/auto.misc # ------------------------- [root@rhcsa data]# vim /etc/auto.data // 配置挂载目录中的挂载对象; [root@rhcsa data]# cat /etc/auto.data autofs -fstype=nfs,rw 192.168.188.128:/nfs/autofs [root@rhcsa data]##:超时时间设置:下面可以看到等待时间太长,所以我们可以调整一下超时时间;
--------------- # timeout = 300 # -------------- // 这里的单位是秒 # timeout = 60 # --------------#重启服务:验证结果:
[root@rhcsa data]# systemctl restart autofs [root@rhcsa data]# ll total 0 drwxr-xr-x. 2 nfsnobody nfsnobody 6 Aug 1 09:48 autofs -rw-r--r--. 1 root root 0 Aug 1 09:37 hehe [root@rhcsa data]## :可以看到文件以及自动挂载成功:
(1):首先前提是可以正常使用https协议访问,然后生成RSA私钥以及自签名证书:
[root@rhce-128 ~]# openssl req -newkey rsa:2048 -nodes -keyout rsa_private.key -x509 -days 36500 -out cert.crt Generating a 2048 bit RSA private key .................+++ ..........................+++ writing new private key to 'rsa_private.key' ----- 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) [XX]:cn State or Province Name (full name) []:shanxi Locality Name (eg, city) [Default City]:xian Organization Name (eg, company) [Default Company Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []:128 Email Address []:#:默认放到了root目录下:
[root@rhce-128 ~]# ll /root total 24 -rwxr-xr-x. 1 root root 110 Aug 1 10:48 1.sh -rw-------. 1 root root 1736 Jun 3 10:05 anaconda-ks.cfg -rw-r--r--. 1 root root 1285 Aug 1 12:08 cert.crt -rw-r--r--. 1 root root 1708 Aug 1 12:08 rsa_private.key drwxr-xr-x. 3 root root 68 Jun 3 15:33 test -rw-r--r--. 1 root root 37 Aug 1 10:53 tt -rw-r--r--. 1 root root 33 Jun 3 15:53 ttssb.txt [root@rhce-128 ~]##:现在去使用自签名证书,使用https协议访问服务器,先修改配置文件中的证书以及私钥
配置完成之后重启服务:
192.168.188.140:443> SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA SSLCertificateFile /root/cert.crt SSLCertificateKeyFile /root/rsa_private.key DocumentRoot "/www/myssl" #ServerName 192.168.188.128 Alias "/data" "/www/virtualDir/test.html" ScriptAlias "/bin" "/www/mybin" [root@rhce-128 conf.d]# systemctl restart httpd# :执行结果:可以看到使用自签名证书也是可以访问页面的:
握手协议流程:(四个阶段)
第一次阶段:
客户端发送ClientHello给服务器,服务器处理请求后返回ServerHello包,在这个阶段,不会发送CA证书,本阶段进行的任务是协商版本,协商加密套件,产生随机数等;
第二个阶段:
服务器想客户端返回certificate(CA证书),如果是第一次访问,那么必须发送证书证明身份,若服务器想客户端发送Certificate Request包,那么客户端就必须要想服务器发送自己的CA证书;
第三个阶段:
秘钥交换阶段,Server Key Exchange,这个阶段不会发送秘钥,客户端和服务器通过在第一阶段产生的随机数Server_random,Client_random,计算得出premaster(第三个随机数),通过这三个随机数产生主密钥,也就是会话秘钥(具有随机性,时效性),客户端将自己产生的会话秘钥通过服务器的公钥打包发送给服务器,服务器,通过自己的秘钥解密,通过相同的算法得到客户端的会话秘钥,和自己计算得出的会话秘钥进行比较,若是相同的,则可以确定身份,后面的通信通过回话秘钥加密即可,提高效率;
第四个阶段:确认阶段;
确认双方身份,返回确认信息,开始通信;