RHCE学习笔记记录

环境配置:

1.将主机网卡设置为卡机启用

[root@localhost ~]# nmcli connection modify ens160 connection.autoconnect yes
[root@localhost ~]# nmcli connection up ens160

2.学习环境RHEL 8.x

[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.5 (Ootpa)

3.系统时间

timedatectl set-timezone Asia/Shanghai

date 月日时分年点秒

4.配置好yum/dnf源 rpm

rpm包进行管理

(1)rpm -ivh

​ -evh

​ -qa rpm -qa | grep httpd

​ -ql

​ -qf

(2)yum/dnf

​ 本地源

​ #vim /etc/fstab

​ /dev/sr0 /mnt iso9660 defaults 0 0

​ #mount -a

​ #vim /etc/yum.repos.d/base.repo

		[BaseOS]
		name=RHEL8.5-BaseOS
		baseurl=file:///mnt/BaseOS
		gpgcheck=0
		[AppStream]
		name=RHEL8.5-AppStream
		baseurl=file:///mnt/AppStream
		gpgcheck=0

​ #yum install lrzsz -y

​ 网络源

(3) 源码安装

http服务/www服务、web服务器

1.www web 万维网,通过网络节点中的主机,基于主机运行的服务程序可以给用户提供相应的数据结果(文本,语音,视屏,图片…)

2.web服务两种形式

静态网站:html —> .html /.htm

动态网站:lamp linux–apache-mariadb-python/perl/php…

3.web主流服务程序 linux —apache 微软–IIS unix—nginx

4.客户端程序: 浏览器

5.网址: http://主机:80 tcp 每次访问响应完成自动断开连接

网站(由n多个网页组成)

网页

网页文件(资源文件)

6.请求和相应报文信息

起始行

首部

空白行(mime)

主体

7.搭建web服务

框架C/S

案例一: 搭建web服务器,提供redhat测试界面

linux主机作为服务器

​ 1).部署web服务程序 apache http server(httpd)

     [root@localhost ~]# rpm -qa | grep httpd
     httpd-filesystem-2.4.37-41.module+el8.5.0+11772+c8e0c271.noarch
	 httpd-tools-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64
	 httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64
	 redhat-logos-httpd-84.5-1.el8.noarch
	 [root@localhost ~]# yum install httpd -y

​ 2).当前主机启动该服务程序

#systemctl    start|stop|restart|status|load|reload|enable|disable|is-active|is-enabled   httpd
   [root@localhost ~]# systemctl start httpd
   [root@localhost ~]# systemctl is-active httpd

​ 3).提供客户端主机可以访问的资源文件

​ 默认的资源文件

问什么默认访问的是欢迎界面:通过主配置/var/www/html加载网站资源文件(index.html),当文件不存在,匹配子配置文件/etc/httpd/conf.d/welcome.conf

Alias /.noindex.html /usr/share/httpd/noindex/index.html

​ 4).关闭防火墙,selinux

 [root@localhost ~]# systemctl stop firewalld      ---建议临时关闭
 [root@localhost ~]# systemctl disable firewalld

关闭selinux

临时生效
[root@localhost ~]# setenforce 0      ---主机运行状态下临时关闭
[root@localhost ~]# getenforce            --查看selinux状态
Permissive 
永久修改linux状态
[root@localhost ~]# vim /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.     强制状态(开启)
#     permissive - SELinux prints warnings instead of enforcing.   警告(关闭)
#     disabled - No SELinux policy is loaded.                    禁用(不加载selinux)
SELINUX=permissive

window/linux 客户端主机

​ 浏览器:url 网址

rpm -ql httpd | more

/etc/httpd/conf 主配置目录(默认提供的参数信息)

/etc/httpd/conf/httpd.conf

/etc/httpd/conf.d 子配置目录(辅助)(自定义的配置文件)

