楼主: 一生有你llx

[原创] Linux服务器配置

[复制链接]
论坛徽章:
0
21#
 楼主| 发表于 2018-12-6 20:45 | 只看该作者
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




使用道具 举报

回复
论坛徽章:
0
22#
 楼主| 发表于 2018-12-7 08:54 | 只看该作者
ftp限制IP
1、通过vsftpd的配置文件以及“hosts.deny”和“hosts.allow”文件设置允许某个ip地址访问
      1)修改配置文件“/etc/vsftpd/vsftpd.conf”中的参数“tcp_wrapper”,确保这个参数是yes
[root@localhost wj]# gedit /etc/vsftpd/vsftpd.conf        //匿名登录
tcp_wrapper=YES
      2)打开配置文件“/etc/hosts.deny“,在末尾追加一句话”vsftpd:alleny“
[root@localhost wj]# gedit /etc/hosts.deny
# hosts.deny  This file contains access rules which are used to
#      deny connections to network services that either use
#      the tcp_wrappers library or that have been
#      started through a tcp_wrappers-enabled xinetd.
#
#      The rules in this file can also be set up in
#      /etc/hosts.allow with a 'deny' option instead.
#
#      See 'man 5 hosts_options' and 'man 5 hosts_access'
#      for information on rule syntax.
#      See 'man tcpd' for information on tcp_wrappers
#
vsftpd:alleny       //所有的ip都不可以访问
      3)打开配置文件“/etc/hosts.allow“,在末尾追加一句话”vsftpd:192.168.0.123:Allow“。当前的配置就是只允许“192.168.0.123”访问
[root@localhost wj]# gedit /etc/hosts.allow
# hosts.allow This file contains access rules which are used to
#      allow or deny connections to network services that
#      either use the tcp_wrappers library or that have been
#      started through a tcp_wrappers-enabled xinetd.
#
#      See 'man 5 hosts_options' and 'man 5 hosts_access'
#      for information on rule syntax.
#      See 'man tcpd' for information on tcp_wrappers
#
vsftpd:192.168.0.123:Allow
      4)测试是否可以访问,当前主机的ip并不是“192.168.0.123”,因此访问不会成功的
[root@localhost wj]# service vsftpd restart        //重启服务
关闭vsftpd:                                             [确定]
为 vsftpd 启动vsftpd:                                    [确定]
[root@localhost wj]# lftp weijie:123456@192.168.0.113:8765     //本地用户登录
中断                                                                     //ls失败,并没有连接成功
[root@localhost wj]# lftp 192.168.0.113:8765                     //匿名登录
lftp 192.168.0.113:~> ls
中断                                                                     //ls失败,并没有连接成功
lftp 192.168.0.113:~>

2、当一个ip地址对主机的连接太多时,就会降低服务器的效率。因此有必要设置一个IP的连接数,当连接超过一定的数量就不能再连了,这样就可以提高服务器的效率。Vsftpd默认没有连接设置,可以通过参数“max_clients“来设置。由于同一个局域网的ip是一样的,因此这个最大连接数要合理设置。
      1)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”max_clients=2“
[root@localhost pub]# gedit /etc/vsftpd/vsftpd.conf
max_clients=2
      2)重启服务,测试。一次打开三个连接,发现第三个连接不能访问
