day19 作业

day19-作业


  1. 分别提供windows、linux中可安装的软件包正确可下载链接,可以是任意软件

  2. 在linux部署golang开发环境,可以运行如下代码

    • 要求用yum部署golang环境

      package main
      
      import "fmt"
      
      func main() {
          fmt.Println("于超老师带你学Linux")
      }
      
    • 操作演示:

      # 1. 安装golong环境
      [root@server ~]#yum install golang
      
      # 2. 编写golong代码
      [root@server ~]#cat ggg.go 
      package main
      import "fmt"
      func main() {
          fmt.Println("于超⽼师带你学Linux")
      }
      
      # 3. 运行golong代码
      [root@server ~]#go run ggg.go 
      于超⽼师带你学Linux
      
  3. 对上述golang代码进行编译,生成二进制可执行的命令,并且添加软连接,可以快捷执行

    # 1. 编译golang代码
    [root@server ~]#go build ggg.go 
    [root@server ~]#ll
    -rwxr-xr-x  1 root root   1936997 Mar 25 20:24 ggg
    -rw-r--r--  1 root root        88 Mar 25 17:51 ggg.go
    
    # 2. 查看当前变量
    [root@server ~]#echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/nginx/sbin
    
    # 3.添加软链接到当前变量目录
    [root@server ~]#ln -s ~/ggg /usr/local/bin
    [root@server ~]#ll /usr/local/bin/ggg 
    lrwxrwxrwx 1 root root 9 Mar 25 20:25 /usr/local/bin/ggg -> /root/ggg
    
    # 4. 运行ggg程序
    [root@server ~]#ggg
    于超⽼师带你学Linux
    
  4. 在linux中部署python3开发环境,可以运行如下代码

    • 要求:

      用编译安装方式,部署python3.9.11开发环境并且可以运行如下代码

      import time
      sentence = "Dear, I love you forever!"
      for char in sentence.split():
         allChar = []
         for y in range(12, -12, -1):
             lst = []
             lst_con = ''
             for x in range(-30, 30):
                  formula = ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3
                  if formula <= 0:
                      lst_con += char[(x) % len(char)]
                  else:
                      lst_con += ' '
             lst.append(lst_con)
             allChar += lst
         print('\n'.join(allChar))
         time.sleep(1)
      
    • 操作演示:

      (1)环境准备

      [root@server ~]#mkdir -p /source/				# 源码存放目录
      
      [root@server ~]#yum install gcc openssl-devel	 # 安装编译器
      

      (2)编译安装python

      # 1. 下载python3.9.11
      [root@server source]#wget https://www.python.org/ftp/python/3.9.11/Python-3.9.11.tgz
      
      # 2. 解压源码
      [root@server source]#tar -xvf Python-3.9.11.tgz 
      
      # 3. 进入解压源码目录
      [root@server source]#cd Python-3.9.11/
      
      # 4. 配置编译参数(指定安装路径及添加ssl功能)
      [root@server Python-3.9.11]#./configure --prefix=/usr/local/python39 --with-ssl
      
      # 5. 开始编译源码
      [root@server Python-3.9.11]#make
      
      # 6. 开始安装
      [root@server Python-3.9.11]#make install
      

      (3)配置环境变量

      # 1. 查看python3程序路径
      [root@server ~]#ll /usr/local/python39/bin/
      -rwxr-xr-x 1 root root       93 Mar 25 20:43 pydoc3.9
      
      # 2. 使用软链接方式添加到环境变量中的目录
      [root@server ~]#ln -s /usr/local/python39/bin/python3 /usr/local/bin/python3
      
      [root@server ~]#ll /usr/local/bin/python3
      lrwxrwxrwx 1 root root 31 Mar 25 20:47 /usr/local/bin/python3 -> /usr/local/python39/bin/python3
      
      # 3. 命令行测试
      [root@server ~]#python3 --version
      Python 3.9.11
      

      (4)编写python程序并运行

      # 1. 编写源码
      [root@server ~]#vim pp.py
      import time
      sentence = "Dear, I love you forever!"
      for char in sentence.split():
         allChar = []
         for y in range(12, -12, -1):
             lst = []
             lst_con = ''
             for x in range(-30, 30):
                  formula = ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3
                  if formula <= 0:
                      lst_con += char[(x) % len(char)]
                  else:
                      lst_con += ' '
             lst.append(lst_con)
             allChar += lst
         print('\n'.join(allChar))
         time.sleep(1)
         
      # 2. 运行py程序
      [root@server ~]#python3 pp.py 
                      ear,Dear,           ear,Dear,               
                  ar,Dear,Dear,Dear   ar,Dear,Dear,Dear           
                Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,D         
               ,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,De        
              r,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dea       
              r,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dea       
              r,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dea       
              r,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dea       
              r,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dea       
              r,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dea       
               ,Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,De        
                Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,D         
                Dear,Dear,Dear,Dear,Dear,Dear,Dear,Dear,D         
                  ar,Dear,Dear,Dear,Dear,Dear,Dear,Dear           
                   r,Dear,Dear,Dear,Dear,Dear,Dear,Dea            
                    ,Dear,Dear,Dear,Dear,Dear,Dear,De             
                      ear,Dear,Dear,Dear,Dear,Dear,               
                        r,Dear,Dear,Dear,Dear,Dea                 
                          Dear,Dear,Dear,Dear,D                   
                             r,Dear,Dear,Dea                      
                                ear,Dear,                         
                                   ,De                            
                                    D  
      
  5. 请写出常见的编程语言有哪些,以如下分类写

    • 编译型语言

      C C++ go

    • 解释型语言

      python shell

  6. 你去了b站上班,b站后端较多使用golang开发,请问你需要在机器上安装golang环境吗?为什么

    • golang环境可以按需安装,非必须;如果经常测试以及调试软件运行环境可以安装
  7. 你去了知乎上班,知乎较多使用python开发,请问你需要在机器上安装python环境吗?为什么?

    需要安装python环境;因为python程序是解释型语言,依赖python环境才能运行

  8. 你去看阿里上班,阿里较多使用java开发,请问你需要在机器上安装java环境吗?为什么?

    必须安装Java环境;Java程序的运行必须要有Java环境

  9. 运维会需要学习哪些编程语言?为什么?

    python & shell 脚本语言对于运维很重要,编写脚本语言可以实现自动化运维,大大减轻工作压力

  10. 请解释什么是软件包?举个例子

    一个软件包中可能包含许多程序和支持这些程序的数据文件。除了要安装的文件,其中还包括关于包本身的元数据,例如包及其内容的文本描述。

    [root@server ~]#rpm -qpl tree-1.6.0-10.el7.x86_64.rpm 
    /usr/bin/tree
    /usr/share/doc/tree-1.6.0
    /usr/share/doc/tree-1.6.0/LICENSE
    /usr/share/doc/tree-1.6.0/README
    /usr/share/man/man1/tree.1.gz
    
  11. 请解释什么是源码包?举个例子

    源码包是程序员使用编程语言所书写的文本代码,一般由英文单词组成。
    计算机可以识别的是二进制语言,源码文件要想在linux上运行,必须经过编译后运行

    # 1. 源码包通过cat命令可以查看源代码
    [root@server ~]#cat ggg.go 
    package main
    import "fmt"
    func main() {
        fmt.Println("于超⽼师带你学Linux")
    }
    
    # 2. 可以自定义安装配置(软件包无法配置,只能按照软件包安装脚本预设安装)
    [root@server nginx-1.20.1]#./configure --prefix=/usr/local/python39 --with-ssl
    
    # 通过源码编译安装,自定义配置更多
    
  12. 请解释什么是二进制包?举个例子

    二进制包就是源码包经过成功编译之后产生的包,无法查看其内部信息

    [root@server sbin]#cat nginx
    ��wJ�walk_treengx_http_auth_ba,,�ȣJȣerngx_temp_numbersk_pop_free@@libcrypto.so.10ngx_conf_deprecatedngx_http_read_client_request_bodysetgid@@GLIBC_2.2���k��k@@GLIBC_2.2.5ngx_ssl_ge
    
  13. 程序编译是指什么意思

    将编程语言所书写的文本代码,一般由英文单词组成编译成计算机可以识别的是二进制语言

  14. 如何获取rpm包?提供3个下载方式

    • 软件官方下载
    • 系统安装光盘
    • 互联网搜索 www.rpmfind.net
  15. 二进制包和源代码包的区别是?举个例子

    二进制包就是源码包经过成功编译之后产生的包,因为内部为机器码,所以无法查看其内部信息

    # 1. 源码包可以查看
    [root@server ~]#cat ggg.go 
    package main
    import "fmt"
    func main() {
        fmt.Println("于超⽼师带你学Linux")
    }
    
    # 2. 源码编译后的二进制包无法查看
    [root@server ~]#cat ggg
    �V�}@�}CP^���o<�@<�k���o��@��z�@��Bx�@x����@�� �@ ������A����bI�bnpthread_e��bI�bLIBC_2.� 
    
  16. centos、redhat、suse提供的默认包管理工具是?以及对应的二进制包格式是?

    请写出该工具的5种使用案例

    centos、redhat、suse都是rpm包管理工具

    # 1. 安装rpm包
    [root@server ~]#rpm -ivh tree-1.6.0-10.el7.x86_64.rpm 
    
    # 2. 卸载rpm包
    [root@server ~]#rpm -evh tree
    
    # 3. 升级rpm包
    [root@server ~]#rpm -Uvh tree-1.6.0-10.el7.x86_64.rpm 
    
    # 4. 查询文件属于哪个软件包
    [root@server ~]#rpm -qf /etc/passwd
    setup-2.8.71-9.el7.noarch
    
    # 5. 查询软件包安装后文件位置
    [root@server ~]#rpm -ql tree
    /usr/bin/tree
    /usr/share/doc/tree-1.6.0
    
  17. 请使用rpm安装nginx-1.10.0-1版本

    以及提供安装后的该nginx软件信息,包括

    • 配置文件路径
    • 日志路径
    • 二进制命令路径
    # 1. 下载rpm包
    [root@server ~]#wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.0-1.el7.ngx.x86_64.rpm
    
    # 2. 安装软件包
    [root@server ~]#rpm -ivh nginx-1.10.0-1.el7.ngx.x86_64.rpm 
    
    # 3. 配置文件路径
    /etc/logrotate.d/nginx
    /etc/nginx/conf.d/default.conf
    /etc/nginx/fastcgi_params
    /etc/nginx/koi-utf
    /etc/nginx/koi-win
    /etc/nginx/mime.types
    /etc/nginx/nginx.conf
    /etc/nginx/scgi_params
    /etc/nginx/uwsgi_params
    /etc/nginx/win-utf
    /etc/sysconfig/nginx
    /etc/sysconfig/nginx-debug
    
    # 4. 日志文件路径
    [root@server ~]#rpm -ql nginx | grep var
    /var/cache/nginx
    /var/log/nginx
    
    # 5. 二进制文件路径
    方法1:
    [root@server ~]#rpm -ql nginx | grep -e "/bin" -e '/sbin'
    /usr/sbin/nginx
    
    方法2:
    [root@server ~]#find / -type f -name 'nginx' -perm 755
    /usr/sbin/nginx
    
  18. 请使用centos7光盘镜像,获取vim软件包,并且基于rpm命令安装,注意处理他们的依赖关系

    # 1. 挂载光盘镜像
    [root@server ~]#mount /dev/sr0 /mnt/
    
    # 2. 获取vim软件包
    [root@server ~]#cp /mnt/Packages/vim* /opt/
    [root@server ~]#ll /opt
    total 8764
    -rw-r--r-- 1 root root 6197792 Mar 26 13:36 vim-common-7.4.160-5.el7.x86_64.rpm
    -rw-r--r-- 1 root root 1087648 Mar 26 13:36 vim-enhanced-7.4.160-5.el7.x86_64.rpm
    -rw-r--r-- 1 root root   10452 Mar 26 13:36 vim-filesystem-7.4.160-5.el7.x86_64.rpm
    -rw-r--r-- 1 root root  447352 Mar 26 13:36 vim-minimal-7.4.160-5.el7.x86_64.rpm
    -rw-r--r-- 1 root root 1220408 Mar 26 13:36 vim-X11-7.4.160-5.el7.x86_64.rpm
    
    # 3. 解决依赖
    [root@server opt]#rpm -ivh vim-enhanced-7.4.160-5.el7.x86_64.rpm 
    error: Failed dependencies:
            vim-common = 2:7.4.160-5.el7 is needed by vim-enhanced-2:7.4.160-5.el7.x86_64
    [root@server opt]#rpm -ivh vim-common-7.4.160-5.el7.x86_64.rpm 
    error: Failed dependencies:
            vim-filesystem is needed by vim-common-2:7.4.160-5.el7.x86_64
    [root@server opt]#rpm -ivh vim-filesystem-7.4.160-5.el7.x86_64.rpm 
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:vim-filesystem-2:7.4.160-5.el7   ################################# [100%]
    [root@server opt]#rpm -ivh vim-common-7.4.160-5.el7.x86_64.rpm 
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:vim-common-2:7.4.160-5.el7       ################################# [100%]
       
    # 4. 安装vim   
    [root@server opt]#rpm -ivh vim-enhanced-7.4.160-5.el7.x86_64.rpm 
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:vim-enhanced-2:7.4.160-5.el7     ################################# [100%]
       
    # 5. 安装成功,查看vim版本
    [root@server opt]#vim -version
    VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct 30 2018 19:56:57)
    
  19. 如何查看linux的磁盘挂载情况?

    # 方法1:
    [root@server opt]#lsblk
    NAME      MAJ:MIN RM  SIZE RO TYPE   MOUNTPOINT
    sda         8:0    0   20G  0 disk   
    ├─sda1      8:1    0    1G  0 part   /boot
    └─sda2      8:2    0   19G  0 part   /
    sdb         8:16   0   10G  0 disk   
    └─md0       9:0    0   20G  0 raid10 
      └─md0p1 259:0    0   20G  0 md     
    sdc         8:32   0   10G  0 disk   
    └─md0       9:0    0   20G  0 raid10 
      └─md0p1 259:0    0   20G  0 md     
    sdd         8:48   0   10G  0 disk   
    └─md0       9:0    0   20G  0 raid10 
      └─md0p1 259:0    0   20G  0 md     
    sde         8:64   0   10G  0 disk   
    └─md0       9:0    0   20G  0 raid10 
      └─md0p1 259:0    0   20G  0 md     
    sr0        11:0    1  4.3G  0 rom    /mnt
    
    # 方法2:
    [root@server opt]#df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2        19G  5.1G   14G  27% /
    devtmpfs        477M     0  477M   0% /dev
    tmpfs           488M     0  488M   0% /dev/shm
    tmpfs           488M   14M  474M   3% /run
    tmpfs           488M     0  488M   0% /sys/fs/cgroup
    /dev/sda1      1014M  124M  891M  13% /boot
    tmpfs            98M     0   98M   0% /run/user/0
    /dev/sr0        4.3G  4.3G     0 100% /mnt
    
  20. 写出rpm管理软件的所有命令,以及对应作用

    -q 查询软件包
    -i 显示软件包详细信息,
    -l 显示软件包中的所有文件列表
    -v 显示详细信息
    -h 用 # 显示安装进度
    -a 与q参数搭配使用,用于查询所有的软件包
    -e 卸载软件包
    -f 查询文件或命令属于哪个软件包
    -U 升级软件包

  21. rpm命令有什么优缺点

    • 优点:方便简单 避免错误安装
    • 缺点:依赖关系严重,不管是安装还是卸载,都需要先处理依赖软件
  22. 通过源代码编译安装方式,安装Tengine-2.3.0版本,要求安装到/opt/tngx230/,并且开启nginx的ssl功能,最终展示tengine可访问的画面

    • 要求:

      查询tengine的进程

      查询tengine的端口

      查询tengine的配置文件

      查询tengine的二进制命令

      添加tengine到PATH变量

    • 操作演示:

      (1)编译安装Tengine

      # 0. 编译环境准备
      [root@server ~]#yum install -y gcc gcc-c++ autoconf automake make
      # 编译工具
      [root@server ~]#yum install -y openssl openssl-devel pcre pcre-devel httpd-tools
      # tengine ssl模块依赖库
      
      # 1. 获取源码
      [root@server tools]#wget http://tengine.taobao.org/download/tengine-2.3.0.tar.gz
      [root@server tools]#ll
      -rw-r--r-- 1 root root 2389514 Mar 14 20:11 tengine-2.3.0.tar.gz
      
      # 2. 解压源码
      [root@server tools]#tar -xf tengine-2.3.0.tar.gz 
      
      # 3. 配置编译参数
      [root@server tengine-2.3.0]#./configure --prefix=/opt/tngx230 --with-http_ssl_module
      
      
      # 4. 编译安装
      [root@server tools]#make && make install
      

      (2)查询Tengine信息

      1. 查询tengine的进程
      [root@server ~]#ps -ef | grep nginx
      root      71654      1  0 14:14 ?        00:00:00 nginx: master process tengine
      nobody    71655  71654  0 14:14 ?        00:00:00 nginx: worker process
      
      2. 查询tengine的端口
      [root@server ~]#netstat -lntup | grep nginx
      tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      71654/nginx: master 
      
      3. 查询tengine的配置文件
      [root@server conf]#ll /opt/tngx230/conf/nginx.conf
      -rw-r--r-- 1 root root 3060 Mar 26 14:11 /opt/tngx230/conf/nginx.conf
      
      4. 查询tengine的二进制命令
      [root@server ~]#ll /opt/tngx230/sbin/nginx 
      -rwxr-xr-x 1 root root 6235384 Mar 26 14:11 /opt/tngx230/sbin/nginx
      
      5. 添加tengine到PATH变量
      [root@server ~]#ln -s /opt/tngx230/sbin/nginx /usr/local/bin/tengine
      
      6. 查看版本测试
      [root@server ~]#tengine -v
      Tengine version: Tengine/2.3.0 (nginx/1.15.9)
      
  23. 编译安装的软件如何更新?如何删除?

    将需要升级的软件,配置文件及日志文件做好备份,然后删除二进制命令文件,再重新编译安装

    将软件目录(编译安装配置的目录)全部删除,即可完成卸载操作

  24. 要求使用二进制免安装的方式,部署java1.8开发环境,可以正确执行如下代码。

    要求添加java到PATH变量

    [root@167 opt]# cat HelloWorld.java 
    public class HelloWorld {
        public static void main(String []args) {
           System.out.println("超哥带你学linux");
        }
    }
    

    (1)配置Java环境

    # 1. 下载二进制压缩文件
    [root@server tools]#wget https://download.oracle.com/java/18/latest/jdk-18_linux-x64_bin.tar.gz
    
    # 2. 解压Java二进制文件
    [root@server tools]#tar -xvf jdk-18_linux-x64_bin.tar.gz 
    
    # 3. 编写Java代码
    [root@server ~]#cat HelloWorld.java 
    class HelloWorld {
        public static void main(String args[]){
            System.out.println("超哥带你学Linux\n");
        }
    }
    
    # 4. 添加java到PATH变量
    [root@server ~]#echo 'PATH=$PATH:/root/tools/jdk-18/bin' > /etc/profile
    
    # 5. 编译Java源码
    [root@server ~]#javac HelloWorld.java 
    
    # 6. 执行Java程序
    [root@server ~]#java HelloWorld 
    超哥带你学Linux
    
    
  25. 按照如下要求配置好yum工具

    1.阿里云yum源

    阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (aliyun.com)

    2.备份好默认的yum仓库文件到/etc/yum.repos.d/bak_repo中

    [root@server ~]#cd /etc/yum.repos.d/
    [root@server yum.repos.d]#mkdir bak_repo
    [root@server yum.repos.d]#\mv *.repo bak_repo/
    

    3.配置并生成新的阿里云yum源缓存

    # 1. 配置Base源
    [root@server yum.repos.d]#wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
    
    # 2. 配置Epel源
    [root@server yum.repos.d]#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    
    # 3. 清空源缓存 && 生成阿里云缓存
    [root@server ~]#yum clean all
    [root@server ~]#yum makecache
    

    4.基于阿里云yum源,安装nginx

    [root@server ~]#yum install -y nginx
    

    5.启动nginx

    [root@server ~]#systemctl start nginx
    
  26. 请写出你的linux机器,安装的如下软件,可执行命令的绝对路径

    java

    [root@server ~]#which java
    /root/tools/jdk-18/bin/java
    

    golang

    [root@server ~]#which go
    /usr/bin/go
    

    python3.9.11

    [root@server ~]#which python3 
    /usr/local/bin/python3
    [root@server ~]#python3 -V
    Python 3.9.11
    [root@server ~]#ll /usr/local/bin/python3 
    lrwxrwxrwx 1 root root 31 Mar 25 20:47 /usr/local/bin/python3 -> /usr/local/python39/bin/python3
    

    基于rpm安装的nginx

    [root@server ~]#which nginx
    /usr/sbin/nginx
    

    基于源码编译的Tengine-2.3.0

    [root@server ~]#which tengine 
    /usr/local/bin/tengine
    [root@server ~]#ll /usr/local/bin/tengine 
    lrwxrwxrwx 1 root root 23 Mar 26 14:14 /usr/local/bin/tengine -> /opt/tngx230/sbin/nginx
    

    基于yum安装的nginx

    [root@server ~]#which nginx
    /usr/sbin/nginx
    
  27. 总结如下软件包管理的区别

    • 源码编译:

      缺点:编译安装过程复杂,需要提前手动解决各种依赖环境

      优点:可以自定义各种配置及模块功能以及软件目录文件便于管理

    • rpm安装

      优点:灵活简单,够底层

      缺点:无法解决依赖问题

    • yum安装

      优点:安装软件简单方便,不必考虑依赖问题

      缺点:过分依赖远程仓库以及网络环境,并且自定义配置差(只能使用仓库中的指定版本,无法自定义选择)

  28. 总结你对linux软件安装的思考(面试官这么问你,你怎么答?)

    软件安装根据实际需求出发,如果没有特殊需求,使用yum安装,如果需要自定义软件版本以及拓展功能等等使用编译安装方式。

posted @ 2025-03-06 22:15  国家一级冲浪yzk  阅读(8)  评论(0)    收藏  举报