免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: 一生有你llx
打印 上一主题 下一主题

[服务应用] Linux服务器配置 [复制链接]

论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
11 [报告]
发表于 2018-11-25 08:45 |只看该作者
本帖最后由 一生有你llx 于 2018-11-26 16:45 编辑

Apache支持cgi    
1、打开Apache配置文件httpd.conf,搜索“cgi”,找到下面的一段,去掉“addhandler”前面的“#“,这样就开启了Apache的cgi功能
[root@localhost ~]# gedit /etc/httpd/conf/httpd.conf
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler cgi-script .cgi

2、cgi的目录在“/var/www/cgi-bin/”,在这里创建一个测试文件“test.cgi”输入内容如下
[root@localhost ~]# touch /var/www/cgi-bin/test.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "hello cgi";

3、将“cgi-bin”的权利改为777
[root@localhost ~]# chmod R 777 /var/www/cgi-bin

4、在浏览器输入“127.0.0.1/cgi-bin/test.cgi”可以看到下面的结果
      


做了一个Linux学习的平台,目前出来一个雏形,各位可以参考使用
链接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ  密码:n7bk

论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
12 [报告]
发表于 2018-11-26 16:43 |只看该作者
Apache支持ssl
1、检测是否安装ssl模块,如果没有就安装
[root@localhost cgi-bin]# rpm -qa | grep mod_ssl           //查看是否安装ssl模块
[root@localhost cgi-bin]# yum install -y mod_ssl           //安装ssl
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile                                 
Complete!
[root@localhost cgi-bin]#

2、修改ssl的配置文件“/etc/httpd/conf.d/ssl.conf”如下,开启ssl,设置监听端口
[root@localhost ~]# gedit /etc/httpd/conf.d/ssl.conf
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
LoadModule ssl_module modules/mod_ssl.so           //开启ssl功能
# When we also provide SSL we have to listen to the
# the HTTPS port in addition.
Listen 443       //监听的端口