[root@localhost wj]# service vsftpd restart        //重启服务
关闭vsftpd:                                             [确定]
为 vsftpd 启动vsftpd:                                    [确定]
[root@localhost wj]# lftp weijie:123456@192.168.0.113:8765        //登录weijie
-rwxrwxrwx    1 0        0        2375494044 Aug 14 07:13 1.zip
[root@localhost wj]# lftp 192.168.0.113:8765                       //匿名登录
lftp 192.168.0.113:~> ls
drwxr-xr-x    2 0        0            4096 Aug 14 06:38 pub
lftp 192.168.0.113:/>
[root@localhost pub]# lftp 192.168.0.113                          //匿名登录
lftp 192.168.0.113:~> ls
[0] ls &                                 
    `ls' at 0 [重新连接前延时: 22]                                  //不能再访问,ls失效
lftp 192.168.0.113:~>


使用道具 举报

回复
论坛徽章:
0
23#
 楼主| 发表于 2018-12-9 07:25 | 只看该作者
用户黑白名单
      一个Linux主机中会多个用户,而我们希望有些用户不能去访问ftp。ftp服务器可以通过配置文件“/etc/vsftpd/user_list”来设置一个用户列表,这个列表可以是黑名单,也可以是白名单,具体要根据配置文件的参数“userlist_deny”来确定

1、黑名单
      1)修改配置文件“/etc/vsftpd/vsftpd.conf”中的参数“userlist_enable”,确保这个参数是yes
[root@localhost wj]# gedit /etc/vsftpd/vsftpd.conf        //匿名登录
userlist_enable=YES
      2)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”userlist_deny=yes“。这个参数是yes,表示要设置一个黑名单
[root@localhost wj]# lftp david:543092@192.168.0.113:8765    //用户david登录,密码是543092
userlist_deny=YES
      3)编辑文件“/etc/vsftpd/user_list“,在末尾追加一句话要设置的用户名即可
[root@localhost ~]#gedit /etc/vsftpd/user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
david
      4)重启服务,测试黑名单内的用户是否可以访问,上面列出的都是不可以访问的用户
[root@localhost wj]# service vsftpd restart        //重启服务
关闭vsftpd:                                             [失败]
为 vsftpd 启动vsftpd:                                    [确定]
[root@localhost wj]# lftp weijie:123456@192.168.0.113:8765     //用户weijie登录,可以访问
-rwxrwxrwx    1 0        0        2375494044 Aug 14 07:13 1.zip
[root@localhost wj]# lftp 192.168.0.113:8765                //匿名用户也可以
lftp 192.168.0.113:~> ls
drwxr-xr-x    2 0        0            4096 Aug 14 06:38 pub
lftp 192.168.0.113:/>
[root@localhost wj]# lftp david:543092@192.168.0.113:8765    //用户david在黑名单中,因此无法访问,ls命令会失败
[0] ls &                                 
    `ls' at 0 [重新连接前延时: 28]

2、白名单
      1)修改配置文件“/etc/vsftpd/vsftpd.conf”中的参数“userlist_enable”,确保这个参数是yes
[root@localhost wj]# gedit /etc/vsftpd/vsftpd.conf        //匿名登录
userlist_enable=YES
      2)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”userlist_deny=NO“。这个参数是NO,表示要设置一个白名单
[root@localhost wj]# lftp david:543092@192.168.0.113:8765    //用户david登录,密码是543092
userlist_deny=NO
      3)编辑文件“/etc/vsftpd/user_list“,在末尾追加一句话要设置的用户名即可
[root@localhost ~]#gedit /etc/vsftpd/user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
david
      4)重启服务,测试黑名单内的用户是否可以访问,上面列出的都是不可以访问的用户
