1. 程式人生 > >Linux伺服器配置---ftp限制頻寬

Linux伺服器配置---ftp限制頻寬

限制頻寬

      ftp伺服器可以設定每個使用者的頻寬,這樣根據實際需求來分配,更加充分的利用系統資源。頻寬通過引數“anon_max_rate“和”local_max_rate“來設定,這兩個引數在配置檔案中如果找不到,那麼使用者可以在末尾追加。

 

1、設定匿名使用者頻寬,通過引數“anon_max_rate”,之後重啟服務

     1)未修改之前的速度

[[email protected] wj]# lftp 192.168.0.113:8765        //

匿名登入

lftp 192.168.0.113:~> cd pub/

lftp 192.168.0.113:/pub> get 1.zip                   //下載檔案

[0] get 1.zip &                                                  

    `1.zip' at 322830336 (13%) 65.74M/seta:30s [正接收資料]     //速度65M

 

     2)開啟配置檔案“/etc/vsftpd/vsftpd.conf“,在末尾追加一句話”anon_max_rate=30000“

[[email protected] ~]#gedit /etc/vsftpd/vsftpd.conf

anon_max_rate=30000      //

匿名使用者的頻寬是30kb

     3)重啟服務,測試匿名使用者頻寬

[[email protected] wj]# service vsftpd restart        //重啟服務

關閉vsftpd                                             [失敗]

 vsftpd 啟動vsftpd                                    [確定]

 

[[email protected] wj]# lftp 192.168.0.113:8765      //匿名登入,注意埠號之前已經修改了

lftp 192.168.0.113:~> cd pub/

lftp 192.168.0.113:/pub> get 1.zip

[0] get 1.zip &                                             

    `1.zip' at 1179648 (0%) 28.0K/s eta:22h [正接收資料]      //可以看到這裡的下載速度很慢,只有28k

 

2、設定本機使用者的頻寬,通過引數“local_max_rate“ 實現 。這裡會限制本地所有的使用者速度

     1)開啟配置檔案“/etc/vsftpd/vsftpd.conf“,在末尾追加一句話”anon_max_rate=30000“

[[email protected] wj]# lftp david:[email protected]:8765     //使用者david登入,密碼是543092

lftp [email protected]:~> ls

-rwxrwxrwx    1 0        0        2375494044 Aug 14 06:54 1.zip

lftp [email protected]:~> get 1.zip                             //下載檔案

[0] get 1.zip &                                                 

    `1.zip' at 322830336 (13%) 65.74M/s eta:30s [正接收資料]   //速度65M

     2)開啟配置檔案“/etc/vsftpd/vsftpd.conf“,在末尾追加一句話”local_max_rate=30000“

[[email protected] ~]#gedit /etc/vsftpd/vsftpd.conf

local_max_rate=30000      //本地使用者的頻寬是30kb

     3)重啟服務,測試本地使用者頻寬

[[email protected] wj]# service vsftpd restart        //重啟服務

關閉vsftpd                                             [失敗]

 vsftpd 啟動vsftpd                                    [確定]

 

[[email protected] wj]# lftp david:[email protected]:8765     //使用者david登入,密碼是543092

lftp [email protected]:~> ls

-rwxrwxrwx    1 0        0        2375494044 Aug 14 06:54 1.zip

lftp [email protected]:~> get 1.zip                             //下載檔案

[0] get 1.zip &                                                 

    `1.zip' at 322830336 (13%) 35.0K/s eta:30s [正接收資料]   //速度30k

 

[[email protected] wj]# lftp weijie:[email protected]:8765     //使用者david登入,密碼是123456

lftp [email protected]:~> ls

-rwxrwxrwx    1 0        0        2375494044 Aug 14 06:54 1.zip

lftp [email protected]:~> get 1.zip                             //下載檔案

[0] get 1.zip &                                                 

    `1.zip' at 322830336 (13%) 29.0K/s eta:30s [正接收資料]   //速度29k

3、設定指定使用者的頻寬

     1)設定頻寬配置目錄,引數“user_config_dir“可以指定一個目錄來存放管理頻寬的檔案

[[email protected] ~]# gedit /etc/vsftpd/vsftpd.conf

user_config_dir=/etc/vsftpd/rate_limit      //管理使用者頻寬的目錄,這個目錄需要使用者自己建立

     2)設定使用者“weijie“的頻寬,在”rate_limit“目錄下建立檔案”weijie“,在檔案中新增引數local_max_rate

[[email protected] wj]# mkdir /etc/vsftpd/rate_limit

[[email protected] wj]# cd /etc/vsftpd/rate_limit/

[[email protected] rate_limit]# touch weijie

[[email protected] rate_limit]# gedit weijie

local_max_rate=30000

     3)重啟vsftpd服務,測試使用者“weijie“使用者”david“的下載速度

[[email protected] wj]# service vsftpd restart        //重啟服務

關閉vsftpd                                             [確定]

 vsftpd 啟動vsftpd                                    [確定]

 

[[email protected] wj]# lftp david:[email protected]:8765        //使用者david登入

lftp [email protected]:~> ls

-rwxrwxrwx    1 0        0        2375494044 Aug 14 06:54 1.zip

lftp [email protected]:~> get 1.zip

[0] get 1.zip &                                                 

    `1.zip' at 276234240 (11%) 54.24M/s eta:37s [正接收資料]     //速度52M

 

[[email protected] wj]# lftp weijie:[email protected]:8765    //使用者weijie登入

lftp [email protected]:~> ls

-rwxrwxrwx    1 0        0        2375494044 Aug 14 07:13 1.zip

lftp [email protected]:~> get 1.zip

[0] get 1.zip &                                             

    `1.zip' at 196608 (0%) 21.4K/s eta:30h [正接收資料]         //速度21k

lftp [email protected]:~>