debian10

一、配置网络源

#系统默认可能会使用光盘源,修改为网络源

su - root #切换到root用户

nano /etc/apt/sources.list #设置源

#deb cdrom:[Debian GNU/Linux 10.9.0 _Buster #注释掉光盘源这一行

#添加以下代码

###网易
deb http://mirrors.163.com/debian/ buster main non-free contrib
deb http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ buster main non-free contrib
deb-src http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ buster/updates main non-free contrib

###清华
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian buster stable
# deb-src [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian buster stable
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free

我们使用163的Debian-security镜像,Debian 10的发型代号是buster

ctrl+o #保存配置

ctrl+x #退出

apt-get update #更新软件源

apt-get install sudo #安装sudo命令

二、设置IP地址、网关、DNS

1、设置ip地址、网关

nano /etc/network/interfaces #编辑网卡配置文件

auto lo

auto ens33 #开机自动连接网络

iface lo inet loopback

allow-hotplug ens33

iface ens33 inet static #static表示使用固定ip,dhcp表述使用动态ip

address 192.168.21.109 #设置ip地址

netmask 255.255.255.0 #设置子网掩码

gateway 192.168.21.2 #设置网关

ctrl+o #保存配置

ctrl+x #退出

2、设置DNS

nano /etc/resolv.conf #编辑配置文件

nameserver 8.8.8.8 #设置首选dns

nameserver 8.8.4.4 #设置备用dns

ctrl+o #保存配置

ctrl+x #退出

service networking restart #重启网络

3、安装ssh服务

OpenSSh 分为客户端openssh-client 与服务端 openssh-server.一般情况下,我们的linux系统都会自带 client端的。

apt-get install openssh-client
apt-get install openssh-server

配置文件sshd_config

