目錄
源碼包概述
# 什么是源碼包
源碼包指的是開發編寫好的程序源代碼,但並沒有將其編譯為一個能正常使用的工具
# 為什么學習源碼包
1.部分軟件,官方只提供源碼包,需要自行編譯安裝
2.運維需要規范時,我們想把所有的軟件全都安裝到同一個目錄下
PS:咱們使用windows時,強迫症,我裝的QQ,微信,游戲等...全都要放到D盤的某一個目錄下
3.有些軟件,官方剛發布,還沒來得及制作成RPM包,那么我們可以自行編譯安裝
# 源碼包安裝步驟
安裝源碼包,必須要經歷4個步驟
1.解壓 tar
2.生成 ./configure cmake
3.編譯 make
4.安裝 make install
自制RPM包--10.0.0.100--nginx服務器
編譯安裝nginx
## 源碼安裝nginx
# 0.安裝依賴
[root@qls nginx-1.16.1]# yum install -y gcc gcc-c++ glibc zlib-devel pcre-devel openssl-devel
# 1.下載nginx源碼包
[root@qls ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
# 2.解壓
[root@qls ~]# tar xf nginx-1.16.1.tar.gz
[root@qls ~]# cd nginx-1.16.1
# 3.生成
[root@qls ~]# mkdir /app
[root@qls nginx-1.16.1]# useradd nginx -s /sbin/nologin -M
[root@qls nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --user=nginx --group=nginx
--help print this message
--prefix=PATH set installation prefix
--sbin-path=PATH set nginx binary pathname
--modules-path=PATH set modules path
--conf-path=PATH set nginx.conf pathname
--error-log-path=PATH set error log pathname
--pid-path=PATH set nginx.pid pathname
--lock-path=PATH set nginx.lock pathname
#后面的內容省略了,使用 ./configure --help 命令查看可以使用的選項。
#一般常用的有 --prefix=PREFIX 這個選項的意思是定義軟件包安裝到哪里。
#建議,源碼包都是安裝在/soft/目錄下。
# 4.編譯
[root@qls nginx-1.16.1]# make
# 5.安裝
[root@qls nginx-1.16.1]# make install
# 6.檢測配置文件有沒有語法錯誤
[root@qls sbin]# /app/nginx-1.16.1/sbin/nginx -t
nginx: the configuration file /app/nginx-1.16.1/conf/nginx.conf syntax is ok
nginx: configuration file /app/nginx-1.16.1/conf/nginx.conf test is successful
# 7.啟動nginx
[root@qls sbin]# /app/nginx-1.16.1/sbin/nginx
# 8.檢測80端口
[root@qls sbin]# netstat -lntup|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 13468/nginx: master
# 9.做軟連接
[root@qls nginx-1.16.1]# ln -s /app/nginx-1.16.1 /app/nginx
修改默認index.html頁面
## 自定義
# 修改默認頁面
[root@qls html]# vim /app/nginx-1.16.1/html/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>歡迎來到曾老濕的nginx頁面</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>歡迎來到曾老濕nginx的web頁面</h1>
<a href="http://www.driverzeng.com">我的博客地址</a>.<br/>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
制作rpm包
# 制作rpm包過程
· 下載fpm包,可從阿里源中的 [TP]( https://developer.aliyun.com/mirror/rubygems?spm=a2c6h.13651102.0.0.3e221b112nz9sk)獲取
· 解壓fpm包,目錄會有.gem文件
· gem文件服務器無法識別,需安裝ruby rubygems ruby-devel可使用命令gem
· 更換gem的默認國外源為阿里源
· 使用命令gem安裝fpm里面的所有.gem結尾的文件
· fpm命令安裝成功,即可對nginx進行打包成rpm包
-----------------------------------------------
## 制作rpm包
[root@qls ~]# mkdir fpm
[root@qls ~]# mv fpm-1.3.3.x86_64.tar.gz fpm
[root@qls fpm]# cd /root/fpm/
# 1. 解壓
[root@qls fpm]# tar xf fpm-1.3.3.x86_64.tar.gz
# 2.安裝ruby
[root@qls fpm]# yum -y install ruby rubygems ruby-devel rpm-build
# 3.查看gem的源
[root@qls fpm]# gem sources --list
*** CURRENT SOURCES ***
https://rubygems.org/
# 4.更換阿里雲的源 先移除國外源
[root@qls fpm]# gem sources --remove https://rubygems.org/
# 5.更換阿里雲的源, 添加阿里雲的源
[root@qls fpm]# gem sources -a https://mirrors.aliyun.com/rubygems/
# 6.使用gem命令安裝當前目錄下所有的.gem文件
[root@qls fpm]# gem install *.gem
# 7.寫出安裝rpm之后要執行的腳本,創建nginx用戶也可以在安裝服務后創建
[root@qls ~]# vim /root/nginx.sh
#!/bin/bash
useradd nginx -s /sbin/nologin -M
ln -s /app/nginx-1.16.1 /app/nginx
# 8.使用fpm打包
[root@qls fpm]# fpm -s dir -t rpm -n nginx -v 1.16.1 -d 'zlib-devel,gcc,gcc-c++,glibc,pcre-devel,openssl-devel' --post-install /root/nginx.sh -f /app/nginx-1.16.1/
fpm:打rpm包命令
-s:dir # 打目錄
-t:rpm # 把目錄打成rpm包
-n:nginx # 軟件名字叫nginx
-v:1.16.1 # 軟件的版本號
-d: # 指定nginx的依賴包
-f: # 指定要達成rpm包的目錄路徑
--post-install # 指定rpm包安裝完成之后要執行的腳本
--pre-install # 指定rpm包安裝之前,要執行的腳本
搭建ftp共享目錄--10.0.0.88--vsfptd服務器
# 創建流程
· 安裝並啟動ftp服務
· 將10.0.0.100服務器中做好的nginx包copy到ftp共享目錄
· 開啟/etc/yum.conf文件中的keepcache緩存為1,並修改緩存路徑為/cp
· 安裝nginx依賴包,將/tcy目錄中下載的依賴包cp到共享目錄中
· 安裝使用命令createrepo創建yum倉庫
-----------------------------------------
# 安裝fpt服務
[root@tcy pub]# yum install -y vsftpd
# 啟動ftp服務
[root@tcy pub]# systemctl start vsftpd
# 檢測ftp服務端口是否啟動
[root@tcy pub]# netstat -lntup|grep 21
# 修改文件,生成緩存
[root@tcy pub]# cat /etc/yum.conf
[main]
cachedir=/vvv # 下載路徑修改為自定義路徑
keepcache=1 # 為1開啟,安裝同時下載文件
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
# 安裝依賴包
[root@tcy pub]# yum install -y gcc gcc-c++ glibc zlib-devel pcre-devel openssl-devel
# 將緩存路徑文件cp到ftp共享目錄
[root@tcy packages]# cp -a /vvv/base/packages /var/ftp/pub
[root@tcy packages]# cp -a /vvv/updates/packages /var/ftp/pub
# 安裝createrepo命令
[root@tcy packages]# yum install -y createrepo
# 創建repodate目錄
[root@tcy packages]# createrepo /var/ftp/pub
客戶端安裝nginx--10.0.0.99
# 流程
· 重寫yum源文件
· 安裝nginx
-------------------------------------
# 重寫yum源文件
[root@oldboy yum.repos.d]# cat yum.repo
[yum]
name='yum_filename'
baseurl=ftp://10.0.0.88/pub # 路徑更改為ftp共享路徑
gpgcheck=0
enabled=1
# 檢查yum源
[root@oldboy yum.repos.d]# yum repolist
# 直接yum安裝nginx
[root@oldboy yum.repos.d]# yum install -y nginx
# 檢查nginx配置文件
[root@oldboy yum.repos.d]# /app/nginx/sbin/nginx -t
# 啟動nginx服務
[root@oldboy yum.repos.d]# /app/nginx/sbin/nginx
# 檢查端口是否啟動
[root@oldboy app]# netstat -lntup |grep 80
瀏覽器訪問客戶端ip
修改環境變量,systemctl啟動nginx
## 針對下面的文件,可使用yum安裝nginx的方法,將配置文件cp一份使用,但需要結合本地路徑進行修改
[root@localhost logs]# vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/app/nginx/logs/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /app/nginx/logs/nginx.pid
ExecStartPre=/app/nginx/sbin/nginx -t
ExecStart=/app/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
nginx -t命令直接使用方式
## 可在環境變量文件/etc/profile.d/中隨意命名如nginx.sh文件,添加如下內容
export PATH="/app/nginx/sbin:$PATH"