网络会话

如果我们在公司网络中使用笔记本电脑时需要手动指定网络的IP地址,而回到家中则是使用DHCP自动分配IP地址。这就需要麻烦地频繁修改IP地址,但是使用了网络会话功能后一切就简单多了—只需在不同的使用环境中激活相应的网络会话,就可以实现网络配置信息的自动切换了。
nmcli connection add con-name company ifname eno16777736 autoconnect no type ethernet ip4 192.168.10.10/24 gw4 192.168.10.1 添加网络会话公司
nmcli connection add con-name house ifname ens160 type etherne添加网络会话家
nmcli connection up company 开启网络会话

ssh

是一种能够以安全的方式提供远程登录的协议,也是目前远程管理Linux系统的首选方式。在此之前,一般使用FTP或Telnet来进行远程登录。但是因为它们以明文的形式在网络中传输账户密码和数据信息,因此很不安全,很容易受到黑客发起的中间人攻击,这轻则篡改传输的数据信息,重则直接抓取服务器的账户密码。
vim /etc/ssh/sshd\_config 主配置文件
ssh [email protected] 远程连接服务器
ssh-keygen 生成密钥对
ssh-copy-id 192.168.10.10 将公钥传送至目标地址

scp

scp haha.sh 192.168.10.20:/root
scp 192.168.10.20:/root/xiaohua /root

tmux

dnf -y install tmux
tmux new -s 会话名称
tmux attach 会话名称
tmux detach


Apache

yum -y install httpd
systemctl start httpd
systemctl enable httpd

服务目录 /etc/httpd
主配置文件 /etc/httpd/conf/httpd.conf
网站数据目录 /var/www/html
访问日志 /var/log/httpd/access\_log
错误日志 /var/log/httpd/error\_log

mkdir /home/wwwroot
echo “The New Web Directory” > /home/wwwroot/index.html
vim /etc/httpd/conf/httpd.conf 修改配置文件

DocumentRoot "/home/wwwroot"
<Directory "/home/wwwroot">
 AllowOverride None
 # Allow open access:
Require all granted 
</Directory>

selinux

ls -Zd /var/www/html 查询selinux上下文 drwxr-xr-x. root root system\_u:object\_r:httpd\_sys\_content\_t:s0 /var/www/html semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot 修改目录上下文 semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/* 修改目录上下文 restorecon
-Rv /home/wwwroot/ 使selinux上下文立即生效

个人用户主页功能

vim /etc/httpd/conf.d/userdir.conf 修改配置文件

17 # UserDir disabled  17行注释
24   UserDir public_html 24行放开

su - linuxprobe 切换用户
mkdir public\_html 创建文件夹
echo “this is linuxprobe website” > public\_html/index.html
chomod -R 755 /home/linuxprobe 赋权限

接下来使用getsebool命令查询并过滤出所有与HTTP协议相关的安全策略。其中,off为禁止状态,on为允许状态。
getsebool -a | grep http
httpd\_enable\_homedirs --> off 其中一个策略
setsebool -P httpd\_enable\_homedirs=on 开启策略

有时,网站的拥有者并不希望直接将网页内容显示出来,只想让通过身份验证的用户访客看到里面的内容,这时就可以在网站中添加口令功能了。
htpasswd -c /etc/httpd/passwd linuxprobe
vim /etc/httpd/conf.d/userdir.conf 修改配置文件

27 #
28 # Control access to UserDir directories. The following is an example
29 # for a site where these directories are restricted to read-only.
30 #
31 <Directory "/home/*/public_html">
32 AllowOverride all
#刚刚生成出来的密码验证文件保存路径
33 authuserfile "/etc/httpd/passwd"
#当用户尝试访问个人用户网站时的提示信息
34 authname "My privately website"
35 authtype basic
#用户进行账户密码登录时需要验证的用户名称
36 require user linuxprobe
37 </Directory>