/etc/httpd/conf.d/*.conf

一个完整配置文件先加载主配置文件,在加载子配置文件

/etc/httpd/conf.modules.d 模块配置文件的路径

全局生效
ServerRoot   /etc/httpd      配置文件中加载文件的主路径
Listen  80                   服务程序默认监听端口
User apache                  服务程序运行后的所属用户和所属组
Group apache
Serveradmin  root@localhost
#ServerName  www.example.com:80   定义服务主机访问名称
ServerName 0.0.0.0:80
DocumentRoot "/var/www/html"   定义网站默认的主路径
IncludeOptional conf.d/*.conf   开始加载所有子配置文件

局部生效
<Directory />            目录起始标签  /
    AllowOverride none
    Require all denied         请求所有拒绝
</Directory>
<Directory "/var/www">     目录起始标签  /var/www  
    AllowOverride None
    # Allow open access:
    Require all granted     请求所有允许  
</Directory>
<IfModule dir_module>      模块标记  对目录模块定义
    DirectoryIndex index.html     网站主目录索引文件文件名为index.html
</IfModule>

案例二:搭建网站创建自定义网页文件

linux主机作为服务器

​ 1).部署web服务程序 apache http server(httpd)

​ 2).当前主机启动该服务程序

​ 3).提供客户端主机可以访问的资源文件

  #cd /var/www/html
  #echo helloworld > index.html
  通过主配置/var/www/html加载网站资源文件(index.html)当文件存在,直接加载该文件内容进行相应。

​ 4).关闭防火墙,selinux

window/linux 客户端主机

​ 浏览器:url 网址 http:///1/index.html /var/www/html/1/index.html

1.权限控制

web服务程序资源文件的权限控制可以在配置文件和文件层级。

<Directory "/www">     目录起始标签  /www  
    AllowOverride None
    \#Allow open access:
    Require all granted     请求所有允许  
</Directory>
[root@localhost ~]# chmod o-r /www/index.html
[root@localhost ~]# ll /www/index.html
-rw-r-----. 1 root root 13 Mar 20 09:58 /www/index.html
[root@localhost ~]# chmod o+r /www/index.html

https://httpd.apache.org/docs/2.4/howto/auth.html
require user tom
Require ip address
Require not  ip address
Require host domain_name
<Directory /openlab>
        AllowOverride none
        <RequireAll>
                Require all granted
                Require not  ip 192.168.153.128
        </RequireAll>
</Directory>

多网站访问
http://ip|域名|:80
https://

一个ip----多域名

案例三:多ip匹配多网站

1)当前主机配置多个ip

[root@localhost ~]# nmcli connection modify ens160 ipv4.method manual ipv4.addresses  192.168.153.128/24 ipv4.gateway 192.168.153.2 ipv4.dns 114.114.114.114 +ipv4.a
ddresses 192.168.153.129 +ipv4.addresses  192.168.153.130
[root@localhost ~]# nmcli connection up ens160 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@localhost ~]# ip a

2)通过配置基于多个虚拟主机标签配置多个网站站点

虚拟主机示例文件
# rpm -ql httpd | grep vhosts.conf
#  vim /usr/share/doc/httpd/httpd-vhosts.conf
1.自定义子配置文件,配置多主机网站信息
vim /etc/httpd/conf.d/vhosts.conf 
<VirtualHost 192.168.153.128:80>
    DocumentRoot "/openlab/128"
    ServerName 192.168.153.128
    ErrorLog "/var/log/httpd/dummy-128.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-128.example.com-access_log" common
</VirtualHost>

<VirtualHost 192.168.153.129:80>
    DocumentRoot "/openlab/129"
    ServerName 192.168.153.129
</VirtualHost>

<VirtualHost 192.168.153.130:80>
    DocumentRoot "/openlab/130"
    ServerName 192.168.153.130
</VirtualHost>
#资源路径的访问权限
<Directory /openlab>
        AllowOverride none
        Require all granted
</Directory>
2.根据配置创建对应资源文件
#mkdir /openlab/{128,129,130} -pv
#echo this is 128 > /openlab/128/index.html
#echo this is 129 > /openlab/129/index.html
#echo this is 130 > /openlab/130/index.html
#systemctl restart httpd

案例四: 基于多端口访问多网站

##130-80
<VirtualHost 192.168.153.130:80>
    DocumentRoot "/openlab/130"
    ServerName 192.168.153.130
</VirtualHost>
##130--10000    
Listen 10000   #监听自定义端口
<VirtualHost 192.168.153.130:10000>
    DocumentRoot "/openlab/10000"
    ServerName 192.168.153.130
</VirtualHost>
<Directory /openlab>
        AllowOverride none
        Require all granted
</Directory> 

[root@localhost ~]# mkdir /openlab/10000
[root@localhost ~]# echo this is 10000 > /openlab/10000/index.html
[root@localhost ~]# systemctl restart httpd     


案例五:基于域名访问多网站

<VirtualHost 192.168.153.128:80>
    DocumentRoot "/openlab/haha"
    ServerName www.haha.com
    ErrorLog "/var/log/httpd/dummy-128.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-128.example.com-access_log" common
</VirtualHost>
<VirtualHost 192.168.153.128:80>
    DocumentRoot "/openlab/xixi"
    ServerName www.xixi.com
    ErrorLog "/var/log/httpd/dummy-128.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-128.example.com-access_log" common
</VirtualHost>
<Directory /openlab>
        AllowOverride none
        Require all granted
</Directory> 
[root@localhost ~]# mkdir /openlab/{haha,xixi}
[root@localhost ~]# echo this is xixi > /openlab/xixi/index.html
[root@localhost ~]# echo this is haha > /openlab/haha/index.html
[root@localhost ~]# systemctl restart httpd

客户端测试

1.通过域名访问需要将域名解析为ip
​	通过浏览器缓存匹配
​	客户端主机的hosts文件匹配  
  		window:C:\Windows\System32\drivers\etc
​							192.168.153.128         www.haha.com
​							192.168.153.128         www.xixi.com                         
​         linux :  /etc/hosts
​	路由缓存记录匹配
​	本地dns服务

2.排错方式

(1) 启动不成功(配置文件写的有问题)systemctl restart httpd  
[root@localhost ~]#systemctl status httpd
[root@localhost ~]# journalctl -xe
[root@localhost ~]# httpd -t

(2)访问的内容不是我们定义的内容
逻辑问题:分析主机配置标签是否能匹配或是否冲突
		资源文件是否创建
		
        匹配对应文件是否有权限
		防火墙,selinux 

/openlab/128/1/index/html

/openlab/128/1/file/newfile/index.html

案例六:虚拟目录

alias 虚拟目录名称 真实目录路径

​ 为了便于对网站资源进行灵活管理,还可以把这些文件存放在本地计算机的其它文件夹中或者其它计算机的共享文件夹中,然后再把这个文件夹映射到网站主目录中的一个目录上,这个文件夹被称为“虚拟目录”。

每个虚拟目录都有一个别名,这样用户就可以通过这个虚拟目录的别名来访问与之对应的真实文件夹中的资源了。虚拟目录的好处是在不需要改变别名的情况下,可以随时改变其对应的文件夹。

<VirtualHost 192.168.153.128:80>
    DocumentRoot "/openlab/128"
    #  /网站根目录=/openlab/128
    Alias /file   /openlab/128/1/f/file/newfile/
    ServerName 192.168.153.128
        #  /openlab/128/3w
    Alias /3w     /www
</VirtualHost>
<Directory /openlab>
        AllowOverride none
        Require all granted
</Directory>
<Directory "/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>


[root@localhost ~]# mkdir -pv  /openlab/128/1/f/file/newfile/
mkdir: created directory '/openlab/128/1'
mkdir: created directory '/openlab/128/1/f'
mkdir: created directory '/openlab/128/1/f/file'
mkdir: created directory '/openlab/128/1/f/file/newfile/'
[root@localhost ~]# echo this is zijiemian > /openlab/128/1/f/file/newfile/index.html

[root@localhost ~]# mkdir /www
mkdir: cannot create directory ‘/www’: File exists
[root@localhost ~]# cd /www
[root@localhost www]# ll
total 4
-rw-r--r--. 1 root root 13 Mar 20 09:58 index.html
[root@localhost www]# echo this is 128 test page > index.html

案例七:用户访问控制+虚拟目录

<VirtualHost 192.168.153.128:80>
    DocumentRoot "/openlab/128"
       # /网站根目录=/openlab/128
    Alias /file   /openlab/128/1/f/file/newfile/
    ServerName 192.168.153.128
    Alias /3w     /www
</VirtualHost>
<Directory /openlab>
​        AllowOverride none
​        Require all granted
</Directory>
<Directory /www>
​        AuthType Basic
​        AuthName "Please login:"
​        AuthuserFile /etc/httpd/userfile
​        Require user tom zhangsan
</Directory>

[root@localhost www]# htpasswd -c /etc/httpd/userfile tom    
New password: 
Re-type new password: 
Adding password for user tom
[root@localhost www]# htpasswd /etc/httpd/userfile zhangsan
New password: 
Re-type new password: 
Adding password for user zhangsan

curl  http://192.168.153.128/3w/   -u tom

案例八:搭建加密网站

防伪装

信息泄露

防篡改

对称秘钥 双方用的是同一把秘钥,既可以实现加密,也可以实现解密(双向通信阶段)

非对称密码 公钥 加密 私钥解密 (身份验证单向通信)

CA 证书标准x509

​ .key

​ .crt

​ .csr

https建立过程

身份验证(证书验证)

​ 双方验证

算法协商 (对称算法)

数据加密传输

1.加载mod_ssl认证模块

[root@localhost www]# yum install mod_ssl -y

2.生成自签名证书

(第二种) [root@localhost ~]#cd /etc/pki/tls/certs
[root@localhost certs]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout ../private/openlab.key  -x509 -days 365 -out openlab.crt

----------------------------------------------x509 key csr crt---------------------------
[root@www certs]# openssl genrsa -aes128 2048 > openlab.key
 (第三种) #openssl req -utf8 -new -key openlab.key -x509 -days 365 -out openlab.crt 
-------------------------------------------------------------------------------------
***私钥文件有密码,解决每次重启服务,不需要手动输入私钥密码验证。
[root@localhost ~]# cat /usr/libexec/httpd-ssl-pass-dialog 
#!/bin/sh

#exec /bin/systemd-ask-password "Enter TLS private key passphrase for $1 ($2) : "
echo redhat

3.虚拟主机标签中添加加密验证信息

<VirtualHost 192.168.153.128:443>
    DocumentRoot "/ssl"
    ServerName 192.168.153.128
    SSLEngine on
	SSLCertificateFile /etc/pki/tls/certs/openlab.crt
	SSLCertificateKeyFile /etc/pki/tls/private/openlab.key
</VirtualHost>
<Directory /ssl>
​        AllowOverride none
​        Require all granted
</Directory>

4.重启服务测试

案例九:扩展配置

1.通过http/https 实现文件共享

目录标签中 options +indexes

indexes 默认加载directoryindex 目录标签后,当目录directoryindex找不到对应网页文件(删除主路径下的index.html,以及欢迎界面)会加载mod_autoindex 会将网站主路径下的文件格式为目录列表提供客户端主机访问。

在这里插入图片描述

2.配置用户主界面—静态

1.更改用户主界面配置

vim /etc/httpd/conf.d/userdir.conf

​ UserDir public_html

<Directory “/home/tom/public_html”>
AuthType Basic
AuthName “please login”
AuthuserFile /etc/httpd/userfile
Require user tom

注意: 访问用户主界面通过什么协议访问

指定网站访问方式(ip)通过哪种协议可以匹配

2.创建资源信息

#useradd tom

#mkdir /home/tom/public_html

#echo this is tom > /home/tom/public_html/index.html

#chmod o+rx /home/tom

#htpasswd -c /etc/httpd/userfile tom

3.重启

4.firewalld setenfore

搭建动态网站

LAMP

1.linux平台部署web服务

2.配置web服务

(1).安装web服务

(2).根据配置定义加载网页资源文件的路径

[root@localhost uc_server]# cat /etc/httpd/conf.d/vhosts.conf

<Directory /www>
AllowOverride none
Require all granted

<Virtualhost 192.168.153.128:80>
DocumentRoot /www
ServerName 192.168.153.128

(3).根据配置创建资源文件

#mkdir /www

#cd /www
在这里插入图片描述

#unzip Discuz_X3.4_SC_UTF8_20191201.zip

(4).重启服务

3.部署mariadb

[root@localhost install]# yum install mairadb-server -y

[root@localhost www]# systemctl start mariadb

[root@localhost www]# mysql_secure_installation 初始化数据库

enter

y

redhat

redhat

一直y

[root@localhost www]# mysql -uroot -predhat // -u用户名 -p密码

MariaDB [(none)]> create database luntan;

MariaDB [(none)]>quit

[root@localhost www]# systemctl restart mariadb

4.安装PHP应用程序

yum install php* -y

客户端:

http://192.168.153.128/upload
在这里插入图片描述
在这里插入图片描述
[root@localhost upload]# pwd
/www/upload
[root@localhost upload]# chmod o+w data config uc_* -R

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值