楼主: 一生有你llx

[原创] Linux服务器配置

[复制链接]
论坛徽章:
0
31#
 楼主| 发表于 2018-12-19 07:37 | 只看该作者
安装squid
      proxy就是软件代理或者代理服务器,而squid就是一种常用的proxy服务
1、安装squid
[root@localhost wj]# rpm -qa | grep squid
[root@localhost wj]# yum install -y squid                                                    
Installed:
  squid.i686 7:3.1.10-19.el6_4                                                                                             
Complete!
[root@localhost wj]#

2、设置防火墙,squid默认使用3128端口,用户可以自行修改一些不冲突的端口,之后要在防火墙中添加端口
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3128 -j ACCEPT
[root@localhost phpMyAdmin]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat                [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
iptables:载入额外模块:nf_conntrack_ftp                   [确定]
[root@localhost phpMyAdmin]#

3、启动squid服务
[root@localhost wj]# service squid start
正在启动squid:.                                          [确定]
[root@localhost wj]#

4、测试,在浏览器中设置http代理为Linux的ip,端口号3128
      
     随便打开一个网站,可以看到还是能正常访问,说明配置成功


使用道具 举报

回复
论坛徽章:
0
32#
 楼主| 发表于 2018-12-20 07:11 | 只看该作者
Squid缓存
     代理服务器会在本地硬盘设置缓存,这样可以提高网络效率
1修改squid配置文件“/etc/squid/squid.conf”,参数“cache_dir_ufs”就是设置缓存目录的
[root@localhost wj]#gedit /etc/squid/squid.conf
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256    //缓存目录var/spool/squid,大小100M

2、重启squid服务
[root@localhost wj]# service squid start
正在启动 squid:.                                          [确定]
[root@localhost wj]# gedit /etc/squid/squid.conf
[root@localhost wj]# service squid restart
停止 squid:2018/08/15 11:17:31| WARNING cache_mem is larger than total disk cache space!
................                                           [确定]
init_cache_dir /var/spool/squid... 正在启动 squid:.       [确定]
[root@localhost wj]#

3、查看squid缓存目录,其中swap.state会随着访问网页的增多二逐渐增大
[root@localhost wj]# ls -al /var/spool/squid/
总用量 76
drwxr-x---   18 squid squid 4096 8月  15 11:18 .
drwxr-xr-x.  15 root  root  4096 8月  15 10:50 ..
drwxr-x---  258 squid squid 4096 8月  15 11:18 00
drwxr-x---  258 squid squid 4096 8月  15 11:18 01
drwxr-x---  258 squid squid 4096 8月  15 11:18 02
drwxr-x---  258 squid squid 4096 8月  15 11:18 03
drwxr-x---  258 squid squid 4096 8月  15 11:18 04
drwxr-x---  258 squid squid 4096 8月  15 11:18 05
drwxr-x---  258 squid squid 4096 8月  15 11:18 06
drwxr-x---  258 squid squid 4096 8月  15 11:18 07
drwxr-x---  258 squid squid 4096 8月  15 11:18 08
drwxr-x---  258 squid squid 4096 8月  15 11:18 09
drwxr-x---  258 squid squid 4096 8月  15 11:18 0A
drwxr-x---  258 squid squid 4096 8月  15 11:18 0B
drwxr-x---  258 squid squid 4096 8月  15 11:18 0C
drwxr-x---  258 squid squid 4096 8月  15 11:18 0D
drwxr-x---  258 squid squid 4096 8月  15 11:18 0E
drwxr-x---  258 squid squid 4096 8月  15 11:18 0F
-rw-r-----    1 squid squid   52 8月  15 11:18 swap.state
[root@localhost wj]#

4、定期清理缓存
     在squid的缓存目录下,swap.state慢慢的变大,用户需要定时清除这个文件,或者可以做一个计划任务来清除。

使用道具 举报

回复
论坛徽章:
0
33#
 楼主| 发表于 2018-12-21 07:16 | 只看该作者
Squid连接限制
     Squid可以有效的限制连接,指定哪些用户可以连接,指定哪些网站可以访问,这样就可以有效的利用服务器带宽。
1、限制指定网段不能连接。编辑配置文件”/etc/squid/squid.conf”,利用acl语言添加受限制的ip地址
[root@localhost wj]# gedit /etc/squid/squid.conf
acl clientdeny src 192.168.0.1-192.168.0.200
http_access deny clientdeny
[root@localhost wj]# service squid restart
停止squid:................                               [确定]
正在启动squid:.                                          [确定]
     重启squid之后,使用这个代理的浏览器将不能访问任何网页
     

2、限制某个ip不能使用呢,和上面的一样使用acl语法  
[root@localhost wj]# gedit /etc/squid/squid.conf
acl clientdeny src 192.168.0.113
http_access deny clientdeny
[root@localhost wj]# service squid restart
停止squid:................                               [确定]
正在启动squid:.                                          [确定]
     重启squid之后,IP地址为“192.168.0.113”的电脑如果用了这个代理,那么它将不能访问网站
     

3、限制某些网站不能访问
[root@localhost wj]# gedit /etc/squid/squid.conf
acl domaindeny dstdomain .baidu.com
http_access deny domaindeny
[root@localhost wj]# service squid restart
停止 squid:................                               [确定]
正在启动squid:.                                          [确定]
     重启squid之后,使用这个代理的浏览器将不能访问百度
     

4、网站黑名单,可以通过一个网站列表文件形成网站黑名单,这些网站将不能被访问。
     1)在/etc/squid目录下创建爱你一个文件denyurl,在此文件内输入要拦截的网站
