马哥N49第二周作业

1. 按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。

目前比较主流的三大发行版本是Debian、Redhat、SUSE

  • 联系:各个版本都是遵循GPL协议基于Linux的内核开发的操作系统,所有人都能在各个版本公开的源码上再次开发和发布

  • 区别:各个版本之间发布的版本各不相同,使用的内核版本号也可能不一样,开发出来的各个开源软件不一样,又分为社区版和商业版(Redhat)。

2. 安装CentOS7.6操作系统。

  • 新建虚拟机启动并选择install CentOS 7选项
image
  • 选择要操作系统的语言和键盘
image
  • 选择最小安装,并点击INSTANLLATION DESTINATION进行手动分区
image
image
image
  • 创建一个以自己命名的用户,等待安装完成并reboot系统
image
image
  • 使用自己创建的用户登录操作系统
image

3. 配置环境变量,实现执行history的时候可以查看到执行命令的时间。

向用户当前家目录的.bash_profile或者/etc/profile文件追加一行export HISTTIMEFORMAT="%F %T ",并source之后即可。

image
image

4. 总结Linux的哲学思想

  • 一切皆文件;普通文件、目录、字符设备、块设备、套接字、链接等在Linux中都是文件对待,虽然它们的类型不同,但却是同一套操作接口,使之所有资源都的访问都统一的表现为文件的访问。

  • 提供很多小型的单一用途的程序;从而确保Linux可以高效运行。

  • 连接程序,共同完成复杂功能,使用连接多个简单的程序的组合实现复杂的任务。

  • 避免令人困惑的用户界面,相比windows,Linux的字符界面更简洁明了,出现问题可以通过简洁的命令排错等。

  • 配置数据存储在文件中;Linux各种应用的配置文件都可见的文本配置文件存放,只需要用文本编辑器修改即可。

5. 总结Linux的常用命令使用格式,并用实例说明。

Linux的常用命令使用格式:命令 【选项】【参数】,选项有长选项"--"和短选项"-"

  • echo [OPTION]... [STRING]...

echo命令的使用格式是echo 选项 加需要输出的字符串,常用的选项有:

-n :不自动换行

[root@localhost ~]# echo -n "aaaaaa"

aaaaaa[root@localhost ~]#

[root@localhost ~]#

-e:启用特别字符处理,将一些特别的字符转换成特殊动作

\a 发出警告声

\b 退格键

\c 最后不加上换行符号

\e escape,相当于\033

\n 换行且光标移至行首

\r 回车,即光标移至行首,但不换行

\t 插入tab

\ 插入\字符

\0nnn 插入nnn(八进制)所代表的ASCII字符

\xHH插入HH(十六进制)所代表的ASCII数字(man 7 ascii)

  • screen [ -options ] [ cmd [ args ] ]

显示所有已经打开的screen会话

[root@localhost ~]# screen -ls 

No Sockets found in /var/run/screen/S-root.

[root@localhost ~]#

创建新的screen会话

[root@localhost ~]# screen -S aaa

[root@localhost ~]#

加入已创建的screen会话

[root@localhost ~]# screen -x aaa

恢复某screen会话

[root@localhost ~]# screen -d aaa  #断开screen会话

[2670.aaa detached.]

[root@localhost ~]# screen -r aaa   #恢复screen会话

[root@localhost ~]# screen -ls

There is a screen on:

        2670.aaa        (Attached)

1 Socket in /var/run/screen/S-root.
  • date [OPTION]... [+FORMAT]

  • date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
    date命令打印或者设置系统日期和时间
    -d,--date=STRING ,通过字符串描述显示非当前的时间

[root@localhost ~]# date -d "-3 day"  #3天之前的时间
Thu Oct  1 01:24:50 EDT 2020
[root@localhost ~]# 
[root@localhost ~]# date -d "-3 years"  #3年前的时间
Wed Oct  4 01:25:02 EDT 2017
[root@localhost ~]# 
[root@localhost ~]# date -d "+3 years"  #3年后的时间
Wed Oct  4 01:25:09 EDT 2023
[root@localhost ~]# 

-f,--file=DATEFILE,类似-d通过文件每一行描述显示非当前时间

[root@localhost ~]# cat testday.txt
-3 day
+3 year
[root@localhost ~]# 
[root@localhost ~]# date -f testday.txt  #依次根据文本每行的内容显示时间
Thu Oct  1 01:28:04 EDT 2020
Wed Oct  4 01:28:04 EDT 2023
[root@localhost ~]#

