“1、建立samba共享,共享目录为/data,要求:(描述完整的过程)
1)共享名为shared,工作组为magedu;
2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名;
3)添加samba用户gentoo,centos和ubuntu,密码均为“mageedu”;
4)此samba共享shared仅允许develop组具有写权限,其他用户只能以只读方式访问;
5)此samba共享服务仅允许来自于172.16.0.0/16网络的主机访问;
1.下载samba
[root@localhost ~]# yum install samba –y
2.创建develop组以及用户。
[root@localhost ~]# groupadd develop
[root@localhost ~]# useradd gentoo -G develop
[root@localhos/ft ~]# useradd centos -G develop
[root@localhost ~]# useradd ubuntu
[root@localhost ~]# for i in gentoo centos ubuntu ;do echo “$i” |passwd –stdin $i;done
更改用户 gentoo 的密码 。
passwd:所有的身份验证令牌已经成功更新。
更改用户 centos 的密码 。
passwd:所有的身份验证令牌已经成功更新。
更改用户 ubuntu 的密码 。
passwd:所有的身份验证令牌已经成功更新
[root@localhost ~]# smbpasswd -a gentoo
New SMB password:
Retype new SMB password:
Added user gentoo.
3.创建samba用户
[root@localhost ~]# smbpasswd -a centos
New SMB password:
Retype new SMB password:
Added user centos.
[root@localhost ~]# smbpasswd -a ubuntu
New SMB password:
Retype new SMB password:
Added user ubuntu.
4.创建共享目录/data
[root@CentOS7 ~]# mkdir /data
[root@CentOS7 ~]# chgrp develop /data
[root@CentOS7 ~]# chmod g+w /data
5.按需修改配置文件(/etc/samba/smb.conf),开启服务(需开启smb和nmb服务)
[root@CentOS7 samba]# vim /etc/samba/smb.conf
[global]
workgroup = mageedu
[shared]
comment = test data
path = /data
read only = Yes
write list = @develop
hosts allow = 192.168.1.0/24
browseable = No
[root@CentOS7 ~]# systemctl start smb.service
[root@CentOS7 ~]# systemctl start nmb.service
6.用客户端命令测试
[root@CentOS7 ~]# smbclient //192.168.1.108/shared -U centos
Enter centos’s password:
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
smb: \> lcd /etc
smb: \> put issue
putting file issue as \issue (0.5 kb/s) (average 0.5 kb/s)
2、搭建一套文件vsftp文件共享服务,共享目录为/ftproot,要求:(描述完整的过程)
1)基于虚拟用户的访问形式;
2)匿名用户只允许下载,不允许上传;
3)禁锢所有的用户于其家目录当中;
4)限制最大并发连接数为200:;
5)匿名用户的最大传输速率512KB/s
6)虚拟用户的账号存储在mysql数据库当中。
7)数据库通过NFS进行共享。
前提关闭防火墙和seliunx(192.168.1.106)
1.开启NFS服务,建立共享目录并设定权限(下载nfs-utils),供客户端共享。
[root@localhost /]# yum install nfs-utils –y
[root@localhost /]# mkdir /mydata
[root@localhost /]# vim /etc/exports # NFS配置文件
/mydata 192.168.1.0/24(rw,sync,no_root_squash)
[root@localhost mydata]# systemctl start nfs.service
[root@localhost mydata]# exportfs
/mydata 192.168.1.0/24
[root@localhost mydata]# showmount -e 192.168.1.109 #查看共享目录
Export list for 192.168.1.109:
/mydata 192.168.1.0/24
2.安装配置mariadb数据库
(mariadb-server,mariadb-devel,openssl-devel, pam-devel)
[root@localhost /]# yum install mariadb-server mariadb-devel openssl-devel –y
修改数据库配置(目录为/mydata),建立vsftpd库以及users表;
[root@CentOS7 textmysql]# chown -R mysql.mysql /mydata
[root@CentOS7 textmysql]# systemctl start mariadb.service
[root@CentOS7 /]# rm -fr /var/lib/mysql
[root@CentOS7 etc]# vim /etc/my.cnf #修改mariadb的配置文件
[mysqld]
datadir=/mydata
socket=/mydata/mysql.sock
[mysqladmin]
socket=/mydata/mysql.sock
[root@localhost /]# mysql_install_db –defaults-file=/etc/my.cnf –datadir=/mydata –user=mysql #初始化
[root@localhost /]# systemctl restart mariadb.service
[root@CentOS7/]# ln -s /textmysql/mysql.sock /var/lib/mysql/mysql.sock
[root@CentOS7 /]# mysqladmin -u root password ‘111111’
[root@CentOS7 /]# mysql -uroot -p111111 #创建数据库
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> quit
Bye
[root@CentOS7 /]# mysql -uroot -p111111
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> create database vsftpd;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> use vsftpd;
Database changed
MariaDB [vsftpd]> create table users(ID int AUTO_INCREMENT NOT NULL PRIMARY KEY , name char(30) NOT NULL, password char(48) NOT NULL );
Query OK, 0 rows affected (0.04 sec)
MariaDB [vsftpd]> desc users;
+———-+———-+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+———-+———-+——+—–+———+—————-+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| name | char(30) | NO | | NULL | |
| password | char(48) | NO | | NULL | |
+———-+———-+——+—–+———+—————-+
3 rows in set (0.05 sec)
MariaDB [vsftpd]> INSERT INTO users(name,password) VALUES (‘tom’,password(‘mageedu’));
Query OK, 1 row affected (0.05 sec)
MariaDB [vsftpd]> INSERT INTO users(name,password) VALUES (‘jerry’,password(‘mageedu’));
Query OK, 1 row affected (0.01 sec)
MariaDB [vsftpd]> select * from users;
+—-+——-+——————————————-+
| ID | name | password |
+—-+——-+——————————————-+
| 1 | tom | *9A94EE7D14C10908118B62D2DA88E6932E11E438 |
| 2 | jerry | *9A94EE7D14C10908118B62D2DA88E6932E11E438 |
+—-+——-+——————————————-+
2 rows in set (0.02 sec)
Database changed
MariaDB [vsftpd]> grant select on vsftpd.* to vsftpd@localhost identified by ‘111111’;
Query OK, 0 rows affected (0.04 sec)
MariaDB [vsftpd]> grant select on vsftpd.* to vsftpd@127.0.0.1 identified by ‘111111’;
MariaDB [vsftpd]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [vsftpd]> quit
Bye
3.编译安装pam_mysql
[root@localhost /]# tar -xf pam_mysql-0.7RC1.tar.gz
[root@localhost /]# cd pam_mysql-0.7RC1
[root@localhost pam_mysql-0.7RC1]# ./configure –with-mysql=/usr –with-pam=/usr –with-pam-mods-dir=/usr/lib
[root@localhost pam_mysql-0.7RC1]# make && make install
4.虚拟用户的账号保存在mariadb中,新建pam配置文件(目录/etc/pam.d下)
[root@CentOS7 /]# vim /etc/pam.d/vsftpd.mysql
auth required pam_mysql.so user=vsftpd passwd=111111 host=localho
st db=vsfftpd tables=users usercolumn=name passwdcolumn=password
crpyt=2
account required pam_mysql.so user=vsftpd passwd=111111 host=localhost db=vsfftpd tables=users usercolumn=name passwdcolumn=password crpyt=2
5.安装vsftpd,修改配置
[root@CentOS7 /]# yum install vsftpd -y
[root@CentOS7 /]# systemctl start vsftpd.service
修改配置(/etc/vsftpd/vsftpd.conf文件)
[root@CentOS7 /]# vim /etc/vsftpd/vsftpd.conf
guest_enable=YES
guest_username=vuser
anon_max_rate=512000
anon_world_readable_only=YES
max_clients=200
anon_other_write_enable=YES
chroot_local_user=YES
write_enable=YES
anon_root=/ftproot/pub
pam_service_name=vsftpd.mysql
创建共享目录/ftproot,以及虚拟用户身份vuser
[root@CentOS7 /]# useradd -s /sbin/nologin -d /ftproot/
[root@CentOS7 /]# chmod 755 /ftproot/
[root@CentOS7 /]# ls /ftproot/ -ld
drwxr-xr-x. 5 vuser vuser 97 8月 11 11:11 /ftproot/
[root@CentOS7 /]# chmod -w /ftproot/
[root@CentOS7 /]# mkdir -p /ftproot/{put,upload}
重启服务
[root@CentOS7 /]# systemctl restart vsftpd.service
测试(客户端192.168.1.109)
[root@localhost /]# ftp 192.168.1.106
Connected to 192.168.1.106 (192.168.1.106).
220 (vsFTPd 3.0.2)
Name (192.168.1.106:root): tom
331 Please specify the password.
Password:
230 Login successful. #登录成功
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,1,106,40,200).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 18 Aug 11 03:47 pub
drwxr-xr-x 2 0 0 6 Aug 11 09:35 put
drwxr-xr-x 2 0 0 6 Aug 11 09:35 upload
226 Directory send OK.
ftp> cd /pub
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,1,106,165,9).
150 Here comes the directory listing.
-rw-r–r– 1 0 0 689 Aug 11 03:47 fstab
226 Directory send OK.
ftp> get fstab
local: fstab remote: fstab #测试下载
227 Entering Passive Mode (192,168,1,106,66,241).
150 Opening BINARY mode data connection for fstab (689 bytes).
226 Transfer complete.
689 bytes received in 0.0385 secs (17.91 Kbytes/sec) #成功下载
ftp> put issue # 测试上传
local: issue remote: issue
227 Entering Passive Mode (192,168,1,106,89,148).
553 Could not create file. #不能上传文件
ftp>
原创文章,作者:ning407631632,如若转载,请注明出处:http://www.178linux.com/84606