3、修改防火墙配置,开启对上面端口443的支持
[color=rgb(68, 68, 6]      1)在终端输入命令“setup”,在弹出的框中选择“防火墙”,接着选择“定制”
[color=rgb(68, 68, 6]      
[color=rgb(68, 68, 6]      2)使用空格键选中”https“,接着选择“转发”
[color=rgb(68, 68, 6]      
[color=rgb(68, 68, 6]     3)选择“添加“
[color=rgb(68, 68, 6]      
[color=rgb(68, 68, 6]     4)添加端口443,协议tcp,然后确定
[color=rgb(68, 68, 6]      
[color=rgb(68, 68, 6]     5)回到最初的界面,“确定”
[color=rgb(68, 68, 6]      
     6)重启防火墙
[root@localhost ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat                [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
[root@localhost ~]#
     7)重启apache
[root@localhost ~]# service httpd restart
停止 httpd:                                              [确定]
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                          [确定]
[root@localhost ~]#

4、测试
     1)在浏览器输入https://127.0.0.1,注意必须是“https“ ,看到如下结果
      
     2)选择“我已充分了解”,弹出如下对话框,选择“确认安全例外”就可以正常访问
      



论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
13 [报告]
发表于 2018-11-27 09:21 |只看该作者
Apache支持用户认证
      为了服务器的安全,通常用户在请求访问某个文件夹的时候,Apache可以要求用户输入有效的用户名和登录密码

1、创建一个测试目录
[root@localhost cgi-bin]# mkdir /var/www/html/wj

2、开启认证功能,修改配置文件httpd.conf如下,(将html目录的配置中none改为all)
[root@localhost ~]# gedit /etc/httpd/conf/httpd.conf
<Directory "/var/www/html">
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride All          //默认是none,这里改为all
#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all
</Directory>

3、给需要认证的目录添加配置,修改httpd.conf文件,添加如下内容
<Directory "/var/www/html/wj">     //wj就是我们要认证的目录
    AllowOverride AuthConfig       //这里必须使用AuthConfig
    Order allow,deny
    Allow from all
</Directory>

4、 给测试目录设置用户名和密码
[root@localhost wj]# htpasswd -c /var/www/html/wj/.htpasswd david      //david就是创建的用户名
New password:                 //这里需要输入密码,下面的是确认密码
Re-type new password:
Adding password for user david      //创建成功
[root@localhost wj]#

5、创建htaccess文件,并且增加内容
[root@localhost wj]# vim .htaccess
AuthUserFile /var/www/html/wj/.htpasswd
AuthName "david"
AuthType Basic
require valid-user

6、重启Apache服务
[root@localhost wj]# service httpd restart

7、测试,在浏览器输入“127.0.0.1/wj”,可以看到需要输入密码
     
[color=rgb(68, 68, 6][size=0.83em]屏幕快照 2018-08-13 下午3.45.24.png (82.25 KB, 下载次数: 0)
下载附件
[color=rgb(153, 153, 153) !important]2018-11-27 09:20 上传



[color=rgb(68, 68, 6]      


论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
14 [报告]
发表于 2018-11-28 09:56 |只看该作者
安装jdk
      jdk是运行或者开发java的必须工具,很多软件都会依赖jdk,因此必须学会安装jdk

1、查看当前系统的jdk情况  
[root@localhost wj]# rpm -qa | grep java
tzdata-java-2013g-1.el6.noarch
java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.i686        //可以看到当前系统已经安装了jdk,但是版本太旧了
java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.i686

2、删除系统jdk包
[root@localhost wj]# yum remove -y java-1.6.0
[root@localhost wj]# yum remove -y java-1.7.0
[root@localhost wj]# rpm -qa | grep java       //查看是否删除了
tzdata-java-2013g-1.el6.noarch

3、到官网下载最新的jdk包,http://www.oracle.com/technetwork/java/javase/downloads/index.html, 下载的时候注意64位或者32位
      

4、将下载的压缩包复制到“/usr/local/src/”,解压
[root@localhost src]# cp /media/sf_data/jdk-10.0.2_linux-x64_bin.tar /usr/local/src/jdk.tar
[root@localhost src]# tar -xvf jdk.tar

5、配置jdk环境变量,打开“/etc/profile”,在最后面追加如下
[root@localhost src]# gedit /etc/profile
#java environment
export JAVAHOME=/usr/local/src/jdk-10.0.2       //这个路径就是jdk解压的路径
export CLASSPATH=.{JAVAHOME}/jre/lib/rt.jar{JAVAHOME}/lib/dt.jar{JAVAHOME}/lib/tools.jar
export PATH=$PATH{JAVAHOME}/bin

6、刷新profile
[root@localhost src]# source /etc/profile

7、测试jdk,在终端输入命令“Java -version”
[root@localhost src]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) Client VM (build 25.181-b13, mixed mode)
[root@localhost src]#


论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
15 [报告]
发表于 2018-11-29 07:49 |只看该作者
本帖最后由 一生有你llx 于 2018-11-29 07:51 编辑

安装Tomcat
      Tomcat作为web服务器实现了对servlet和jsp的支持,centos目前不支持yum方式安装。在使用Tomcat之前,确保你已经安装并配置好了jdk,而且jdk的版本要和tomcat匹配

1、从Tomcat官网下载安装包(http://tomcat.apache.org/download-70.cgi),直接解压就可以使用
[root@localhost wj]# tar -xvf tomcat.tar       //直接解压
[root@localhost wj]# ls
1.c  1.c~ apache-tomcat-9.0.10  tomcat.tar
[root@localhost wj]#

2、进入Apache的bin目录,执行startup.sh就可以启动Apache
[root@localhost apache-tomcat-9.0.10]# cd /wj/apache-tomcat-9.0.10//bin/
[root@localhost bin]# ./startup.sh
Using CATALINA_BASE:   /wj/apache-tomcat-9.0.10
Using CATALINA_HOME:   /wj/apache-tomcat-9.0.10
Using CATALINA_TMPDIR: /wj/apache-tomcat-9.0.10/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /wj/apache-tomcat-9.0.10/bin/bootstrap.jar:/wj/apache-tomcat-9.0.10/bin/tomcat-juli.jar
Tomcat started.

3、修改防火墙配置,Tomcat默认使用8080端口,需要修改防火墙,开启对8080端口的支持
      1)在终端输入命令“setup”,在弹出的框中选择“防火墙”,接着选择“定制”
      
     2)使用空格键选中”https“、“http”,接着选择“转发”
            
     3)选择“添加“
      
     4)添加端口8080,协议tcp,然后确定
      
     5)回到最初的界面,“确定”
      
     6)重启防火墙