[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 07:13 1.zip
[root@localhost wj]# lftp weijie:123456@192.168.0.113:8765    //用户weijie不在白名单中,因此无法访问,ls命令会失败
[0] ls &                                 
    `ls' at 0 [重新连接前延时: 28]
[root@localhost wj]# lftp 192.168.0.113:8765         //匿名用户也不行
lftp 192.168.0.113:~> ls
[0] ls &                                 
    `ls' at 0 [重新连接前延时: 28]
lftp 192.168.0.113:~>



使用道具 举报

回复
论坛徽章:
0
24#
 楼主| 发表于 2018-12-10 14:50 | 只看该作者
FTP其他配置
      在配置文件中,还有一些关于vsftpd的其他设置,这里列出来
# Example config file /etc/vsftpd/vsftpd.conf
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES       //是否允许匿名登录
#
# Uncomment this to allow local users to log in.
local_enable=YES         //是否允许本地用户登录
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES        //是否允许写操作
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022      //本地用农户权限掩码
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES     //是否允许匿名用户上传
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES    //是否允匿名用户创建目录
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES    //是否允许获取目录信息
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES        //是否允许其他用户拥有匿名用户上传的文件
#chown_username=whoever
# You may change the default value for timing out an idle session.
#idle_session_timeout=600    //连接空闲超时
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120    //数据请求超时
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES    //是否允许ls命令使用-R参数,递归
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_local_user=YES    //是否允许用户切换目录
#chroot_list_enable=YES    //是否允许指定的用户切换目录,用户名单在/etc/vsftpd/chroot_list文件中
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list  //这个文件中的用户不能切换目录


使用道具 举报

回复
论坛徽章:
0
25#
 楼主| 发表于 2018-12-11 10:39 | 只看该作者
安装bind
1、安装bind软件,需要安装3 个bind、bind-chroot、bind-util
[root@localhost pub]# yum install -y bind bind-chroot bind-utils
Installed:
  bind.i686 32:9.8.2-0.17.rc1.el6_4.6                                                                                    
Complete!

2、修改配置文件“/etc/named.conf”,追加“forward”
[root@localhost pub]# gedit /etc/named.conf
options {
    listen-on port 53 { 127.0.0.1; };
#   listen-on-v6 port 53 { ::1; };
    directory "/var/named";
    dump-file "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
    allow-query     { localhost; };
    recursion yes;
    dnssec-enable yes;
    dnssec-validation yes;
    dnssec-lookaside auto;
    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";
    managed-keys-directory "/var/named/dynamic";
    forward only;
    forwarders{
       8.8.8.8;   
    }
};

3、设置防火墙,这里需要用到53端口。需要开启tcp和udp的53端口,记得重启防火墙
[root@localhost pub]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT
[root@localhost phpMyAdmin]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat                [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
iptables:载入额外模块:nf_conntrack_ftp                   [确定]
[root@localhost phpMyAdmin]#

4、启动服务
[root@localhost pub]# service named start
启动named:                                              [确定]
[root@localhost pub]#

5、测试,命令格式“dig 网站@ip”,这里用回环地址来测试,看是否能请求成功
[root@localhost pub]# dig www.baidu.com @127.0.0.1
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> www.baidu.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51491
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.baidu.com.          IN  A
;; ANSWER SECTION:
www.baidu.com.       1191   IN  CNAME  www.a.shifen.com.
www.a.shifen.com. 299IN  A   14.215.177.38      //这个就是请求到的结果
www.a.shifen.com. 299IN  A   14.215.177.39
;; Query time: 3053 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Aug 14 19:02:59 2018
;; MSG SIZE  rcvd: 90

6、更改配置文件named.conf,让所有机器都可以使用该服务。
1)将配置文件中的回环地址改为any,意味着允许任何人使用
[root@localhost pub]# gedit /etc/named.conf
options {
    listen-on port 53 {any; };
#   listen-on-v6 port 53 { ::1; };
    directory "/var/named";
    dump-file "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
    allow-query     { any; };
    recursion yes;
    dnssec-enable yes;
    dnssec-validation yes;
    dnssec-lookaside auto;
    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";
    managed-keys-directory "/var/named/dynamic";
    forward only;
    forwarders{
       8.8.8.8;   
    }
};
2)找一个其他ip地址来测试
[root@localhost pub]# service named restart   //重启服务
停止named:                                              [确定]
启动named:                                              [确定]
[root@localhost pub]# dig www.baidu.com @192.168.0.113
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> www.baidu.com @192.168.0.113
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37134
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.baidu.com.          IN  A
;; ANSWER SECTION:
www.baidu.com.       871 IN  CNAME  www.a.shifen.com.
www.a.shifen.com. 299 IN  A   14.215.177.39
www.a.shifen.com. 299 IN  A   14.215.177.38
;; Query time: 474 msec
;; SERVER: 192.168.0.113#53(192.168.0.113)
;; WHEN: Tue Aug 14 19:06:19 2018
;; MSG SIZE  rcvd: 90


使用道具 举报

回复
论坛徽章:
0
26#
 楼主| 发表于 2018-12-12 15:42 | 只看该作者
配置bind
1、确定已经安装bind软件,需要安装3 个bind、bind-chroot、bind-util
[root@localhost wj]# yum install y bind bind-chroot bind-util

2、修改配置文件“/etc/named.conf”
[root@localhost pub]# gedit /etc/named.conf
options {
#   listen-on port 53 { 127.0.0.1; };
#   listen-on-v6 port 53 { ::1; };
    directory "/var/named";
    。。。
};
。。。。
zone "david.cn" IN{      //正向解析配置
    type master;
    file "david.cn";    //注意名字,后面要用到这个名字
    allow-update {none;};
};
zone "0.168.192.in-addr.arpa" IN{   //反向解析配置
    type master;
    file "192.168.0";   //注意名字,后面要用到这个名字
    allow-update {none;};
};

3、编辑正向配置文件“/var/named/david.cn”,这个文件不存在,用户需要自己创建
[root@localhost pub]# gedit /var/named/david.cn
$TTL 86400
@   IN  SOAbind.david.cn. root.david.cn. (
    2011071001
    3600
    1800
    604800
    86400
)
    IN NS      bind.david.cn.
    IN A       192.168.0.113     //这个是本机ip
    IN MX 10   mailsrv.david.cn.
