Linux基础篇学习——程序包安装及管理方式

软件安装

yum安装

可以自动处理依赖关系,并且一次安装所有依赖的软件包

国内源:开源镜像站(第三方)
本地源:iso镜像,/media 基础包(数量少、无更新)
官方源:(最新版本、标准)

配置yum源

配置网络源(基础)

网易163 yum源:http://mirrors.163.com/.help/centos.html

yum源 安装方法
中科大 https://lug.ustc.edu.cn/wiki/mirrors/help
阿里云 http://mirrors.aliyun.com/repo/
清华大学 https://mirrors.tuna.tsinghua.edu.cn/
中国科技大学 http://centos.ustc.edu.cn

配置:下载对应版本的镜像源,放在/etc/yum.repo.d/
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
清理缓存 yum clean all
重新生成缓存 yum makecache

配置epel源

EPEL(Extra Packages for Enterprise Linux)是由 Fedora 社区打造,为 RHEL 及衍生发行版如CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源。

方法一 从基础源里找epel-release
查找 yum list|grep epel-release
安装 yum install epel-release.noarch

方法二 从镜像站获取
下载 wget https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
安装 yum install epel-release-latest-7.noarch.rpm

安装完成之后,会在/etc/yum.repo.d/生成 epel.repoepel-testing.repo

[root@localhost yum.repos.d]# ls epel*
epel.repo  epel-testing.repo

清理缓存 yum clean all
重新生成缓存 yum makecache


配置本地源

方法一:挂载光驱
[root@zycentos7 ~]# mount /dev/sr0 /media	;挂载
mount: /dev/sr0 is write-protected, mounting read-only
[root@zycentos7 ~]# cd /etc/yum.repos.d/	;进入yum配置目录
[root@zycentos7 yum.repos.d]# vim yum.repo

yum.repo的内容如下:
[centos7.6] ;yum源名称,名称一定要在[]中
name=centos7.6 ;yum源说明
baseurl=file:///media ;yum源服务器地址,其中//是标准格式,/media是绝对路径
gpgcheck=0 ;不验证
enabled=1 ;启动

持久挂载(关机/重启自动挂载光驱)

扫描二维码关注公众号,回复: 8564256 查看本文章
[root@localhost ~]# echo "mount /dev/sr0 /media" >> /etc/rc.local
方法二:挂载镜像
方法三:利用tftp或http

官网源配置

nginx:http://nginx.org/en/linux_packages.html#RHEL-CentOS
mysql:https://dev.mysql.com/downloads/file/?id=489467

yum常用命令


rpm安装(不能一次性解决依赖)

rpm的安装和升级都需要rpm包的全名,而删除和查询不需要全名

RPM选项 含义
-i install,安装
-v 显示安装详细信息
-h 显示进度条,每个#表示2%的进度
-U upgrade升级或安装
-F 升级
-e 卸载
-q 查询已安装的rpm包(-qa,-ql)
-p 查询未安装包信息
-f 查询系统文件属于哪个软件包
-R 查询依赖性requires

1.rpm包安装

rpm -ivh 安装包全名

-i install,安装
-v verbose,显示安装详细信息
-h hash marks,显示进度条,每个#表示2%的进度
–nodeps 不检测依赖
–replacepkgs 重新安装

2.rpm包升级

rpm -Uvh 包全名

-U upgrade升级或安装
-F 升级
不要对内核升级,Linux支持多内核版本并存

查询所有可以升级的rpm包 yum list |grep updates

3.rpm包卸载

rpm -e 包全名

-e 卸载
–test 测试卸载

4.查询rpm包是否安装

rpm -q 包名

-qa 查询所有已安装的rpm包

5.查询详细信息

rpm -qi 包名

-i 查询软件信息
-p 查询未安装包信息

6.查询软件包安装位置

rpm -ql 包名

-l 列表

7.查询系统文件属于哪个RPM包

rpm -qf 系统文件名

-f 查询系统文件属于哪个软件包

