linux-关于安装问题

image

linux中安装软件的三种方式

1、rpm安装
rpm安装类似于windows中的安装包,下载下来直接安装,缺点是不能自己解决依赖。
2、yum安装
yum安装基于rpm安装,也就是字啊rpm安装上面增加了自动解决以来的功能。
3、源代码安装
源代码安装是通过编译源代码,得到安装包,有点是可以自定制软件包,缺点是比较麻烦。

rpm安装

1、下载安装包

⚠️ 
mac 上需要安装VMware Tools 打开工具 添加共享文件夹
windows则用yum下载lrzsz即可实现拖拽

2、安装:rpm -ivh [软件包名称]

[root@judyju /mnt/hgfs/共享]# rpm -ivh  zsh-5.0.2-34.el7_8.2.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:zsh-5.0.2-34.el7_8.2             ################################# [100%]

3、卸载
rpm -e zsh
4、更新
rpm -Uvh [软件包名称]
5、软件包名称

rpm -ivh  zsh-5.0.2-34.el7_8.2.x86_64.rpm
	软件包名称:zsh
	版本号:5.0.2
	第多少次编译:34
	使用的平台:el7_8( CentOs7)
	使用的系统位数:x86_64
	扩展名:rpm

6、查看安装包的配置文件
rpm -qc [软件名]

[root@judyju /mnt/hgfs/共享]# rpm -qc zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc

7、查看是否安装某软件
rpm -q [软件名]

[root@judyju /mnt/hgfs/共享]# rpm -q zsh
zsh-5.0.2-34.el7_8.2.x86_64

8、查看当前系统安装了哪些软件
rpm -qa
9、查看软件安装路径以及查看安装了哪些东西
rpm -ql

yum安装

(基于rpm安装,自动解决以来)
1、安装
yum install [软件包名称]

参数:-y 免交互
-nongpgchek 忽略公钥认证

2、卸载
yum remove [软件包名称]

参数:-y 免交互

3、更新
yum update [软件包名称]

参数:-y 免交互

如果跟具体的软件包名称,就会更新指定软件包,如果没有指定,则更新系统所有的需要更新的软件包
4、yum安装的生命周期

(1)执行yum install zsh -y
(2)去 /etc/yum.repos.d/找到.repo结尾的文件
(3)通过.repo文件中的链接,找到相应的软件仓库
(4)在对应的软件仓库下载指定的软件包
(5)缓存至/var/cache/yum中
(6)根据缓存,安装软件包
(7)删除软件报(keepcache是否保存缓存,0代表不保存,1代表保存)

/etc/yum.conf 是yum的配置文件

编译安装

编译安装即使用源代码,编译打包软件

特点:

1、可以自定制软件
2、按需构建软件

步骤

1、下载源代码包
wget+地址
[root@judyju ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz
2、解压
[root@judyju ~]# tar -xf nginx-1.20.2.tar.gz 
3、设置系统参数
[root@judyju ~]# cd nginx-1.20.2/
4、自定制
[root@judyju ~/nginx-1.20.2]# vim ./src/core/nginx.h
5、[root@judyju ~/nginx-1.20.2]# ./configure 
6、编译
[root@judyju ~/nginx-1.20.2]# make
7、安装
[root@judyju ~/nginx-1.20.2]# make install
8、启动
[root@judyju ~/nginx-1.20.2]# /usr/local/nginx/sbin/nginx
9、关闭
[root@judyju ~/nginx-1.20.2]# /usr/local/nginx/sbin/nginx -s stop
[root@judyju ~/nginx-1.20.2]# systemctl stop nginx

yum私有仓库

一、本地版

1、下载必要的软件包
[root@judyju /var/cache/yum]# yum install yum-utils createrepo -y
2、创建软件仓库 
[root@judyju /opt]# mkdir repos
3、下载对应的软件,并创建Packages目录,将下载的软件复制到Packages中
[root@judyju /opt/repos]# mkdir Packages
[root@judyju /opt/repos]# cp /mnt/hgfs/共享/zsh-5.0.2-34.el7_8.2.x86_64.rpm /opt/repos/Packages
4、初始化软件仓库
[root@judyju /opt/repos]# createrepo /opt/repos/
5、添加yum源
[root@judyju /opt/repos]# cd /etc/yum.repos.d/
[root@judyju /etc/yum.repos.d]# mkdir backup
[root@judyju /etc/yum.repos.d]# mv *.repo backup/
[root@judyju /etc/yum.repos.d]# yum-config-manager --add-repo=file:///opt/repos/

[opt_repos_]     源的名字
name=added from: file:///opt/repos/    源的简介
baseurl=file:///opt/repos/   源的下载地址
enabled=1    是否启用 1为启用 2为不启用
6、生成缓存
[root@judyju /etc/yum.repos.d]# yum clean all
[root@judyju /etc/yum.repos.d]# yum makecache

二、远程版

前6步和本地版一样
7、安装远程访问软件
因为前面操作破坏了yum源,所以我们重新将CentOsbase库和epel库下载
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@judyju /etc/yum.repos.d/backup]# yum install nginx --nogpgcheck
8、修改配置文件
vim /etc/nginx/nginx.conf

image
image
image

9、测试更改是否成功
[root@judyju ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
10、启动nginx
[root@judyju ~]# systemctl start nginx 如果需要开机自启动:systemctl enable nginx (这样就不用每次开机都启动nginx了)
11、关闭selinux和firewalld
关闭防火墙:[root@judyju ~]# systemctl disable --now firewalld
关闭selinux:[root@judyju ~]# vim /etc/selinux/config 

image
12、测试机测试
(1)yum utils -y
(2)mkdir backup
(3)将.repo结尾的文件移动到bakeup目录下
(4)添加源:yum-config-manager --add-repo=http://ip地址
(5)刷新缓存:yum clean all yum makecache
(6)下载试试

系统安全优化

一、selinux

一般我们将它关闭
临时关闭:sentenforce 0
永久关闭:编辑配置文件,vim /etc/selinux/config
	功能永久开启:enforcing
	功能临时关闭:permissive
	功能永久关闭:disabled

二、firewalld

开启:服务器可以被外界访问:
	CentOs7:
	systemctl start firewalld.service
关闭:
	CentOs7
	systemctl stop firewalld.service

防止系统乱码优化

en_US.UTF-8
zh_CN.UTF-8

临时优化:
export LANG=zh_CN.UTF-8 设置编码

永久优化:编辑配置文件
vim /etc/locale.conf

补充
关于文件执行

1、sh 文件名
2、给文件添加可执行权限,./2.sh 
3、bash 2.sh
posted @ 2021-12-16 17:04  JudyJU  阅读(95)  评论(0)    收藏  举报