bind   IN A       192.168.0.113
mailsrv IN A  192.168.0.250
www IN CNAME   bind.david.cn.

4、编辑反向配置文件“/var/named/192.168.0”,这个文件不存在,用户需要自己创建
[root@localhost pub]# gedit /var/named/192.168.0
$TTL 86400
@   IN  SOAbind.david.cn. root.david.cn. (
    2011071001
    3600      
    1800      
    604800     
    86400      
)
    IN NS      bind.david.cn.
    IN PTR david.cn.
    IN A       255.255.255.0
113    IN PTRbind.david.cn.
250 IN PTRmailsrv.david.cn

5、重启服务(确保防火墙的53端口已经打开)
[root@localhost wj]# service named restart
停止named:                                              [确定]
启动named:                                              [确定]
[root@localhost wj]#

6、测试
[root@localhost wj]# nslookup
> server 192.168.0.113          //切换dns服务器为上面配置好的
Default server: 192.168.0.113
Address: 192.168.0.113#53
> bind.david.cn               //正向解析A类型
Server:       192.168.0.113
Address:   192.168.0.113#53
Name:  bind.david.cn
Address: 192.168.0.113
> mailsrv.david.cn        //正向解析A类型
Server:       192.168.0.113
Address:   192.168.0.113#53
Name:  mailsrv.david.cn
Address: 192.168.0.250
> set q=mx             //正向解析MX类型
> david.cn
Server:       192.168.0.113
Address:   192.168.0.113#53
david.cn   mail exchanger = 10 mailsrv.david.cn.
> www.david.cn     //正向解析CNAME类型
Server:       192.168.0.113
Address:   192.168.0.113#53
www.david.cn  canonical name = bind.david.cn.
> 192.168.0.113     //反向解析
Server:       192.168.0.113
Address:   192.168.0.113#53
113.0.168.192.in-addr.arpa  name = bind.david.cn.
> 192.168.0.250       //反向解析
Server:       192.168.0.113
Address:   192.168.0.113#53
250.0.168.192.in-addr.arpa  name = mailsrv.david.cn.0.168.192.in-addr.arpa.
>


使用道具 举报

回复
论坛徽章:
0
27#
 楼主| 发表于 2018-12-13 07:35 | 只看该作者
安装samba  
1、检测samba是否安装,如果没有,那么可以使用yum来安装。至少需要安装3个软件:samba,samba-client、samba-common
[root@localhost pub]# rpm -qa | grep samba
samba-winbind-clients-3.6.9-164.el6.i686
samba-client-3.6.9-164.el6.i686
samba-common-3.6.9-164.el6.i686
samba4-libs-4.0.0-58.el6.rc4.i686
samba-winbind-3.6.9-164.el6.i686
[root@localhost pub]# yum install y samba samba-client samba-common    //如果没有,那么可以用此命令安装

2、创建共享目录
[root@localhost /]# mkdir /wj        //创建目录
[root@localhost /]# chmod 777 /wj   //设置权限

3、修改配置文件“/etc/samba/smb.cnf”
[root@localhost /]#gedit /etc/samba/smb.conf
# ----------------------- Standalone Server Options ------------------------
# Scurity can be set to user, share(deprecated) or server(deprecated)
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration
    security = share           //这里默认是user,改为share,这样不用输入密码就可访问
    passdb backend = tdbsam
    [wj]                //创建共享目录配置
    comment=wj       //名字
    path=/wj         //路径
    read only=no    //是否只读,这里为no,这样用户就可以创建文件夹
    guest ok=yes    //是否允许guest用户登录
    browseable=yes //是否可以浏览目录