Port 22  #设置ssh监听的端口号,默认22端口
ListenAddress ::
ListenAddress 0.0.0.0  #指定监听的地址,默认监听所有;
Protocol 2,1   #指定支持的SSH协议的版本号。'1'和'2'表示仅仅支持SSH-1和SSH-2协议。
#"2,1"表示同时支持SSH-1和SSH-2协议。#
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key    #HostKey是主机私钥文件的存放位置; 
#SSH-1默认是 /etc/ssh/ssh_host_key 。SSH-2默认是 /etc/ssh/ssh_host_rsa_key和
#/etc/ssh/ssh_host_dsa_key 。一台主机可以拥有多个不同的私钥。"rsa1"仅用于SSH-1,
#"dsa"和"rsa"仅用于SSH-2。
UsePrivilegeSeparation yes     #是否通过创建非特权子进程处理接入请求的方法来进行权
#限分 离。默认值是"yes"。 认证成功后,将以该认证用户的身份创另一个子进程。这样做的目的是
#为了防止通过有缺陷的子进程提升权限,从而使系统更加安全。
KeyRegenerationInterval 3600   #在SSH-1协议下,短命的服务器密钥将以此指令设置的时
#间为周期(秒),不断重新生成;这个机制可以尽量减小密钥丢失或者黑客攻击造成的损失。设为 0 
#表示永不重新生成为 3600(秒)。
ServerKeyBits 1024    #指定服务器密钥的位数
SyslogFacility AUTH   #指定 将日志消息通过哪个日志子系统(facility)发送。有效值是:
#DAEMON, USER, AUTH(默认), LOCAL0, LOCAL1, LOCAL2, LOCAL3,LOCAL4, LOCAL5, 
#LOCAL6, LOCAL7
LogLevel INFO     #指定日志等级(详细程度)。可用值如下:QUIET, FATAL, ERROR, INFO
#(默认), VERBOSE, DEBUG, DEBUG1, DEBUG2, DEBUG3,DEBUG 与 DEBUG1 等价;DEBUG2
# 和 DEBUG3 则分别指定了更详细、更罗嗦的日志输出。比 DEBUG 更详细的日志可能会泄漏用户
# 的敏感信息,因此反对使用。
LoginGraceTime 120  #限制用户必须在指定的时限(单位秒)内认证成功,0 表示无限制。默认
#值是 120 秒;如果用户不能成功登录,在用户切断连接之前服务器需要等待120秒。
PermitRootLogin yes  #是否允许 root 登录。可用值如下:"yes"(默认) 表示允许。
#"no"表示禁止。"without-password"表示禁止使用密码认证登录。"forced-commands-only"
#表示只有在指定了 command 选项的情况下才允许使用公钥认证登录,同时其它认证方法全部被禁止。
#这个值常用于做远程备份之类的事情。
StrictModes yes       #指定是否要求 sshd(8) 在接受连接请求前对用户主目录和相关的配
#置文件 进行宿主和权限检查。强烈建议使用默认值"yes"来预防可能出现的低级错误。
RSAAuthentication yes  #是否允许使用纯 RSA 公钥认证。仅用于SSH-1。默认值是"yes"。
PubkeyAuthentication yes  #是否允许公钥认证。仅可以用于SSH-2。默认值为"yes"。
IgnoreRhosts yes    #是否取消使用 ~/.ssh/.rhosts 来做为认证。推荐设为yes。
RhostsRSAAuthentication no  #这个选项是专门给 version 1 用的,使用 rhosts 档案在                  
#/etc/hosts.equiv配合 RSA 演算方式来进行认证!推荐no。
HostbasedAuthentication no    #这个与上面的项目类似,不过是给 version 2 使用的
IgnoreUserKnownHosts no          #是否在 RhostsRSAAuthentication 或 
#HostbasedAuthentication 过程中忽略用户的 ~/.ssh/known_hosts 文件。默认值是"no"。
#为了提高安全性,可以设为"yes"。
PermitEmptyPasswords no         #是否允许密码为空的用户远程登录。默认为"no"。
ChallengeResponseAuthentication no   #是否允许质疑-应答(challenge-response)认         
#证。默认值是"yes",所有 login.conf中允许的认证方式都被支持。
PasswordAuthentication yes      # 是否允许使用基于密码的认证。默认为"yes"。
KerberosAuthentication no    #是否要求用户为 PasswordAuthentication 提供的密码
#必须通 过 Kerberos KDC 认证,也就是是否使用Kerberos认证。使用Kerberos认证,服务器
#需要一个可以校验 KDC identity 的 Kerberos servtab 。默认值是"no"。
KerberosGetAFSToken no       #如果使用了 AFS 并且该用户有一个 Kerberos 5 TGT,
#那么开   启该指令后,将会在访问用户的家目录前尝试获取一个 AFS  token 。默认为"no"。
KerberosOrLocalPasswd yes   #如果 Kerberos 密码认证失败,那么该密码还将要通过其它
#的 认证机制(比如 /etc/passwd)。默认值为"yes"。
KerberosTicketCleanup yes    #是否在用户退出登录后自动销毁用户的 ticket 。默认
#"yes"。
GSSAPIAuthentication no      #是否允许使用基于 GSSAPI 的用户认证。默认值为"no"。
#仅用 于SSH-2。
GSSAPICleanupCredentials yes   #是否在用户退出登录后自动销毁用户凭证缓存。默认值      
#是"yes"。仅用于SSH-2。
X11Forwarding no    #是否允许进行 X11 转发。默认值是"no",设为"yes"表示允许。如果
#允许X11转发并且sshd代理的显示区被配置为在含有通配符的地址(X11UseLocalhost)上监听。
#那么将可能有额外的信息被泄漏。由于使用X11转发的可能带来的风险,此指令默认值为"no"。需
#要注意的是,禁止X11转发并不能禁止用户转发X11通信,因为用户可以安装他们自己的转发器。如
#果启用了 UseLogin ,那么X11转发将被自动禁止。
X11DisplayOffset 10    #指定X11 转发的第一个可用的显示区(display)数字。默认值                   
#是 10 。这个可以用于防止 sshd 占用了真实的 X11 服务器显示区,从而发生混淆。
PrintMotd no                #登入后是否显示出一些信息呢?例如上次登入的时间、地点等
#等,预设是 yes ,但是,如果为了安全,可以考虑改为 no !
PrintLastLog yes           #指定是否显示最后一位用户的登录时间。默认值是"yes"
TCPKeepAlive yes       #指定系统是否向客户端发送 TCP keepalive 消息。默认值是"yes"
#。这种消息可以检测到死连接、连接不当关闭、客户端崩溃等异常。可以设为"no"关闭这个特性。
UseLogin no               #是否在交互式会话的登录过程中使用 login。默认值是"no"。
#如果开启此指令,那么 X11Forwarding 将会被禁止,因为 login 不知道如何处理 xauth 
#cookies 。需要注意的是,login是禁止用于远程执行命令的。如果指定了 
#UsePrivilegeSeparation ,那么它将在认证完成后被禁用。
MaxStartups 10        #最大允许保持多少个未认证的连接。默认值是 10 。到达限制后,
#将不再接受新连接,除非先前的连接认证成功或超出 LoginGraceTime 的限制。
MaxAuthTries 6     #指定每个连接最大允许的认证次数。默认值是 6 。如果失败认证的次数超
#过这个数值的一半,连接将被强制断开,且会生成额外的失败日志消息。
UseDNS no          #指定是否应该对远程主机名进行反向解析,以检查此主机名是否与其IP
#地址真实对应。
Banner /etc/issue.net   #将这个指令指定的文件中的内容在用户进行认证前显示给远程用户。
#这个特性仅能用于SSH-2,默认什么内容也不显示。"none"表示禁用这个特性。
Subsystem sftp /usr/lib/openssh/sftp-server   #配置一个外部子系统(例如,一个文件
#传输守   护进程)。仅用于SSH-2协议。值是一个子系统的名字和对应的命令行(含选项和参数)。
UsePAM yes     #是否使用PAM模块认证

