1、建立samba共享,共享目錄為/data,要求:(描述完整的過程)
mkdir /data #建立共享目錄
1)共享名為shared,工作組為magedu
vim /etc/samba/smb.conf
修改 workgroup = MYGROUP 為 workgroup = magedu 修改 passdb backend = tdbsam 為 passdb backend = smbpasswd smb passwd file = /etc/samba/smbpasswd
2)添加組develop,添加用戶gentoo,centos和ubuntu,其中gentoo和centos以develop為附加組,ubuntu不屬于develop組;密碼均為用戶名;
[root@CentOS7 samba]# groupadd develop [root@CentOS7 samba]# useradd -G develop gentoo [root@CentOS7 samba]# useradd -G develop centos [root@CentOS7 samba]# useradd ubuntu [root@CentOS7 samba]# echo "gentoo"| passwd --stdin gentoo 更改用戶 gentoo 的密碼 。 passwd:所有的身份驗證令牌已經成功更新。 [root@CentOS7 samba]# echo "centos"| passwd --stdin centos 更改用戶 centos 的密碼 。 passwd:所有的身份驗證令牌已經成功更新。 [root@CentOS7 samba]# echo "ubuntu"| passwd --stdin ubuntu
3)添加samba用戶gentoo,centos和ubuntu,密碼均為“mageedu”;
[root@CentOS7 samba]# smbpasswd -a gentoo New SMB password: Retype new SMB password: startsmbfilepwent_internal: file /etc/samba/smbpasswd did not exist. File successfully created. Added user gentoo. [root@CentOS7 samba]# smbpasswd -a centos New SMB password: Retype new SMB password: Added user centos. [root@CentOS7 samba]# smbpasswd -a ubuntu New SMB password: Retype new SMB password: Added user ubuntu. [root@CentOS7 samba]#
4)此samba共享shared僅允許develop組具有寫權限,其他用戶只能以只讀方式訪問;
vim smb.conf
末尾添加 [shared] comment = Magedu.com path = /data guest = yes writable = no write list = +develop
**5)此samba共享服務僅允許來自于172.16.0.0/16網絡的主機訪問; **
vim smb.conf
添加 hosts allow = 172.16.0.0/16 [root@CentOS7 samba]# systemctl start smb.service [root@CentOS7 samba]# systemctl status smb.service ● smb.service - Samba SMB Daemon Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled) Active: active (running) since 四 2017-03-23 14:39:18 CST; 5s ago Main PID: 101560 (smbd) Status: "smbd: ready to serve connections..." CGroup: /system.slice/smb.service ├─101560 /usr/sbin/smbd ├─101561 /usr/sbin/smbd ├─101562 /usr/sbin/smbd └─101563 /usr/sbin/smbd 3月 23 14:39:18 CentOS7 systemd[1]: Starting Samba SMB Daemon... 3月 23 14:39:18 CentOS7 smbd[101557]: [2017/03/23 14:39:18.773050, 0] .....) 3月 23 14:39:18 CentOS7 smbd[101557]: Unknown parameter encountered: "g..." 3月 23 14:39:18 CentOS7 smbd[101557]: [2017/03/23 14:39:18.773117, 0] .....) 3月 23 14:39:18 CentOS7 smbd[101557]: Ignoring unknown parameter "guest" 3月 23 14:39:18 CentOS7 systemd[1]: smb.service: Supervising process 101...s. 3月 23 14:39:18 CentOS7 smbd[101560]: [2017/03/23 14:39:18.787425, 0] .....) 3月 23 14:39:18 CentOS7 smbd[101560]: STATUS=daemon 'smbd' finished sta...s 3月 23 14:39:18 CentOS7 systemd[1]: Started Samba SMB Daemon. Hint: Some lines were ellipsized, use -l to show in full.
PS: CentOS7必須關閉防火墻,還有SELinux
[root@CentOS7 ~]# systemctl list-unit-files |grep fire firewalld.service enabled [root@CentOS7 ~]# systemctl stop firewalld.service [root@CentOS7 ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
親測OK,有圖有真相
PS:這里我把hosts allow = 172.16.0.0/16 改為了hosts allow = 192.168.0.0/24
workgroup 改為WORKGROUP
這樣就看到了,歐耶~
2、搭建一套文件vsftp文件共享服務,共享目錄為/ftproot,
要求:(描述完整的過程)
1)基于虛擬用戶的訪問形式;
2)匿名用戶只允許下載,不允許上傳;
3)禁錮所有的用戶于其家目錄當中;
4)限制最大并發連接數為200
5)匿名用戶的最大傳輸速率512KB/s
6)虛擬用戶的賬號存儲在mysql數據庫當中
7)數據庫通過NFS進行共享
先科(zhuang)普(bi)
我們登錄FTP有三種方式,匿名登錄、本地用戶登錄和虛擬用戶登錄。
匿名登錄:在登錄FTP時使用默認的用戶名,一般是ftp或anonymous。
本地用戶登錄:使用系統用戶登錄,在/etc/passwd中。
虛擬用戶登錄:這是FTP專有用戶,有兩種方式實現虛擬用戶,本地數據文件和數據庫服務器。
FTP虛擬用戶是FTP服務器的專有用戶,使用虛擬用戶登錄FTP,只能訪問FTP服務器提供的資源,大大增強了系統的安全。
測試環境
NFS&MySQL服務器 192.168.0.248
vsftp 服務器 192.168.0.235
一、通過NFS服務器共享數據庫
1、在192.168.0.248服務器上啟動nfs服務,設置共享目錄為/nfs_data
[root@CentOS6 ~]# mkdir -pv /nfsdata mkdir: created directory `/nfsdata’
2、安裝組件
yum install rpcbind nfs-server nfs-lock nfs-idmap
3、啟動nfs服務
[root@CentOS7 ~]# systemctl start nfs-server.service [root@CentOS7 ~]# systemctl status nfs-server.service ● nfs-server.service - NFS server and services Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled) Active: active (exited) since 五 2017-03-24 16:38:33 CST; 1 day 7h ago Main PID: 37384 (code=exited, status=0/SUCCESS) CGroup: /system.slice/nfs-server.service 3月 24 16:38:33 CentOS7 systemd[1]: Starting NFS server and services... 3月 24 16:38:33 CentOS7 systemd[1]: Started NFS server and services. [root@CentOS7 ~]#
4、編輯 vim /etc/exports
添加一下內容
/nfs_data 192.168.0.0/24(rw,no_root_squash,sync)
exportfs -r 一下使其生效
注:配置文件說明:
/nfs_data為共享目錄 192.168.0.0/24 可以為一個網段,一個IP,也可以是域名,域名支持通配符 如: *.qq.com rw:read-write,可讀寫; ro:read-only,只讀; sync:文件同時寫入硬盤和內存; async:文件暫存于內存,而不是直接寫入內存; no_root_squash:NFS客戶端連接服務端時如果使用的是:root的話,那么對服務端分享的目錄來說,也擁有root權限。顯然開啟這項是不安全的。 root_squash:NFS客戶端連接服務端時如果使用的是root的話,那么對服務端分享的目錄來說,擁有匿名用戶權限,通常他將使用nobody或nfsnobody身份; all_squash:不論NFS客戶端連接服務端時使用什么用戶,對服務端分享的目錄來說都是擁有匿名用戶權限;
二、vsftp mysql 服務器掛載nfs
[root@CentOS6 ~]# showmount -e 192.168.0.235 Export list for 192.168.0.235: /nfs_data 192.168.0.0/24 [root@CentOS6 ~]# mount -t nfs 192.168.0.235:/nfs_data /nfs_data [root@CentOS6 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos6-lv_root 18G 3.3G 13G 21% / tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/sda1 477M 69M 383M 16% /boot 192.168.0.235:/nfs_data 17G 6.9G 11G 41% /nfs_data
客戶端在掛載的時候遇到的一個問題如下,可能是網絡不太穩定,NFS默認是用UDP協議,換成TCP協議即可
mount -t nfs 192.168.0.235:/nfsdata /nfsdata -o proto=tcp -o nolock
在客戶端寫入一個有內容的文件測試,嘿嘿,服務端馬上看到了,歐耶~~~
vsftp mysql 服務器 192.168.0.235安裝MySQL/MariaDB
這里我就直接yum安裝MariaDB了
yum install mariadb-server.x8664 mariadb-devel.x8664 openssl-devel.x86_64 systemctl start mariadb.service systemctl enable mariadb.service
安裝PAM-MySQL,要跟vsftp安裝在同一臺機器上
下載源碼包,加壓
安裝前再次確認依賴包
yum install pam-devel openssl-devel mariadb-devel
CentOS7 ./configure –with-mysql=/usr –with-openssl –with-pam=/usr –with-pam-mods-dir=/usr/lib64/security
CentOS6 ./configure –with-mysql=/usr –with-openssl –with-pam=/usr –with-pam-mods-dir=/lib64/security/
make -j 4 && make install
配置數據庫,創建vsftpd的庫和表
[root@CentOS7 pam_mysql-0.7RC1]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 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)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | vsftpd | +--------------------+ 5 rows in set (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) binary not null ); Query OK, 0 rows affected (0.00 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.00 sec) MariaDB [vsftpd]> insert into users(name,password) values ('jerry',password('mageedu')); Query OK, 1 row affected (0.00 sec) MariaDB [vsftpd]> insert into users(name,password) values ('tom',password('mageedu111')); Query OK, 1 row affected (0.00 sec) MariaDB [vsftpd]> select * from users; +----+-------+-------------------------------------------+ | id | name | password | +----+-------+-------------------------------------------+ | 1 | jerry | *9A94EE7D14C10908118B62D2DA88E6932E11E438 | | 2 | tom | *67CF267D9D554496768C605C2D66754EAE874C12 | +----+-------+-------------------------------------------+ 2 rows in set (0.00 sec) MariaDB [vsftpd]> #我這邊vsftpd跟mysql不是同一臺機器,所以開啟遠程授權 MariaDB [mysql]> grant select on vsftpd.* to vsftpd@'192.168.0.248' identified by 'mageedu'; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec) [root@CentOS7 pam_mysql-0.7RC1]# mysql -uvsftpd -pmageedu Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 14 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)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | test | | vsftpd | +--------------------+ 3 rows in set (0.00 sec) MariaDB [(none)]> use vsftpd; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [vsftpd]> select * from users; +----+-------+-------------------------------------------+ | id | name | password | +----+-------+-------------------------------------------+ | 1 | jerry | *9A94EE7D14C10908118B62D2DA88E6932E11E438 | | 2 | tom | *67CF267D9D554496768C605C2D66754EAE874C12 | +----+-------+-------------------------------------------+ 2 rows in set (0.00 sec) MariaDB [vsftpd]> exit Bye [root@CentOS7 pam_mysql-0.7RC1]#
遷移MariaDB的數據庫默認數據存放目錄,放到/nfs_data/目錄中,形成NFS共享
[root@CentOS7 /]# systemctl stop mariadb.service [root@CentOS7 /]# cp -r /var/lib/mysql/ /nfs_data/ [root@CentOS7 /]#vim /etc/my.cnf 修改成:datadir=/nfs_data/mysql [root@CentOS7 /]#cd /nfs_data/ [root@CentOS7 /]# chown -R mysql:mysql mysql/ [root@CentOS7 /]#systemctl start mariadb.service [root@CentOS7 /]#systemctl status mariadb.service ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since 日 2017-03-26 15:16:34 CST; 18min ago Process: 94278 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 94247 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 94277 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─94277 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─94435 /usr/libexec/mysqld --basedir=/usr --datadir=/nfs_data... 3月 26 15:16:32 CentOS7 systemd[1]: Starting MariaDB database server... 3月 26 15:16:32 CentOS7 mysqld_safe[94277]: 170326 15:16:32 mysqld_safe.... 3月 26 15:16:32 CentOS7 mysqld_safe[94277]: 170326 15:16:32 mysqld_safe...l 3月 26 15:16:34 CentOS7 systemd[1]: Started MariaDB database server. Hint: Some lines were ellipsized, use -l to show in full.
這時候,兩邊機器的NFS目錄都看看,OK啦~~~
安裝vsftpd
[root@CentOS6 mysql]# yum install vsftpd Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package vsftpd.x86_64 0:2.2.2-21.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================ Package Arch Version Repository Size ============================================================================ Installing: vsftpd x86_64 2.2.2-21.el6 base 155 k Transaction Summary ============================================================================ Install 1 Package(s) Total download size: 155 k Installed size: 340 k Is this ok [y/N]: y Downloading Packages: vsftpd-2.2.2-21.el6.x86_64.rpm | 155 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : vsftpd-2.2.2-21.el6.x86_64 1/1 Verifying : vsftpd-2.2.2-21.el6.x86_64 1/1 Installed: vsftpd.x86_64 0:2.2.2-21.el6 Complete!
配置vsftpd的pam文件
[root@CentOS6 ~]# vim /etc/pam.d/vsftpd.mysql
輸入以下內容:
auth required pam_mysql.so user=vsftpd passwd=mageedu host=192.168.0.235 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2 account required pam_mysql.so user=vsftpd passwd=mageedu host=192.168.0.235 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
創建系統用戶
因為虛擬用戶最終要映射為系統用戶,所以得創建用于vsftpd映射使用滴用戶啦。。。。。
[root@CentOS6 ~]# mkdir -pv /ftproot mkdir: created directory `/ftproot' [root@CentOS6 /]# useradd -s /sbin/nologin -d /ftproot vuser
確保vuser的家目錄其他用戶能讀能執行
[root@CentOS6 /]# ll |grep ftproot/ [root@CentOS6 /]# ll |grep ftpr drwx------ 3 vuser vuser 4096 Mar 27 13:59 ftproot [root@CentOS6 /]# chmod +rx -R /ftproot/ [root@CentOS6 /]# ll |grep ftpr drwxr-xr-x 3 vuser vuser 4096 Mar 27 13:59 ftproot [root@CentOS6 /]#
配置/etc/vsftpd/vsftpd.conf
[root@CentOS6 /]# vim /etc/vsftpd/vsftpd.conf
修改 pamservicename=vsftpd.mysql
匿名用戶只允許下載,不允許上傳
[root@CentOS6 /]# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES #允許匿名賬戶登錄
anonuploadenable=NO #不允許匿名用戶上傳文件
禁錮所有的用戶于其家目錄當中
chrootlocaluser=YES #禁錮本地賬戶的家目錄
限制最大并發連接數為200
max_clients=200 #最大允許的客戶端連接數
匿名用戶的最大傳輸速率512KB/s
localmaxrate=512000
寫入配置文件后,重啟vsftp服務即可。
原創文章,作者:N24_Jerry,如若轉載,請注明出處:http://www.www58058.com/71959
總結的非常好,詳細的操作過程,仔細的解釋各參數意義,加油?。?!
Have you gone to Bi.mcgatewaybeol? You can look up verses in several different translations there, in many different languages. They have the KJV available. Oh, and pagans don't necessarily think that wealth is a sign of divine favor. Long story. Won't bore you with it here, tho.