4、修改防火墙,打开tcp的端口137、138、139、445
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 137 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 138 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
[root@localhost wj]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat                [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
iptables:载入额外模块:nf_conntrack_ftp                   [确定]

5、启动smb服务
[root@localhost wj]# service smb start
启动 SMB 服务:                                            [确定]

6、测试,在终端输入命令“testparm”,可以看到共享目录的信息
[root@localhost wj]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[wj]"
WARNING: The security=share option is deprecated
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[global]
    workgroup = MYGROUP
    server string = Samba Server Version %v
    security = SHARE
    log file = /var/log/samba/log.%m
    max log size = 50
    idmap config * : backend = tdb
    cups options = raw
[homes]
    comment = Home Directories
    read only = No
    browseable = No
[printers]
    comment = All Printers
    path = /var/spool/samba
    printable = Yes
    print ok = Yes
    browseable = No
[wj]
    comment = wj            //名字
    path = /wj              //路径
    read only = No         //是否只读
    guest ok = Yes         //是否允许guest访问
7、从windows测试,按下快捷键“window+r”,在弹出的窗口输入命令“smb:\\192.168.0.113”,可以看到本机的共享目录
     
     

使用道具 举报

回复
论坛徽章:
0
28#
 楼主| 发表于 2018-12-14 08:48 | 只看该作者
配置samba使用用户名和密码登录   
1、当samba配置文件中的secure设置为user的时候,需要正确的用户名和密码才能登录。
root@localhost /]#gedit /etc/samba/smb.conf
# ----------------------- Standalone Server Options ------------------------
# Scurity can be set to user, share(deprecated) or server(deprecated)
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration
    security = user           //这是默认值,需要用户名密码
    passdb backend = tdbsam

2、管理账户和密码
     samba默认使用tdbsam数据库管理机制来统一管理用户名和密码,使用的命令是pdbedit,命令如下
命令
说明
pdbedit -L
列出samba用户列表
pdbedit -Lv
列出samba用户详细信息
pdbedit -Lw
列出smbpasswd格式的用户
pdbedit –a wj
增加用户wj
pdbedit –x wj
删除用户wj
pdbedit –c “[D]” –u wj
暂停用户wj
pdbedit –c “[]” –u wj
回复用户wj

3、添加用户,必须确保这个用户存在于你的Linux系统中
[root@localhost wj]# pdbedit -a david    //添加用户david
new password:
retype new password:
Unix username:        david
NT username:         
Account Flags:        [U          ]
User SID:             S-1-5-21-1098217942-694112815-2930643030-1000
Primary Group SID:    S-1-5-21-1098217942-694112815-2930643030-513
Full Name:            david
Home Directory:       \\localhost\david
HomeDir Drive:        
Logon Script:         
Profile Path:         \\localhost\david\profile
Domain:               LOCALHOST
Account desc:         
Workstations:         
Munged dial:         
Logon time:           0
Logoff time:          never
Kickoff time:         never
Password last set:    三, 15 8月 2018 10:15:21 CST
Password can change:  三, 15 8月 2018 10:15:21 CST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
[root@localhost wj]# pdbedit -L    //查看是否添加成功
david:500:david

