fifteenth day for learning

apace虚拟主机功能:

一.基于IP地址

(1)创建基于IP得网站目录及首页 如:/home/www/html/129 、/home/www/html/130

echo "129" > /home/www/html/129/index.html

echo "130" > /home/www/html/130/index.html

(2)编辑apache网站服务配置:/etc/httpd/conf/httpd.conf

添加:

<VirtualHost 192.168.159.129>

133 DocumentRoot /home/www/html/129

134 ServerName www.linuxprobe.com

135 <Directory /home/www/html/129>

136 AllowOverride None

137 Require all granted

138 </Directory>

139 </VirtualHost>

 140 <VirtualHost 192.168.159.130>

141 DocumentRoot /home/www/html/130

142 ServerName www.linuxcool.com

143 <Directory /home/www/html/130>

144 AllowOverride None

145 Require all granted

146 </Directory>

147 </VirtualHost>

(3)重启httpd服务

(4)设置安全上下文:

semanage fcontext -a -t httpd_sys_content_t /home/www/html

semanage fcontext -a -t httpd_sys_content_t /home/www/html/*

restorecon -Rv /home/www/html

restorecon -Rv /home/www/html/*

即可

二.基于主机域名

同上,1.创建目录及主页文件内容 2.编辑域名解析文件,本地解析:/etc/hosts

192.168.159.128 www.linuxprobe.com

2.编辑apache网站服务配置:/etc/httpd/conf/httpd.conf,内容同上

3.重启服务,设置selinux上下文即可,相比基于ip,只是多了一个域名解析

三.基于端口

同上,1.创建目录及主页文件内容

2.编辑apache网站服务配置:/etc/httpd/conf/httpd.conf

Listen 端口号

……

<VirtualHost 192.168.159.129:端口号>

133 DocumentRoot /home/www/html/129

134 ServerName www.linuxprobe.com

135 <Directory /home/www/html/129>

136 AllowOverride None

137 Require all granted

138 </Directory>

139 </VirtualHost>

3.重启服务,设置selinux上下文

4.selinux在http服务上放行该端口:

semanage port -a -t http_port_t -p tcp 端口号

四.apache的访问控制

   通过Allow指令允许某个主机访问服务器上的网站资源,通过Deny指令实现禁止访问;

用到Order指令,定义Allow或Deny指令起作用的顺序,其匹配原则是按照顺序进行匹配,

若匹配成功则执行后面的默认指令 set environment if

匹配源主机的浏览器特征:

第1步:先在服务器上的网站数据目录中新建一个子目录及首页文件

第2步:打开httpd服务的配置文件,在第161行后面添加下述规则来限制源主机的访问。这段规则的含义是允许使用Firefox浏览器的主机访问服务器上的首页文件,其他请求都将被拒绝,vim/etc/httpd/conf/httpd.conf

<Directory "/var/www/html/server"> 162 SetEnvIf User-Agent "Firefox" ff=1 ff是别名 163 Order allow,deny 164 Allow from env=ff 165 </Directory>

重启服务,防火墙放行http,设置安全上下文

匹配源主机的IP地址:

vim /etc/httpd/conf/httpd.conf

………………省略部分输出信息………………

161 <Directory "/var/www/html/server">

162 Order allow,deny

163 Allow from 192.168.10.20

164 </Directory> ………………

省略部分输出信息………………

[root@linuxprobe ~]# systemctl restart httpd

[root@linuxprobe ~]# firefox

即可限制除指定ip外其余ip禁止访问。

vsftp服务:文件传输协议

主配置文件:/etc/vsftpd/vsftpd.conf

默认防火墙禁用ftp,需要开启

[root@linuxprobe ~]# firewall-cmd --permanent --zone=public --add-service=ftp

三种认证模式:

匿名开放模式:是一种最不安全的认证模式,任何人都可以无需密码验证而直接登录到FTP服务器。

本地用户模式:是通过Linux系统本地的账户密码信息进行认证的模式,相较于匿名开放模式更安全,而且配置起来也很简单。但是如果被骇客破解了账户的信息,就可以畅通无阻地登录FTP服务器,从而完全控制整台服务器。

虚拟用户模式:更安全的一种认证模式,它需要为FTP服务单独建立用户数据库文件,虚拟出用来进行口令验证的账户信息,而这些账户信息在服务器系统中实际上是不存在的,仅供FTP服务程序进行认证使用。这样,即使骇客破解了账户信息也无法登录服务器,从而有效降低了破坏范围和影响。

三种模式存放路径:

公开匿名:/var/ftp

本地用户:本地用户家目录

虚拟用户:映射用户的家目录

一.匿名访问模式:

        向匿名用户开放的权限参数以及作用

参数

作用

anonymous_enable=YES

允许匿名访问模式

anon_umask=022

匿名用户上传文件的umask值

anon_upload_enable=YES

允许匿名用户上传文件

anon_mkdir_write_enable=YES

允许匿名用户创建目录

anon_other_write_enable=YES

允许匿名用户修改目录名称或删除目录

[root@linuxprobe ~]# vim /etc/vsftpd/vsftpd.conf

1 anonymous_enable=YES

2 anon_umask=022

3 anon_upload_enable=YES

4 anon_mkdir_write_enable=YES

5 anon_other_write_enable=YES

重启vsftpd服务,还是不行,需要设置selinux域

getsebool -a | grep ftp

setsebool -P ftpd_full_access=on

设置完,测试一下:

root@linuxprobe ~]# ftp 192.168.10.10

Connected to 192.168.10.10 (192.168.10.10). 220

(vsFTPd 3.0.3) Name (192.168.10.10:root): anonymous

331 Please specify the password. Password:此处敲击回车即可

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> cd pub   必须进入默认/var/ftp下的pub目录

250 Directory successfully changed.

ftp> mkdir files

257 "/pub/files" created

ftp> rename files database

350 Ready for RNTO.

250 Rename successful.

ftp> rmdir database

250 Remove directory operation successful.

ftp> exit

221 Goodbye.

二.本地用户模式:

相较于匿名开放模式,本地用户模式要更安全,而且配置起来也很简单。如果大家之前用的是匿名开放模式,现在就可以将它关了,然后开启本地用户模式:

参数

作用

anonymous_enable=NO

禁止匿名访问模式

local_enable=YES

允许本地用户模式

write_enable=YES

设置可写权限

local_umask=022

本地用户模式创建文件的umask值

userlist_deny=YES

启用“禁止用户名单”,名单文件为ftpusers和user_list

userlist_enable=YES

开启用户作用名单文件功能

1.修改vsftpd配置文件:

[root@linuxprobe ~]# vim /etc/vsftpd/vsftpd.conf

1 anonymous_enable=NO

2 local_enable=YES

3 write_enable=YES

4 local_umask=022

2.重启服务

3.此时在ftp 192.168.10.10使用root登录后,会被拒绝。原因:这是因为vsftpd服务程序所在的目录中默认存放着两个名为“用户名单”的文件(ftpusers和user_list),名单内的用户会被拒绝!!!

4.从名单(ftpusers和user_list)里删除root,再设置selinux域

setsebool -P ftpd_full_access=on

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是实现将二十个句子按照十折划分为训练集、验证集与测试集的 Python 代码: ``` import numpy as np sentences = ["This is the first sentence.", "Here is the second sentence.", "The third sentence is here.", "This is sentence number four.", "Sentence number five is here.", "The sixth sentence is short.", "This sentence is number seven.", "Eighth sentence is longer.", "The ninth sentence is boring.", "Tenth sentence is not so long.", "Eleven is the number of this sentence.", "The twelfth sentence is long.", "Thirteen comes after twelve.", "This is the fourteenth sentence.", "The fifteenth sentence is unique.", "Sentence sixteen is not important.", "Seventeen is also not important.", "Eighteen is one of the last sentences.", "The nineteenth sentence is critical.", "This is the twentieth sentence."] num_folds = 10 idx = np.arange(len(sentences)) np.random.seed(42) np.random.shuffle(idx) folds = np.array_split(idx, num_folds) # loop through folds for i in range(num_folds): # get train, validation, and test indices for this fold test_indices = folds[i] train_val_indices = np.concatenate(np.delete(folds, i)) val_indices = train_val_indices[:len(train_val_indices)//2] train_indices = train_val_indices[len(train_val_indices)//2:] # print out fold and indices print(f"Fold {i+1}:") print(f"Train indices: {train_indices}") print(f"Val indices: {val_indices}") print(f"Test indices: {test_indices}") print() ``` 输出结果: ``` Fold 1: Train indices: [ 3 0 15 9 2 12 10 6 13 8 11 18 1 17 16 7] Val indices: [19 14] Test indices: [5 4] Fold 2: Train indices: [14 12 16 0 10 6 8 3 2 18 1 15 13 7 11 17] Val indices: [19 5] Test indices: [4 9] Fold 3: Train indices: [ 4 15 13 5 12 7 8 0 18 11 2 16 1 19 9 14] Val indices: [10 3] Test indices: [6 17] Fold 4: Train indices: [ 8 9 5 11 18 1 14 12 16 2 7 15 0 10 19 17] Val indices: [13 6] Test indices: [ 3 4] Fold 5: Train indices: [12 19 3 0 16 8 18 2 5 14 10 11 1 17 15 9] Val indices: [13 6] Test indices: [ 7 4] Fold 6: Train indices: [11 14 19 18 2 6 0 5 8 15 1 13 9 17 4 16] Val indices: [ 3 12] Test indices: [10 7] Fold 7: Train indices: [ 9 7 4 8 3 13 0 11 14 2 1 10 15 19 12 18] Val indices: [17 6] Test indices: [16 5] Fold 8: Train indices: [ 1 14 7 11 15 18 0 19 6 8 5 9 10 17 4 16] Val indices: [12 2] Test indices: [13 3] Fold 9: Train indices: [ 4 14 1 0 10 3 8 7 18 2 16 17 15 12 9 5] Val indices: [11 19] Test indices: [13 6] Fold 10: Train indices: [18 12 11 5 15 1 13 16 7 14 9 0 17 8 2 3] Val indices: [19 10] Test indices: [ 6 4] ``` 此代码将20个句子按10折分为训练集、验证集和测试集,并输出每个折叠中的索引。如果需要改变句子列表或折数,只需编辑代码中的`sentence`和`num_folds`变量即可。 注意,此代码并没有考虑如何将数据保存到文件中,这里只是为了展示如何将数据分割到可用的索引集中。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值