[root@localhost ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat                [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
[root@localhost ~]#
     7)重启apache
[root@localhost ~]# service httpd restart
停止 httpd:                                              [确定]
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                          [确定]
[root@localhost ~]#

4、测试。在浏览器输入https://127.0.0.1:8080,看到如下结果
      

论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
16 [报告]
发表于 2018-11-30 20:13 |只看该作者
安装mysql
1、检测是否已安装mysql
[root@localhost bin]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.i686
[root@localhost bin]

2、安装mysql和mysql-server
[root@localhost bin]# yum install -y mysql
[root@localhost bin]# yum install -y mysql-server

3、启动mysql,注意这里的服务名字是“mysqld”
[root@localhost bin]# service mysqld start
shell-init: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
chdir: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
初始化 MySQL 数据库: Installing MySQL system tables...
OK
Filling help tables...
OK                                                         [确定]
正在启动 mysqld:                                          [确定]
[root@localhost bin]#

4、配置MySQL开机启动
[root@localhost bin]# chkconfig mysqld on
[root@localhost bin]# chkconfig --list mysqld
mysqld         0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
[root@localhost bin]#

5、设置root用户密码 ,设置密码的命令是“mysqladmin -u 用户名password密码”
[root@localhost bin]# mysqladmin -u root password 543092   //密码是543092

6、修改密码,命令是“mysqladmin -u 用户名-p password 新密码”
[root@localhost bin]# mysqladmin -u root -p password 123456     //新密码123456
Enter password:        //这里要求输入旧密码
[root@localhost bin]#

7、mysql配置文件“/etc/my.cnf”
[root@localhost bin]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql            //数据库文件目录
socket=/var/lib/mysql/mysql.sock    //socket文件
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log     //日志文件
pid-file=/var/run/mysqld/mysqld.pid    //进程pid文件

8、修改端口
1)mysql默认的端口是3306,可以使用netstat来查看
[root@localhost bin]# netstat -tunlp | grep mysqld
tcp        0      0 0.0.0.0:3306               0.0.0.0:*                  LISTEN      4339/mysqld         
2)端口在配置文件中修改,打开配置文件,在后面追加一句话”port=xxx”
[root@localhost bin]# gedit /etc/my.cnf
port=3307      
3)重启myslqd服务,查看端口
[root@localhost bin]# service mysqld restart
shell-init: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
chdir: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
^[[A停止mysqld:                                          [确定]
正在启动mysqld:                                          [确定]
[root@localhost bin]# netstat -tunlp | grep mysqld
tcp        0      0 0.0.0.0:3307               0.0.0.0:*                   LISTEN      4604/mysqld              




论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
17 [报告]
发表于 2018-12-01 16:45 |只看该作者

使用mysql
1、登录,可以用密码登录,也可以不用密码登录。命令格式“mysql –u 用户名 –p 密码”
[root@localhost src]# mysql -u root p     //有密码登录
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
[root@localhost src]# mysql -u root         //无密码登录

2、退出,命令“quit”
[root@localhost bin]# quit

3、创建数据库,命令“create database 数据库名称;”,注意这个命令后面有分号
mysql> create database test1;
Query OK, 1 row affected (0.00 sec)

4、查看数据库,命令“show databases;”
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| test1              |
+--------------------+
4 rows in set (0.00 sec)

5、删除数据库,命令“drop database 数据库名称;”
mysql> drop database test1;
Query OK, 0 rows affected (0.01 sec)

6、设置权限
mysql允许给某个特定的用户赋予指定的权利,而且可以指定在某台机器上使用。Mysql的权限如下
权限
数据库
Table
Column
说明
all privileges


所有权利
alter

增减、删除、修改列
create

创建数据库、表
delete

删除行
drop

删除表、数据库
file


操作文件
index

索引
insert
插入
process


查看线程、连接
reference


创建外键
reload


重新加载,拥有此权限可以刷新表
select
选择
shutdown


关闭
update
更新
usage


无权限,只能连接

1)授权用户权限,命令格式“grant 权限on 数据库文件to 用户名@ip identified by ‘密码’;”。在使用grant的时候,如果用户不存在,那么久创建用户。
//给david在本机授权插入功能,密码123456,只能对test01操作
mysql> grant insert on test01.* to david@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql>
//给david所有权限,在所有的主机都可以操作,而且可以操作任意数据库
mysql> grant all privileges on *.* to david@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql>
2)查看当前数据库所有授权情况,命令“select host,user from mysql.user”
mysql> select host,user from mysql.user;
+-----------------------+-------+
| host                  | user  |
+-----------------------+-------+
| %                     | david |
| 127.0.0.1             | root  |
| localhost             |       |
| localhost             | david |
| localhost             | root  |
| localhost.localdomain |       |
| localhost.localdomain | root  |
+-----------------------+-------+
7 rows in set (0.00 sec)
mysql>
3)查看当前登录用户的权利,命令“show grants”
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                             |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*1256939B1977AFF6C3D114C5594EE354EF363A8B' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
4)查看某个用户在某台机器的权限,命令“show grants for user@ip”
mysql> show grants for david@localhost;
+--------------------------------------------------------------------------------------------------------------+
| Grants for david@localhost                                                                                  |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'david'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
| GRANT INSERT ON `test01`.* TO 'david'@'localhost'                                                            |
+--------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql>
5)删除用户的权限,命令“revoke 权限on  数据库文件  from  user@ip”
mysql> revoke all privileges on *.* from david@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for david@localhost;        //删除之后查看一下
+--------------------------------------------------------------------------------------------------------------+
| Grants for david@localhost                                                                                  |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'david'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
+--------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql>         
6)删除用户,命令“delete from user where user=‘username’”
mysql> use mysql;       //首先要调用这个命令
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
mysql> delete from user where user='david';    //删除用户
Query OK, 2 rows affected (0.00 sec)
mysql> select host,user from mysql.user;     //查看用户
+-----------------------+------+
| host                  | user |
+-----------------------+------+
| 127.0.0.1             | root |
| localhost             |      |
| localhost             | root |
| localhost.localdomain |      |
| localhost.localdomain | root |
+-----------------------+------+
5 rows in set (0.00 sec)
mysql>