4、重启smb服务
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 137 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 138 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
[root@localhost wj]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat                [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
iptables:载入额外模块:nf_conntrack_ftp                   [确定]

5、启动smb服务
[root@localhost wj]# service smb restart
关闭 SMB 服务:                                            [确定]
启动 SMB 服务:                                            [确定]
[root@localhost wj]#

6、从windows测试,按下快捷键“window+r”,在弹出的窗口输入命令“smb:\\192.168.0.113”,要求输入用户名和密码,匿名用户也无法登陆。
     
     
     用户登录后,只能查看自己的家目录,不能选择其他目录
     
     

使用道具 举报

回复
论坛徽章:
0
29#
 楼主| 发表于 2018-12-17 08:11 | 只看该作者
安装swat
      swat是一个图形化的samba管理软件,可以帮助不熟悉的人去灵活的配置samba服务,
1、安装swat
[root@localhost wj]#yum install -y samba-swat
Dependency Updated:
  libsmbclient.i686 0:3.6.23-51.el6  samba.i686 0:3.6.23-51.el6               
  samba-client.i686 0:3.6.23-51.el6  samba-common.i686 0:3.6.23-51.el6         
  samba-winbind.i686 0:3.6.23-51.el6 samba-winbind-clients.i686 0:3.6.23-51.el6
Complete!
[root@localhost wj]#

2、修改swat配置文件“/etc/xinetd.d/swat”
[root@localhost wj]# gedit /etc/xinetd.d/swat
service swat
{
    port       = 901    //端口号
    socket_type   = stream
    wait       = no
    only_from = 127.0.0.1    //是否只允许本机登录,如果想在其他电脑登录,那么用#注释掉这句话。
    user       = root
    server     = /usr/sbin/swat
    log_on_failure    += USERID
    disable       = no   //这里一定要是no,默认yes
}

3、修改防火墙,添加tcp的901端口
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 901 -j ACCEPT
[root@localhost wj]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat                [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
iptables:载入额外模块:nf_conntrack_ftp                   [确定]

4、启动swat服务
[root@localhost wj]# service xinetd start
正在启动xinetd:   

5、在浏览器输入“ip:901”,可以看到一个图形化的管理界面
     

使用道具 举报

回复
论坛徽章:
0
30#
 楼主| 发表于 2018-12-18 07:23 | 只看该作者
DansGuardian
      DansGuardian可以限制客户端的访问,通过这个软件,我们可以限制哪些网站不可以访问、哪些内容不能下载。

2、安装
[root@localhost wj]# rpm -ivh dansguardian-2.8.0.6-1.2.el5.rf.i386.rpm
warning: dansguardian-2.8.0.6-1.2.el5.rf.i386.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
Preparing...               ########################################### [100%]
   1:dansguardian          ########################################### [100%]

3、修改配置文件“/etc/dansguardian/dansguardian.conf”,搜索“filterport”将端口改为8088。默认是8080,和tomcat冲突。关于proxyport端口,使用的是proxy服务器端口,默认3128,如果你修改了proxy的端口,那么这里也要改成对应的端口。
[root@localhost wj]# gedit /etc/dansguardian/dansguardian.conf
# the port that DansGuardian listens to.
filterport = 8088

4、配置防火墙,打开tcp的8088端口
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8088 -j ACCEPT
[root@localhost wj]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat                [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
iptables:载入额外模块:nf_conntrack_ftp                   [确定]

5、启动服务
[root@localhost wj]# service dansguardian start
正在关闭 Web Content Filter (dansguardian):               [确定]
启动 Web Content Filter (dansguardian):                   [确定]

6、修改客户端的代理设置,将代理端口改成dansguardian的端口8088,然后去百度一些内容,不良的网站就被屏蔽了。注意,这里端口必须修改,不可以使用3128.
      
     


7、增加过滤网址。
1)修改配置文件“/etc/dansguardian/bannedsitelist”,在后面追加要过滤的网址。重启服务
[root@localhost wj]# gedit /etc/dansguardian/bannedsitelist
# You will need to edit to add and remove categories you want
news.baidu.com
[root@localhost wj]# service dansguardian restart
正在关闭 Web Content Filter (dansguardian):               [确定]
启动 Web Content Filter (dansguardian):                   [确定]
2)客户端访问百度新闻
      

8、过滤关键字
1)修改配置文件“/etc/dansguardian/bannedphraselist”,在后面追加要过滤的网址。重启服务
[root@localhost wj]# gedit /etc/dansguardian/bannedphraselist
# To block any page with words that contain the string "sex". (ie. sexual)
<sex>
[root@localhost wj]# service dansguardian restart
正在关闭 Web Content Filter (dansguardian):               [确定]
启动 Web Content Filter (dansguardian):                   [确定]
2)使用客户端浏览器搜索sex,发现网页打不开
      
     


9、过滤下载内容
1)修改配置文件“/etc/dansguardian/bannedextentsionlist”,里面默认已经有很多被禁止下载的格式了,如果要去掉某个限制,在前面加#
[root@localhost wj]# gedit /etc/dansguardian/bannedextentsionlist
#Banned extension list
.ade  # Microsoft Access project extension
.adp  # Microsoft Access project
.asx  # Windows Media Audio / Video
.bas  # Microsoft Visual Basic class module
.bat  # Batch file
.cab  # Windows setup file
.chm  # Compiled HTML Help file
.cmd  # Microsoft Windows NT Command script
[root@localhost wj]# service dansguardian restart
正在关闭 Web Content Filter (dansguardian):               [确定]
启动 Web Content Filter (dansguardian):                   [确定]
2)使用客户端浏览器下载一个文件
      

10、查看日志。可以通过日志文件“/var/log/dansguardian/access.log”来分析当前哪些内容被拦截了。
[root@localhost wj]# gedit /var/log/dansguardian/access.log
Sella&utm_term=wkjxxx0913 *DENIED* 禁止的文件扩展名: .exe GET 0
2018.8.15 16:29:07 - 192.168.0.112 http://xiazai.mindmanager.cc/favicon.ico  GET 345
module=&appid=1155&mid=bc7ba9731b77d3e10d329f751e774f1c&userid=0&token=&version=2.6.4&vipType=0&album_id=517209  GET 318




使用道具 举报

回复

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

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表