systemctl restart httpd 重启服务

虚拟网站主机功能

基于ip地址
设置服务器IP地址
vim /etc/sysconfig/network-scripts/ifcfg-ens160 设置网卡
mkdir -p /home/wwwroot/10 创建10文件夹
mkdir -p /home/wwwroot/20 创建20文件夹
mkdir -p /home/wwwroot/30 创建30文件夹
echo “this is 10” > /home/wwwroot/10/index.html 10文件夹写入文件
echo “this is 20” > /home/wwwroot/20/index.html 20文件夹写入文件
echo “this is 30” > /home/wwwroot/30/index.html 30文件夹写入文件
vim /etc/httpd/conf/httpd.conf 修改配置文件

113 <VirtualHost 192.168.10.10>
114 DocumentRoot /home/wwwroot/10
115 ServerName www.linuxprobe.com
116 <Directory /home/wwwroot/10 >
117 AllowOverride None
118 Require all granted
119 </Directory>
120 </VirtualHost>
121 <VirtualHost 192.168.10.20>
122 DocumentRoot /home/wwwroot/20
123 ServerName bbs.linuxprobe.com
124 <Directory /home/wwwroot/20 >
125 AllowOverride None
126 Require all granted
127 </Directory>
128 </VirtualHost>
129 <VirtualHost 192.168.10.30>
130 DocumentRoot /home/wwwroot/30
131 ServerName tech.linuxprobe.com
132 <Directory /home/wwwroot/30 >
133 AllowOverride None
134 Require all granted
135 </Directory>
136 </VirtualHost>

systemctl restart httpd 重启服务

semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/10 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/10/* 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/20 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/20/* 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/30 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/30/* 修改selinux上下文
restorecon -Rv /home/wwwroot 重新加载selinux上下文

基于主机域名
vim /etc/hosts 修改配置文件

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.10 www.linuxprobe.com bbs.linuxprobe.com tech.linuxprobe.com

mkdir -p /home/wwwroot/www 创建www文件夹
mkdir -p /home/wwwroot/bbs 创建bbs文件夹
mkdir -p /home/wwwroot/tech 创建tech文件夹
echo “WWW.linuxprobe.com” > /home/wwwroot/www/index.html 为www文件夹写入文件
echo “BBS.linuxprobe.com” > /home/wwwroot/bbs/index.html 为bbs文件夹写入文件
echo “TECH.linuxprobe.com” > /home/wwwroot/tech/index.html 为tech文件夹写入文件
vim /etc/httpd/conf/httpd.conf 修改配置文件

113 <VirtualHost 192.168.10.10>
114 DocumentRoot "/home/wwwroot/www"
115 ServerName "www.linuxprobe.com"
116 <Directory "/home/wwwroot/www">
117 AllowOverride None
118 Require all granted
119 </directory> 
120 </VirtualHost>
121 <VirtualHost 192.168.10.10>
122 DocumentRoot "/home/wwwroot/bbs"
123 ServerName "bbs.linuxprobe.com"
124 <Directory "/home/wwwroot/bbs">
125 AllowOverride None
126 Require all granted
127 </Directory>
128 </VirtualHost>
129 <VirtualHost 192.168.10.10>
130 DocumentRoot "/home/wwwroot/tech"
131 ServerName "tech.linuxprobe.com"
132 <Directory "/home/wwwroot/tech">
133 AllowOverride None
134 Require all granted
135 </directory>
136 </VirtualHost>

semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/www 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/www/* 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/bbs 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/bbs/* 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/tech 修改selinux上下文
semanage fcontext -a -t httpd\_sys\_content\_t /home/wwwroot/tech/* 修改selinux上下文
restorecon -Rv /home/wwwroot 让selinux上下文生效

标签: wwwroot, 笔记, httpd, home, selinux, content, 上下文, LinuxProbe

相关文章推荐

添加新评论,含*的栏目为必填