4、ll命令的使用

sudo vim ~/.bashrc
找到alias ll=’ls -l’将前面的’#'去掉就可以了

三、更改网卡名称为eth*模式

默认安装完成之后,服务器网卡为ens模式,这台服务器是ens33,我们修改为eth模式。

cp /etc/default/grub /etc/default/grub-bak #备份配置文件

sed -i '/GRUB_CMDLINE_LINUX=/s/"$/net.ifnames=0 biosdevname=0"/' /etc/default/grub #修改文件

其实就是修改  /etc/default/grub文件里面的参数

GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"

update-grub #使配置文件生效

cp /etc/network/interfaces  /etc/network/interfaces-bak #备份配置文件
sed -i 's/ens33/eth0/' /etc/network/interfaces  #替换ens33为eth0

reboot #重启系统

下载指定版本的docker

https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/dists/buster/pool/stable/amd64/

apt-cache policy  xxx的作用

显示该软件包是否已经安装,在哪个版本的仓库中可用,以及它的优先级。

默认情况下,每个已安装的软件包版本的优先级为 100,未安装的软件包的优先级为 500

 apt-cache policy docker-ce
docker-ce:
  已安装:5:20.10.8~3-0~debian-buster
  候选: 5:20.10.8~3-0~debian-buster
  版本列表:
 *** 5:20.10.8~3-0~debian-buster 500
        500 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian buster/stable amd64 Packages
        500 https://mirrors.aliyun.com/docker-ce/linux/debian buster/stable amd64 Packages
        100 /var/lib/dpkg/status
     5:20.10.7~3-0~debian-buster 500
        500 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian buster/stable amd64 Packages
        500 https://mirrors.aliyun.com/docker-ce/linux/debian buster/stable amd64 Packages
     5:20.10.6~3-0~debian-buster 500
        500 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian buster/stable amd64 Packages
        500 https://mirrors.aliyun.com/docker-ce/linux/debian buster/stable amd64 Packages
     5:20.10.5~3-0~debian-buster 500
        500 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian buster/stable amd64 Packages
        500 https://mirrors.aliyun.com/docker-ce/linux/debian buster/stable amd64 Packages

四、系统参数优化

1、nano /etc/security/limits.conf #编辑添加以下优化信息

#root

root soft core unlimited

root hard core unlimited

root soft nproc 1000000

root hard nproc 1000000

root soft nofile 1000000

root hard nofile 1000000

root soft memlock 32000

root hard memlock 32000

root soft msgqueue 8192000

root hard msgqueue 8192000

#*

* soft core unlimited

     * hard core unlimited

* soft nproc 1000000

* hard nproc 1000000

* soft nofile 1000000

* hard nofile 1000000

* soft memlock 32000

* hard memlock 32000

* soft msgqueue 8192000

* hard msgqueue 8192000

ctrl+o #保存配置

ctrl+x #退出

2、nano /etc/sysctl.conf #编辑添加以下优化参数

# Controls source route verification

net.ipv4.conf.default.rp_filter = 1

net.ipv4.ip_nonlocal_bind = 1

      net.ipv4.ip_forward = 1

# Do not accept source routing

net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel

kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.

# Useful for debugging multi-threaded applications.

kernel.core_uses_pid = 1

# Controls the use of TCP syncookies

net.ipv4.tcp_syncookies = 1