8.查找软件包的依赖性

rpm -qR 包名

-R 查询依赖性requires

8.查看一个rpm软件的修改记录

rpm -q --changelog postfix

源码安装

安装依赖

[root@localhost yum.repos.d]# yum install gcc gcc-c++ gcc-g77 make

分析环境(略)

下载源码包

nginx
apache

[root@localhost ~]# wget http://nginx.org/download/nginx-1.17.5.tar.gz

安装

准备

创建一个安装目录

[root@localhost ~]# mkdir -p /opt/data/nginx/

创建一个运行软件的用户

[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -g nginx nginx

解压

[root@localhost ~]# mv nginx-1.17.5.tar.gz /opt/data/nginx/
[root@localhost nginx]# tar -zxf nginx-1.17.5.tar.gz
[root@localhost nginx]# cd nginx-1.17.5
源码编译安装三步

预编译 ./configure ------>编译 make ------->安装 make install

./configure
a. 指定安装路径,例如 --prefix=/usr/local/apache
b. 启用或禁用某项功能,例如 --enable-ssl, --disable-filter --with-http_ssl_module
c. 和其它软件关联,例如–with-pcre
d. 检查安装环境,例如是否有编译器gcc,是否满足软件的依赖需求
最终生成:Makefile
make clean //清理掉以前编译后产生的 *.o目标文件
make //按Makefile文件编译,可以使用-j 2指定两颗CPU编译,优化编译器参数
make install //按Makefile定义的文件路径安装

预编译
[root@localhost nginx-1.17.5]# ./configure --prefix=/opt/data/nginx
checking for OS
 + Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
checking for gcc -pipe switch ... found
......
checking for PCRE library in /opt/local/ ... not found

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

解除依赖 [root@localhost nginx-1.17.5]# yum install pcre-devel
devel为源码安装所需要的开发包,包括头文件、链接库等

安装过程中可能需要解决多个依赖

检查预编译是否成功,0成功,非0失败

[root@localhost nginx-1.17.5]# echo $?
0
编译
[root@localhost nginx-1.17.5]# make
[root@localhost nginx-1.17.5]# echo $?
0
安装
[root@localhost nginx-1.17.5]# make install
[root@localhost nginx-1.17.5]# echo $?
0

进入安装目录启动程序

[root@localhost nginx-1.17.5]# cd /opt/data/nginx/sbin
[root@localhost sbin]# ll
total 3748
-rwxr-xr-x. 1 root root 3835456 Oct 28 20:23 nginx
[root@localhost sbin]# ./nginx

找不到安装目录
在ngnix的解压的文件目录里面查看MakeFile文件里面的安装目录

upgrade:
        /opt/data/nginx/sbin/nginx -t

查看程序进程

[root@localhost sbin]# ps -ef|grep nginx
root      13811      1  0 20:27 ?        00:00:00 nginx: master process ./ngin
nobody    13812  13811  0 20:27 ?        00:00:00 nginx: worker process
root      13814   7121  0 20:28 pts/0    00:00:00 grep --color=auto nginx

关闭防火墙

[root@localhost sbin]# systemctl stop firewalld
[root@localhost sbin]# setenforce 0

修改静态页面

[root@localhost nginx]# cd sbin/
[root@localhost sbin]# cd ..
[root@localhost nginx]# cd html
[root@localhost html]# vim index.html
Welcome to zhao's nginx!

访问页面

http://192.168.182.188/(linux IP)

在这里插入图片描述

apache 源码安装关键步骤
【下载源码包】  wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
【解压】  tar -zxf httpd-2.4.41.tar.gz
【进入解压路径】  cd httpd-2.4.41
【预编译1】./configure --prefix=/opt/data/apache
【解决依赖】  yum install apr-devel -y
【预编译2】  ./configure --prefix=/opt/data/apache
【解决依赖】  yum install apr-util-devel -y
【预编译3】  ./configure --prefix=/opt/data/apache
【检查预编译是否成功】 echo $?
【编译】  make;
【检查编译是否成功】 echo $?echo $? 
【安装】  make install
【检查安装是否成功】  echo $?
【进入程序启动路径】  cd /opt/data/apache/bin
【启动程序】 ./apachectl
【解决未设定ServerName】  vim /opt/data/apache/conf/httpd.conf
						#ServerName www.example.com:80   ;把#去掉
【解决80端口占用问题】  ps -ef|grep nginx
 					kill 13811
【启动程序2】 ./apachectl
【查看进程】  ps -ef|grep apache

沒有設定 ServerName

[root@localhost bin]# pwd
/opt/data/apache/bin
[root@localhost bin]# ./apachectl
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

解决方法

[root@localhost conf]# vim /opt/data/apache/conf/httpd.conf
#ServerName www.example.com:80   ;把#去掉,再重启apache

地址已在使用:ah00072:make_sock:无法绑定到地址[::]:80

(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80

查看80端口被哪个服务使用

[root@zycentos7 bin]# netstat -tunlp|grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      27358/ngin     x: master

杀死占用80端口的进程

[root@localhost bin]# ps -ef|grep nginx
root      13811      1  0 20:27 ?        00:00:00 nginx: master process ./nginx
nobody    13812  13811  0 20:27 ?        00:00:00 nginx: worker process
root      31779   7121  0 21:23 pts/0    00:00:00 grep --color=auto nginx
[root@localhost bin]# kill 13811
[root@localhost bin]# ps -ef|grep nginx
[root@localhost bin]# ps -ef|grep apache
root      31785      1  0 21:25 ?        00:00:00 /opt/data/apache/bin/httpd
daemon    31786  31785  0 21:25 ?        00:00:00 /opt/data/apache/bin/httpd
daemon    31787  31785  0 21:25 ?        00:00:00 /opt/data/apache/bin/httpd
daemon    31788  31785  0 21:25 ?        00:00:00 /opt/data/apache/bin/httpd
root      31873   7121  0 21:25 pts/0    00:00:00 grep --color=auto apache

在这里插入图片描述


Python包管理

python ------ rpm
pip ------ yum

安装setuptools

[root@localhost ~]# yum -y install git
[root@localhost ~]# git clone https://github.com/pypa/setuptools.git
[root@localhost ~]# cd setuptools
[root@localhost setuptools]# python easy_install.py pexpect
[root@localhost setuptools]# python bootstrap.py
[root@localhost setuptools]# python setup.py install

安装pip软件包

[root@localhost ~]# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
[root@localhost ~]# tar -xzvf pip-1.5.4.tar.gz
[root@localhost ~]# cd pip-1.5.4
[root@localhost pip-1.5.4]# python setup.py install

使用pip安装软件包

  1. 安装软件包
[root@localhost ~]# pip install SomePackage
  1. 检查哪些包需要更新
[root@localhost ~]# pip list --outdated
  1. 升级软件包
[root@localhost ~]# pip install --upgrade SomePackage
  1. 卸载软件包
[root@localhost ~]# pip uninstall SomePackage
  1. pip 安装redis 实战案例
[root@localhost ~]# pip install redis

实时解析nginx 访问日志ngxtop

  1. 源码安装
[root@localhost ~]# wget https://github.com/lebinh/ngxtop/archive/master.zip -O ngxtop-master.zip
[root@localhost ~]# unzip ngxtop-master.zip
[root@localhost ~]# cd ngxtop-master
[root@localhost ngxtop-master]# python setup.py install
  1. nginx 基本示例
[root@localhost ~]# [root@localhost ~]# ngxtop -c /opt/data/nginx/conf/nginx.conf //实时状态
[root@localhost ~]# ngxtop -c /opt/data/nginx/conf/nginx.conf top remote_addr //top 10
发布了43 篇原创文章 · 获赞 30 · 访问量 5939

猜你喜欢

转载自blog.csdn.net/qq_42049496/article/details/102789467