tongsiying

阅读|运动|自律

0%

Linux上天之路(十一)之软件管理

软件管理

软件包格式:

  • RPM:源码封装后的格式,类似于exe文件
  • 源码:软件源代码,可以修改,优化

1. RPM软件包管理

rpm是一个很有用的包管理器,可以用于生成、安装、查询、核实、更新以及卸载单个软件包

适用于redhat redflag centos suse

  • rpm命令:rpm -ivh
1
2
3
4
5
6
7
8
9
10
11
12
i 安装
v 显示安装过程
h hash [Use with -v|--verbose for a nicer display.]
q 查找 查询
-qf 查看某个文件时属于哪个软件包
-qi 查看软件包的信息【出厂信息】
-qa 查找已安装所有匹配XXX关键字的软件包
-e 卸载rpm软件包
-ql 查看软件包包含哪些文件
-U 升级软件包
—nodeps 忽略依赖
软包安装不完整 重新安装 —replacepkgs —force
  • 问题
1
2
3
4
5
1.非官方提供的rpm格式的包是由别人基于源码打包的,安全无法保证

2.rpm格式的包一般都比较旧,除非官方提供

3.rpm包的依赖问题比较致命
  • yum安装

YUM C/S架构

1
2
3
4
5
6
7
YUM源服务器    [共享所有软件包]  通过文件服务器  【http ftp file】  存储大量RPM软件包,通过FTP|HTTP|HTTPS|FILE方式共享软件包

YUM客户端:从yum仓库下载软件包并安装
优点:
自动解决依赖
自动下包
自动安装
  • YUM 客户端配置文件: /etc/yum.repos.d/

配置文件名字两部分组成 *.repo 前半部分可以随便写 后半部分必须是repo

1
2
3
4
5
[baism]       
name=www.ayitula.com
baseurl=ftp://192.168.10.253/pub
enabled=1
gpgcheck=0
  • 配置第三方yum源
1
2
3
4
[root@localhost ~]# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm
[root@localhost ~]# yum repolist ##检查是否已添加至源列表
[root@localhost ~]# yum -y install epel-release
  • 相关命令
1
2
3
4
5
6
7
8
9
10
11
12
yum clean all  清除缓存目录下的软件包及旧的headers
yum update 清除缓存目录下的软件包及旧的headers
yum install 软件包名字 -y 安装
yum remove 软件包名字 -y 删除
yum update 软件包名字 -y 升级
yum search 软件包名字 查找软件包
yum list 软件包名字 列出所有可安裝的软件清单
yum localinstall 软件包名字 -y 安装本地软件包
yum groupinstall 组名
yum groupupdate 组名
yum grouplist 组名
yum groupremove 组名
  • 协议配置

ftp协议安装

1
2
3
4
5
6
7
[zhangyafei@centos ~]$ rpm -qa|grep vsftpd
[zhangyafei@centos ~]$ yum install -y vsftpd
[root@centos /]# systemctl start vsftpd # systemctl restart vsftpd systemctl stop vsftpd

# 创建FTP使用的用户
useradd -s /sbin/nologin -d /var/www/html ftpuser
passwd ftpuser

2. 源码包安装

适用于所有linux发行版本

1
2
3
4
5
6
7
解压
配置【configure】 #指定软件功能及安装路径
编译 【make】 #将源码进行编译生成安装文件
安装 【make install#将安装文件安装到目标路径

启动
注意:多看install readme 官网 有安装教程

3. 压缩与解压缩

压缩文件的好处有如下几点:

1、文件更小,便于网络传输,效率高;

2、避免杂乱,可以减少文件个数,多个文件一起压缩;

3、有些文件不能直接传输,比如安装程序,压缩后就可以传输了

常见的压缩格式:tar tar.gz tar.bz2 zip gz bz2 rar xz

  • tar 压缩或解压
1
2
3
4
5
6
7
8
9
10
11
12
13
tar 压缩或解压时根据其后面所跟的名令选项决定
命令语法
tar 压缩或者解压
gz、bz2、xz格式包tar [OPTION...] [FILE]...
命令选项
c 建立压缩包
v 显示过程
x 解压压缩包
f 必选项 归档文件名
t 查看压缩包内容
j 二次压缩使用bz2格式
z 二次压缩使用gz格式
J 二次压缩使用xz格式
  •  zip格式
1
2
3
4
5
6
7
8
9
10
11
安装压缩与解压命令
yum -y install zip unzip
zip- package and compress (archive) files 压缩文件或文件夹
压缩
-r 选项指定你想递归地(recursively)包括所有包括在 filesdir 目录中的文件
zip -r etc.zip /etc
解压
unzip - list, test and extract compressed files in a ZIP archive 显示、测试、解压ZIP
-v 显示压缩目录内容,但是不解压 unzip -v etc.zip
-t 检查压缩文件是否正确、完整,但是不解压 unzip -t etc.zip
-l 列出压缩文件内容,但是不解压 unzip -l etc.zip
  •   压缩文件
1
2
3
4
5
相关命令
[root@www ~]# rpm -qf which bzip2bzip2-1.0.6-13.el7.x86_64
[root@www ~]# rpm -qf which bunzip2bzip2-1.0.6-13.el7.x86_64
[root@www ~]# rpm -qf `which gunzip`gzip-1.5-10.el7.x86_64
[root@www ~]# rpm -qf `which gzip`gzip-1.5-10.el7.x86_64
  •   源码包的解压与压缩总结
压缩 解压
tar -cvzf etc.tar.gz /etc tar xvzf etc.tar.gz
tar -cjvf etc.tar.bz2 /etc tar -jvxf etc.tar.bz2
tar -cvJf etc.tar.xz /etc tar -Jvxf etc.tar.xz
tar -cvf etc.tar /etc tar xvf etc.tar
zip -r tmp.zip /tmp unzip tmp.zip
bzip2 anaconda-ks.cfg
#压缩文件基于块排序压缩
bunzip2 install.log.bz2
bzcat install.log.bz2 #查看压缩文件内容
gzip anaconda-ks.cfg gunzip install.log.gz
zcat install.log.gz 查看压缩文件内容
zip install.log.zip install.log unzip install.log.zip
  • nginx的安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install gcc-c++
yum install -y openssl openssl-devel
wget -c https://nginx.org/download/nginx-1.14.0.tar.gz
tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
./configure --prefix=/usr/local/nginx \
make
make install
whereis nginx
进入sbin目录,可以看到有一个可执行文件nginx,直接./执行就OK了。
运行起来之后访问服务器ip,可以看到nginx的欢迎页面
[root@centos /]# /usr/sbin/nginx
浏览器输入:http://182.254.179.186/
nginx服务的停止:
nginx -s stop 或者
[root@centos shell_learn]# ps -ef|grep nginx
root 1939 1 0 21:53 ? 00:00:00 nginx: master process nginx
nginx 1940 1939 0 21:53 ? 00:00:00 nginx: worker process
root 1945 12666 0 21:53 pts/0 00:00:00 grep --color=auto nginx
[root@centos shell_learn]# kill 1939
[root@centos shell_learn]# ps -ef|grep nginx
root 1979 12666 0 21:53 pts/0 00:00:00 grep --color=auto nginx
1
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-master

相关文件:默认

1
2
3
4
5
6
配置文件:/etc/nginx
可执行文件:/usr/sbin/nginx
html文件:/usr/share/nginx/html
日志文件
/var/log/nginx/error.log
/var/log/nginx/access.log

  

 

赞赏一下吧~