-r,--reference=FILE,显示文件的最后一次被修改时间

[root@localhost ~]# date -r testday.txt
Sun Oct  4 01:27:42 EDT 2020
[root@localhost ~]#

-s,--set=STRING,设置时间

[root@localhost ~]# date -s "2021-10-1 01:36:42"
Fri Oct  1 01:36:42 EDT 2021
[root@localhost ~]# 
  • ifconfig [interface]
  • ifconfig interface [aftype] options | address ...
    ifconfig [interface]查看某个网卡的详细信息
[root@www ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:77:09:A3  
          inet addr:10.0.0.204  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe77:9a3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:23839 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10536 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:33827748 (32.2 MiB)  TX bytes:660782 (645.2 KiB)

[root@www ~]# 

ifconfig [interface] up/down启用和关闭某个网卡

[root@www ~]# ifconfig lo
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:40 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2872 (2.8 KiB)  TX bytes:2872 (2.8 KiB)

[root@www ~]# 
[root@www ~]# ifconfig lo down #关闭lo网卡
[root@www ~]# ifconfig lo
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          LOOPBACK  MTU:65536  Metric:1
          RX packets:40 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2872 (2.8 KiB)  TX bytes:2872 (2.8 KiB)

[root@www ~]# ifconfig lo up #启用lo网卡
[root@www ~]# ifconfig lo
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:40 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2872 (2.8 KiB)  TX bytes:2872 (2.8 KiB)

[root@www ~]# 

ifconfig [interface] [ip_addr] netmask [netmask]设置某个网卡的ip地址和掩码

[root@www ~]# ifconfig eth0 10.0.0.204 netmask 255.255.255.0
[root@www ~]# 
  • export
    export 变量名="值"
[root@localhost ~]# export HISTTIMEFORMAT="%F %T "   #设置history的输出格式显示时间
[root@localhost ~]# 
[root@localhost ~]# echo $HISTTIMEFORMAT
%F %T
[root@localhost ~]# 
[root@localhost ~]# history 
    1  2020-10-04 01:47:36 man ls
    2  2020-10-04 01:47:36 ls -Ad .*
    3  2020-10-04 01:47:36 ls -A -d .*

架构作业:
1、Ubuntu server18.04的安装,优化系统
1.1 安装ubuntu server18.04

  • 传递内核参数需改网卡名为eth0


    image.png
  • 选择语言


  • 选择china时区


    image.png
  • 跳过键盘检测,并设置为美式键盘


    image.png
  • 设置主机名


    image.png
  • 创建一个新用户


    image.png
  • 磁盘分区,选择一个磁盘


    image.png

    image.png

    image.png

    image.png

    image.png

    image.png

    image.png

    image.png
  • 取消自动更新


    image.png
  • 安装openssh服务


    image.png
  • 写入grub


    image.png
  • 安装完成,重启系统


    image.png

    image.png

    1.2 优化系统

  • 内核参数优化

root@ubuntu-node:~# cat /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.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
# 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_tw_recycle = 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
root@ubuntu-node:~#  sysctl -p
  • 系统资源限制优化
root@ubuntu-node:~# cat /etc/security/limits.conf 
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
root@ubuntu-node:~#

2、ubuntu双网卡绑定bond,双网卡桥接

  • 4张网卡分别做bond后并桥接
root@ubuntu-node:~# cat /etc/netplan/01-netcfg.yaml 
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      dhcp6: no
    eth1:
      dhcp4: no
      dhcp6: no
    eth2:
      dhcp4: no
      dhcp6: no
    eth3:
      dhcp4: no
      dhcp6: no
  bonds:
    bond0:
      interfaces:
        - eth0
        - eth1
      parameters:
        mode: active-backup
        mii-monitor-interval: 100
    bond1:
      interfaces:
        - eth2
        - eth3
      parameters:
        mode: active-backup
        mii-monitor-interval: 100
  bridges:
    br0:
      dhcp4: no
      dhcp6: no
      interfaces:
        - bond0
      addresses: [10.0.0.20/24]
      gateway4: 10.0.0.2
      nameservers:
        addresses: [223.6.6.6]
    br1:
      dhcp4: no
      dhcp6: no
      interfaces:
        - bond1
      addresses: [172.168.0.20/24]

root@ubuntu-node:~# netplan apply

你可能感兴趣的:(马哥N49第二周作业)