軟件安裝:Linux如何安裝軟件,程序。
源碼安裝 類似于.exe 源碼包就是一堆源代碼程序組成的。
linux tar.gz 這個就是源碼包
源碼包--------二進制包,源碼包里面的代碼經過編譯之后形成的包。
優點:1、開源,可以二次修改,可以做二次開發,可以自由選擇需要的功能。
? 2、編譯安裝,與系統的適配性更高,更加穩定,卸載比較方便(刪除即可)。
缺點:1、安裝步驟多,容易出錯
? 2、編譯的時間長
? 3、一旦報錯,新手很難解決
安裝步驟: 1、源碼包放到系統中
-rw-r--r--. 1 root root 1073322 5月 22 09:31 nginx-1.22.0.tar.gz
[root@localhost opt]# systemctl stop firewalld.service 關閉防火墻
[root@localhost opt]# setenforce 0
? 2、安裝編譯過程中需要的依賴環境
yum -y install gcc pcre-devel openssl-devel zlib-devel openssl openssl-devel
? 3、創建nginx程序運行需要的用戶和組
[root@localhost opt]# useradd -M -s /bin/nologin nginx 創建用戶
? 4、編譯安裝nginx
? (1)解壓
[root@localhost opt]# tar -xf nginx-1.22.0.tar.gz
? (2) 開始配置,配置程序安裝路徑,基于程序需要的相關組件。
[root@localhost nginx-1.22.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx安裝到 /usr/local/nginx目錄下
? (3)編譯和安裝 mack 編譯 mack install 安裝
[root@localhost nginx-1.22.0]# make && make install 編譯并且安裝
? 5、后續配置,設置權限和系統管理配置。
(1) 權限配置(修改用戶組和所屬組)
[root@localhost local]# chown -R nginx.nginx nginx/
(2)做一個軟連接,讓系統能夠識別nginx的指令
[root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/ 設置軟鏈接
[root@localhost ~]# nginx -t 查看配置狀態、是否成功
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
(3)設置系統控制,系統能對nginx這個軟件的運行狀態進行控制
vim /lib/systemd/system/nginx.service[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
#表示支持dns解析以及該軟件依賴于網絡。
Wants=network-online.target
#先啟動網絡服務,才能啟動nginx
[Service]
Type=forking
PIDFile=/usr/local/nginx/run/nginx.pid
#注意文件位置,如果不對 啟動不了
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
#注意啟動文件位置
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
#支持多用戶模式
:wq
(4)創建目錄,修改nginx的配置文件
[root@localhost nginx]# mkdir /usr/local/nginx/run
[root@localhost nginx]# mkdir /usr/local/nginx/run
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid; 修改位置 /usr/local/nginx/run/nginx.pid;events {worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
[root@localhost conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost /]# systemctl daemon-reload 重新讀取
[root@localhost /]# systemctl restart nginx 啟動ngin
rpm安裝 基于安裝包安裝 .rpm
yum 安裝方式就是rpm升級版
源碼安裝的升級版本
rpm 的安裝解決了源碼安裝的繁瑣,基本實現了一鍵安裝,沒有解決包一包之間的依賴關系。
rpm
-i 安裝過程中的詳細信息
-v 顯示安裝的過程中的詳細信息
-h 在安裝過程中已“#” 顯示安裝
rpm -ivh 安裝包
rpm -q 軟件名 (查詢系統已經安裝該軟件)
httpd-2.4.6-88.el7.centos.x86 64
httpd :軟件名稱 apache web 軟件
2.4.6 軟件版本
88:更新迭代88次
x86_64: 64為的x86的CPU