[color=rgb(68, 68, 6]做了一个Linux学习的平台,目前出来一个雏形,各位可以参考使用
链接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ  密码:n7bk
[color=rgb(68, 68, 6]


论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
18 [报告]
发表于 2018-12-03 15:29 |只看该作者
忘记root密码
如果不小心忘记了root密码,那么mysql就不能再登录了,这时就要重置root密码才行。通过下面的步骤,我们可以重新设置root密码。
1、退出mysql
[root@localhost src]# service mysqld stop
停止mysqld:                                             [确定]
[root@localhost src]#

2、进入sql安全模式,命令“/usr/bin/mysqld_safe --skip-grant-table &”
[root@localhost src]#/usr/bin/mysqld_safe --skip-grant-table &
[1] 6332
[root@localhost src]# 180814 10:10:00 mysqld_safe Logging to '/var/log/mysqld.log'.
180814 10:10:00 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

3、无密码方式登录,命令“mysql –u root”
[root@localhost src]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.71 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

4、使用mysql,命令“use mysql;”
mysql> use mysql;
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
mysql>

5、重设root密码,命令“update user set password=password (“密码”) where user=’root’”
mysql> update user set password=password('123456') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql>

6、刷新
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

7、退出,重新登录
[root@localhost src]# mysql -u root -p
Enter password:        //这里输入新密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Sever version: 5.1.71 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>


论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
19 [报告]
发表于 2018-12-04 10:27 |只看该作者
phpMyAdmin 工具
1、检测是否已安装php、php-mysql、apache等工具
[root@localhost src]# rpm -qa |grep php
php-cli-5.3.3-26.el6.i686
php-gd-5.3.3-26.el6.i686
php-mysql-5.3.3-26.el6.i686
php-pdo-5.3.3-26.el6.i686
php-5.3.3-26.el6.i686
php-xml-5.3.3-26.el6.i686
php-common-5.3.3-26.el6.i686
[root@localhost src]#

2、到phpMyAdmin官网下载“phpMyAdmin”,https://www.phpmyadmin.net/

3、将下载的软件拷贝到“/var/www/html/”目录下,重命名“phpMyAdmin”
[root@localhost down]#tar zxvf phpMyAdmin-4.8.2.tar.gz
[root@localhost down]#cp r phpMyAdmin-4.8.2 /var/www/html/phpMyAdmin

4、修改配置文件“config.sample.inc.php”,将第29行的“cookie”改为“http”
[root@localhost src]# cd /var/www/html/phpMyAdmin/
[root@localhost phpMyAdmin]# gedit config.sample.inc.php
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';

5、启动Apache 和mysql
[root@localhost phpMyAdmin]# service httpd start
正在启动 httpd:
[root@localhost phpMyAdmin]# service mysqld start
正在启动mysqld:                                          [确定]
[root@localhost phpMyAdmin]#

6、在浏览器输入“127.0.0.1/phpMyAdmin”,就可以登录到phpMyAdmin


论坛徽章:
1
15-16赛季CBA联赛之福建
日期:2018-12-10 14:43:45
20 [报告]
发表于 2018-12-04 10:34 |只看该作者
本帖最后由 一生有你llx 于 2019-11-23 10:19 编辑

ftp限制带宽
      ftp服务器可以设置每个用户的带宽,这样根据实际需求来分配,更加充分的利用系统资源。带宽通过参数“anon_max_rate“和”local_max_rate“来设置,这两个参数在配置文件中如果找不到,那么用户可以在末尾追加。

1、设置匿名用户带宽,通过参数“anon_max_rate”,之后重启服务
     1)未修改之前的速度
[root@localhost 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“
[root@localhost ~]#gedit /etc/vsftpd/vsftpd.conf
anon_max_rate=30000      //匿名用户的带宽是30kb
     3)重启服务,测试匿名用户带宽
[root@localhost wj]# service vsftpd restart        //重启服务
关闭vsftpd:                                             [失败]
为 vsftpd 启动vsftpd:                                    [确定]

[root@localhost 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“
[root@localhost wj]# lftp david:543092@192.168.0.113:8765     //用户david登录,密码是543092
-rwxrwxrwx    1 0        0        2375494044 Aug 14 06:54 1.zip
lftp david@192.168.0.113:~> 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“
[root@localhost ~]#gedit /etc/vsftpd/vsftpd.conf
local_max_rate=30000      //本地用户的带宽是30kb
     3)重启服务,测试本地用户带宽
[root@localhost wj]# service vsftpd restart        //重启服务
关闭vsftpd:                                             [失败]
为 vsftpd 启动vsftpd:                                    [确定]

[root@localhost wj]# lftp david:543092@192.168.0.113:8765     //用户david登录,密码是543092
-rwxrwxrwx    1 0        0        2375494044 Aug 14 06:54 1.zip
lftp david@192.168.0.113:~> get 1.zip                             //下载文件
[0] get 1.zip &                                                
    `1.zip' at 322830336 (13%) 35.0K/s eta:30s [正接收数据]   //速度30k

[root@localhost wj]# lftp weijie:123456@192.168.0.113:8765     //用户david登录,密码是123456
-rwxrwxrwx    1 0        0        2375494044 Aug 14 06:54 1.zip
lftp david@192.168.0.113:~> get 1.zip                             //下载文件
[0] get 1.zip &                                                
    `1.zip' at 322830336 (13%) 29.0K/s eta:30s [正接收数据]   //速度29k
3、设置指定用户的带宽
     1)设置带宽配置目录,参数“user_config_dir“可以指定一个目录来存放管理带宽的文件