# Disable netfilter on bridges.

# Controls the default maxmimum size of a mesage queue

kernel.msgmnb = 65536

# # Controls the maximum size of a message, in bytes

kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes

kernel.shmmax = 68719476736

# # Controls the maximum number of shared memory segments, in pages

kernel.shmall = 4294967296

# TCP kernel paramater

net.ipv4.tcp_mem = 786432 1048576 1572864

net.ipv4.tcp_rmem = 4096 87380 4194304

net.ipv4.tcp_wmem = 4096 16384 4194304

net.ipv4.tcp_window_scaling = 1

net.ipv4.tcp_sack = 1

# socket buffer

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.core.netdev_max_backlog = 262144

net.core.somaxconn = 20480

net.core.optmem_max = 81920

# TCP conn

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_syn_retries = 3

net.ipv4.tcp_retries1 = 3

net.ipv4.tcp_retries2 = 15

# tcp conn reuse

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_tw_reuse = 0

      net.ipv4.tcp_fin_timeout = 1

net.ipv4.tcp_max_tw_buckets = 20000

net.ipv4.tcp_max_orphans = 3276800

net.ipv4.tcp_synack_retries = 1

net.ipv4.tcp_syncookies = 1

# keepalive conn

net.ipv4.tcp_keepalive_time = 300

net.ipv4.tcp_keepalive_intvl = 30

net.ipv4.tcp_keepalive_probes = 3

net.ipv4.ip_local_port_range = 10001 65000

# swap

vm.overcommit_memory = 0

 vm.swappiness = 10

#net.ipv4.conf.eth1.rp_filter = 0

#net.ipv4.conf.lo.arp_ignore = 1

#net.ipv4.conf.lo.arp_announce = 2

#net.ipv4.conf.all.arp_ignore = 1

#net.ipv4.conf.all.arp_announce = 2

ctrl+o #保存配置

ctrl+x #退出

/sbin/sysctl -p #使配置立即生效

三、配置内网离线源

apt-mirror方式

1、下载apt-mirror

sudo apt install apt-mirror

2、配置

sudo nano  /etc/apt/mirror.list

deb 配置的是拖库的目标地址 ,配置中选择的是阿里云镜像站。默认的文件下载存放地址是 /var/spool/apt-mirror/mirror/

deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ buster/updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian-security/ buster/updates main non-free contrib

3、拉取

sudo apt-mirror

4、安装apache2

sudo apt install apache2
ln -s /var/spool/apt-mirror/mirror/mirrors.aliyun.com/debian /var/www/html/debian
ln -s /var/spool/apt-mirror/mirror/mirrors.aliyun.com/debian-security /var/www/html/debian-security

5、在测试机上更换本地源

sudo nano /etc/apt/sources.list

deb http://本地IP/debian/ buster main non-free contrib
deb http://本地IP/debian/ buster-updates main non-free contrib
deb http://本地IP/debian/ buster-backports main non-free contrib
deb-src http://本地IP/debian/ buster main non-free contrib
deb-src http://本地IP/debian/ buster-updates main non-free contrib
deb-src http://本地IP/debian/ buster-backports main non-free contrib
deb http://本地IP/debian-security/ buster/updates main non-free contrib
deb-src http://本地IP/debian-security/ buster/updates main non-free contrib

6、 update

sudo apt update

7、更新时,提示缺少i18n文件夹下的文件

wget -r -np  -erobots=off  -c -nH http://mirrors.aliyun.com/debian/dists/buster-backports/main/i18n/ -P  /var/spool/apt-mirror/mirror/mirrors.aliyun.com/
wget -r -np  -erobots=off  -c -nH http://mirrors.aliyun.com/debian/dists/buster-backports/contrib/i18n/ -P  /var/spool/apt-mirror/mirror/mirrors.aliyun.com/
wget -r -np  -erobots=off  -c -nH http://mirrors.aliyun.com/debian/dists/buster-backports/non-free/i18n/ -P  /var/spool/apt-mirror/mirror/mirrors.aliyun.com/
wget -r -np  -erobots=off  -c -nH http://mirrors.aliyun.com/debian-security/dists/buster/updates/main/i18n/ -P  /var/spool/apt-mirror/mirror/mirrors.aliyun.com/
wget -r -np  -erobots=off  -c -nH http://mirrors.aliyun.com/debian-security/dists/buster/updates/non-free/i18n/ -P  /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

少安在线锤人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值