[root@localhost wj]# gedit /etc/squid/denyurl
.baidu.com
.hao123.com
[root@localhost wj]# service squid restart
停止squid:................                               [确定]
正在启动squid:.                                          [确定]
    2)修改配置文件“/etc/squid/squid.conf”
[root@localhost wj]# gedit /etc/squid/squid.conf
acl denyurl url_regex "/etc/squid/denyurl"     //注意这个路径就是上面定义的文件路径
http_access deny denyurl
[root@localhost wj]# service squid restart
停止squid:................                               [确定]
正在启动 squid:.                                          [确定]
    3)访问百度和hao123
     

5、限制某个时间段内不能连接  
[root@localhost wj]# gedit /etc/squid/squid.conf
acl timedeny time M 10:00-17:00    //M周一  T周二   W周三   H周四   F周五   A周六    S周日
http_access deny clientdeny
[root@localhost wj]# service squid restart
停止squid:................                               [确定]
正在启动squid:.                                          [确定]
     重启squid之后,使用这个电脑的代理将无法再星期一的10~17点上网
     

使用道具 举报

回复
论坛徽章:
0
34#
 楼主| 发表于 2018-12-24 06:58 | 只看该作者
代理认证
      proxy代理服务被广泛的使用,为了安全起见,可以在服务器上增加一层安全认证机制。这里使用htpasswd建立认证账号和密码
1、创建认证账号和密码
[root@localhost wj]# htpasswd -c /etc/squid/passwd david
New password:
Re-type new password:
Adding password for user david

2、修改认证文件,让其他用户可以读取
[root@localhost wj]# chmod o+r /etc/squid/passwd

3、查看认证服务文件
[root@localhost wj]# rpm -ql squid | grep ncsa_auth
/usr/lib/squid/ncsa_auth       //记住这个地址,下面要用到
/usr/share/man/man8/ncsa_auth.8.gz

4、修改配置文件squid.conf
[root@localhost wj]# gedit /etc/squid/squid.conf
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd        //账号位置、密码位置
auth_param basic children 5
auth_param basic realm you must author     //欢迎词上面的这三句话必须放在配置文件的开头
acl squid_user proxy_auth REQUIRED        //acl语法
http_access allow squid_user               //只允许认证的人使用

5、测试。重启服务后,用使用这个代理的电脑去上网,会弹窗要求认证
[root@localhost wj]# service squid restart
停止squid:................                               [确定]
正在启动squid:.                                          [确定]
      
      

使用道具 举报

回复
论坛徽章:
0
35#
 楼主| 发表于 2018-12-25 08:43 | 只看该作者
Ssh登录   
       Ssh是建立在应用层和传输层的安全协议,专门为远程登录回话和其他网络服务提供安全性。利用ssh可以有效的防止远程管理中的信息泄露问题,同时ssh传输的数据是经过压缩的,可以加快传输速度。

1、启动sshd服务。Centos默认已经安装了ssh,而且该服务默认是启动的
[root@localhost wj]# rpm -qa | grep ssh
libssh2-1.4.2-1.el6.i686
openssh-askpass-5.3p1-94.el6.i686
openssh-server-5.3p1-94.el6.i686
openssh-clients-5.3p1-94.el6.i686
openssh-5.3p1-94.el6.i686
[root@localhost wj]# service sshd status
openssh-daemon (pid  1634) 正在运行...
[root@localhost wj]#

2、测试登录
[root@localhost wj]# ssh root@192.168.0.119
The authenticity of host '192.168.0.119 (192.168.0.119)' can't be established.
RSA key fingerprint is 36:20:c9:ab:88:1f:47:74:1b:f1:d7:47:55:e0:14:7c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.119' (RSA) to the list of known hosts.
root@192.168.0.119's password:
Last login: Fri Aug 10 14:57:45 2018
already login
[root@localhost ~]# exit
logout
Connection to 192.168.0.119 closed.

3、禁止root登录
      root用户在Linux系统中拥有最高的权利,如果用root用户登录就意味着增大了系统的风险。Ssh默认可以使用root登录,为了安全考虑,我们可以禁止root登录。
      1)修改配置文件“/etc/ssh/sshd_config”,找到“permitRootLogin”将其改为no
[root@localhost wj]# gedit /etc/ssh/sshd_config
PermitRootLogin no    //这里默认是yes,而且已经被注释掉了。取消注释,改为no
[root@localhost wj]# service sshd restart           //重启服务
停止sshd:                                               [确定]
正在启动sshd:                                            [确定]
[root@localhost wj]#
      2)测试,使用root登录,可以看到没有权利
[root@localhost wj]# ssh root@192.168.0.119
root@192.168.0.119's password:
Permission denied, please try again.

4、设置指定用户登录
      有时候为了降低系统风险,我们还会设置指定的用户登录,而其他用户登录就会拒绝。
      1)修改配置文件“/etc/ssh/sshd_config”,在最后追加
[root@localhost wj]# gedit /etc/ssh/sshd_config
AllowUsers david    //允许david登录
[root@localhost wj]# service sshd restart           //重启服务
停止sshd:                                               [确定]
正在启动sshd:                                            [确定]
[root@localhost wj]#
      2)测试,分别使用david和weijie两个用户登录,其中weijie会登录失败
[root@localhost wj]# ssh weijie@192.168.0.119
weijie@192.168.0.119's password:
Permission denied, please try again.
[root@localhost wj]# ssh david@192.168.0.119
david@192.168.0.119's password:
Last login: Wed Aug 15 17:12:59 2018 from 192.168.0.112
already login


使用道具 举报

回复
论坛徽章:
0
36#
 楼主| 发表于 2018-12-26 09:13 | 只看该作者
Ssh配置   
        通过配置文件,我们可以有效的管理ssh
1、空闲时间关闭连接
        1)修改配置文件“/etc/ssh/sshd_config”,设置clientAliveInterval和clientAliveCountMax,注意取消前面的注释
[root@localhost wj]# gedit /etc/ssh/sshd_conf
ClientAliveInterval 10       //超时时间,10s
ClientAliveCountMax 0        //超时次数,0
[root@localhost wj]# service sshd restart           //重启服务
停止sshd:                                               [确定]
正在启动sshd:                                            [确定]
        2)测试超时,登录之后不要进行任何操作,10s之后连接就会关闭
[root@localhost wj]# ssh david@192.168.0.119
david@192.168.0.119's password:
Last login: Thu Aug 16 08:22:25 2018 from 192.168.0.119
already login
[david@localhost ~]$ Connection to 192.168.0.119 closed by remote host.
Connection to 192.168.0.119 closed.
[root@localhost wj]#

2、输入密码超时,关闭连接
        1)修改配置文件“/etc/ssh/sshd_config”,设置参数“LoginGraceTime”
[root@localhost wj]# gedit /etc/ssh/sshd_config
LoginGraceTime 10s    //这里默认是2m,代表2分钟。设置为10s,取消注释
[root@localhost wj]# service sshd restart           //重启服务
停止sshd:                                               [确定]
正在启动sshd:                                            [确定]
        2)测试,登录的时候不输入密码,连接会自动断开
[root@localhost wj]# ssh david@192.168.0.119
david@192.168.0.119's password:
Connection closed by UNKNOWN



使用道具 举报

回复
论坛徽章:
0
37#
 楼主| 发表于 2018-12-27 06:46 | 只看该作者
安装telnet     
  telnet是标准的远程登录协议,历史悠久。但是telnet的对话数据没有加密,甚至用户名和密码都是明文显示,这样的服务风险极大。目前大多数系统多已经不会再安装这个服务了,用户需要自己手动安装

1、安装telnet软件,用户可以将telnet的服务器和客户端都安装
[root@localhost wj]# rpm -qa | grep telnet
[root@localhost wj]# yum install -y telnet-server   //telnet服务器端,允许其他电脑连接
Installed:
  telnet-server.i686 1:0.17-48.el6                                                                                          
Complete!
[root@localhost wj]# yum install -y telnet      //telnet客户端,可以连接其他电脑
Installed:
  telnet.i686 1:0.17-48.el6                                                                                                
Complete!

2、配置telnet,修改配置文件“/etc/xinetd.d/telnet”,将参数disable改为no
[root@localhost wj]#gedit /etc/xinetd.d/telnet
# default: on
# description: The telnet server serves telnet sessions; it uses \
#   unencrypted username/password pairs for authentication.
Service telnet
{
    flags      = REUSE
    socket_type   = stream        
    wait       = no
    user       = root
    server     = /usr/sbin/in.telnetd
    log_on_failure    += USERID
    disable       = no  //这个默认是yes,只有改成no才可以启动telnet
}

3、修改端口。telnet默认的端口是23,用户可以修改“/etc/services”文件来改变端口。
[root@localhost wj]# gedit /etc/service
telnet          23/tcp     //为了防止被攻击,一般都不会使用23端口。注意这里的23端口要使用tcpudp两种协议
telnet          23/udp

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

5、启动telnet
[root@localhost wj]# service xinetd restart        //telnet依赖xinetd
停止xinetd:                                             [确定]
正在启动xinetd:                                          [确定]

6、测试,在window端连接telnet。注意,不要用root用户登录,默认不允许。
[root@localhost wj]# telnet 192.168.0.119
Trying 192.168.0.119...
Connected to 192.168.0.119.
Escape character is '^]'.
CentOS release 6.5 (Final)
Kernel 2.6.32-431.el6.i686 on an i686
login: david
Password:
Last login: Thu Aug 16 08:24:19 from 192.168.0.119
already login



使用道具 举报

回复
论坛徽章:
0
38#
 楼主| 发表于 2018-12-28 08:04 | 只看该作者
配置telnet     
     通过配置文件,我们可以设置telnet的连接时间、连接数、连接ip等,实现更加安全的连接
1、设置连接时间,参数“access_times”
[root@localhost wj]# gedit /etc/xinetd.d/telnet
service telnet
{
    flags      = REUSE
    socket_type   = stream        
    wait       = no
    user       = root
    server     = /usr/sbin/in.telnetd
    log_on_failure    += USERID
    disable       = no
    access_times = 08:00-09:00 13:00-15:00           //规定允许连接的时间段8~9点,13~15
}
[root@localhost wj]# service xinetd restart         //重启服务
停止xinetd:                                             [确定]
正在启动xinetd:                                          [确定]
[root@localhost wj]# telnet 192.168.0.119           //尝试连接
Trying 192.168.0.119...
Connected to 192.168.0.119.
Escape character is '^]'.
Connection closed by foreign host.                  //连接失败

2、设置连接数,通过参数“instances”可以设置允许的连接数,超过之后就无法再连接了
[root@localhost wj]# gedit /etc/xinetd.d/telnet
service telnet
{
    flags      = REUSE
    socket_type   = stream        
    wait       = no
    user       = root
    server     = /usr/sbin/in.telnetd
    log_on_failure    += USERID
    disable       = no
    instances      = 1                                   //这里设置只允许一个连接,第二个就无法连接了
}
[root@localhost wj]# service xinetd restart         //重启服务
停止xinetd:                                             [确定]
正在启动xinetd:                                          [确定]
[root@localhost wj]# telnet 192.168.0.119          //第一个连接
Connected to 192.168.0.119.
login: david      
Password:
Last login: Thu Aug 16 09:10:22 from 192.168.0.119
already login                                          //成功
[root@localhost wj]# telnet 192.168.0.119        //第二个连接
Connected to 192.168.0.119.
Connection closed by foreign host.                //失败

3、允许/禁止特定的ip或者网段登录,参数“only-from”“no_access”
[root@localhost wj]# gedit /etc/xinetd.d/telnet
service telnet
{
    flags      = REUSE
    socket_type   = stream        
    wait       = no
    user       = root
    server     = /usr/sbin/in.telnetd
    log_on_failure    += USERID
    disable       = no
    only_from  = 192.168.0.113                     //只允许113连接
#   only_from  = 192.168.0.0/24                    //允许1~254连接
#   only_from  = 192.168.0.100-192.168.0.200    //允许100~200连接
#   only_from  = 192.168.0.                        //允许113114连接
#   no_access  = 192.168.0.113                    //禁止113连接,其他写法同上
}

4、允许root连接。只要将文件“/etc/securetty”删除,那么系统读不到这个文件,自然就会永续root登录
[root@localhost wj]# mv /etc/securetty /etc/securetty.bak     //重命名该文件
[root@localhost wj]# service xinetd restart                     //重启服务
停止 xinetd:                                              [确定]
正在启动 xinetd:                                          [确定]
[root@localhost wj]# telnet 192.168.0.119                       //连接
Trying 192.168.0.119...
Connected to 192.168.0.119.
login: root                                                          //使用root用户连接
Password:                                                              
Last login: Thu Aug 16 07:51:45 from 192.168.0.119
already login                                                       //连接成功




使用道具 举报

回复
论坛徽章:
0
39#
 楼主| 发表于 2018-12-29 08:43 | 只看该作者
配置ntp   
      ntp就是网络时间同步的服务,时间的准确性非常重要,很多数据在记录时都要知道准确的时间。网上有很多站点,一般国内会设置匹配中科院国家授时中心的时间。
1、安装ntp软件
[root@localhost ~]# rpm -qa | grep ntp         //检测是否已安装,这个软件默认是安装的
ntpdate-4.2.6p5-1.el6.centos.i686
fontpackages-filesystem-1.41-1.1.el6.noarch
ntp-4.2.6p5-1.el6.centos.i686
[root@localhost ~]#

2、配置ntp站点,修改配置文件“/etc/ntp.conf”
[root@localhost wj]# gedit /etc/xinetd.d/telnet
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst    //上面这几个不要了
server ntp1.aliyun.com                    //阿里云时间服务器
server ntp2.aliyun.com
server ntp3.aliyun.com
server ntp4.aliyun.com

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

4、启动ntp服务
[root@localhost wj]# service ntpd restart
关闭ntpd:                                               [确定]
正在启动ntpd:                                            [确定]

5、检测ntp运行状态
[root@localhost wj]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
120.25.115.20   10.137.53.7      2 u    4   64    1   26.132  188282.   0.000
203.107.6.88    100.107.25.114   2 u    3   64    1   83.645  188285.   0.000

6、同步时间,使用命令ntpdate
[root@localhost wj]# ntpdate aliyun.com
16 Aug 10:07:03 ntpdate[20193]: the NTP socket is in use, exiting    //如果遇到此错误,请按照下面的方式执行
[root@localhost wj]# lsof -i:123
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
ntpd    20187  ntp   16u  IPv4 262711      0t0  UDP *:ntp         
ntpd    20187  ntp   17u  IPv6 262712      0t0  UDP *:ntp
ntpd    20187  ntp   18u  IPv4 262718      0t0  UDP localhost:ntp
ntpd    20187  ntp   19u  IPv4 262719      0t0  UDP 192.168.0.119:ntp
ntpd    20187  ntp   20u  IPv6 262720      0t0  UDP localhost:ntp
ntpd    20187  ntp   21u  IPv6 262721      0t0  UDP [fe80::a00:27ff:fe14:3357]:ntp
[root@localhost wj]# kill -9 20187     //杀掉上面的进程
[root@localhost wj]# ntpdate 202.112.29.82
16 Aug 10:13:21 ntpdate[20212]: adjust time server 202.112.29.82 offset 0.006454 sec


使用道具 举报

回复
论坛徽章:
0
40#
 楼主| 发表于 2018-12-29 08:50 | 只看该作者
做了一个Linux学习的平台,目前出来一个雏形,各位可以参考使用
链接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ  密码:n7bk


使用道具 举报

回复

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

本版积分规则 发表回复

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