[root@localhost ~]# gedit /etc/vsftpd/vsftpd.conf
user_config_dir=/etc/vsftpd/rate_limit      //管理用户带宽的目录,这个目录需要用户自己创建
     2)设置用户“weijie“的带宽,在”rate_limit“目录下创建文件”weijie“,在文件中添加参数local_max_rate
[root@localhost wj]# mkdir /etc/vsftpd/rate_limit
[root@localhost wj]# cd /etc/vsftpd/rate_limit/
[root@localhost rate_limit]# touch weijie
[root@localhost rate_limit]# gedit weijie
local_max_rate=30000
     3)重启vsftpd服务,测试用户“weijie“用户”david“的下载速度
[root@localhost wj]# service vsftpd restart        //重启服务
关闭vsftpd:                                             [确定]
为 vsftpd 启动vsftpd:                                    [确定]

[root@localhost wj]# lftp david:543092@192.168.0.113:8765        //用户david登录
-rwxrwxrwx    1 0        0        2375494044 Aug 14 06:54 1.zip
lftp david@192.168.0.113:~> get 1.zip
[0] get 1.zip &                                                
    `1.zip' at 276234240 (11%) 54.24M/s eta:37s [正接收数据]     //速度52M

[root@localhost wj]# lftp weijie:123456@192.168.0.113:8765    //用户weijie登录
-rwxrwxrwx    1 0        0        2375494044 Aug 14 07:13 1.zip
lftp weijie@192.168.0.113:~> get 1.zip
[0] get 1.zip &                                             
    `1.zip' at 196608 (0%) 21.4K/s eta:30h [正接收数据]         //速度21k



[color=rgb(68, 68, 6]做了一个Linux学习的平台,目前出来一个雏形,各位可以参考使用
链接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ  密码:n7bk
[color=rgb(68, 68, 6]

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP