運行環境:centos7.3最小化安裝(無法連接互聯網)
gcc,g++安裝4.8.5版本,先安裝gcc,再安裝g++
一、準備gcc的所需依賴包,截圖如下:
執行:
rpm -ivh *.rpm --nodepts --force
或
rpm -uvh *.rpm --nodepts --force
ivh是安裝,uvh是升級
二、準備g++的所需依賴包,截圖如下:
執行:
rpm -ivh *.rpm --nodepts --force
或
rpm -uvh *.rpm --nodepts --force
ivh是安裝,uvh是升級
三、查看gcc、g++是否安裝或者升級成功
輸入命令:
gcc --version或者gcc -v
g++ --version或者g++ -v
四、nginx1.18安裝
1、查看是否需要perl是否安裝(用於安裝和編譯nginx等包)
perl -v
若沒有安裝的話,手動下載離線包
查看對應的操作系統,這裏選擇5.16版本,版本過高會出現錯誤,無法安裝和編譯
2、安裝nginx1.18的依賴包,如下:
安裝步驟如下:
tar zxvf opensslfips1.1.0h.tar.gz
cd opensslfips1.1.0h
./config && make && make install
tar zxvf pcre8.42.tar.gz
cd pcre8.42
./configure && make && make install
tar zxvf zlib1.2.11.tar.gz
cd zlib1.2.11
./configure && make && make install
tar zxvf nginx1.18.0.tar.gz
cd nginx1.18.0
./configure && make && make install
查看nginx安裝位置並啓動
whereis nginx
cd /usr/local/nginx/sbin
./nginx
訪問查看nginx是否安裝成功
五、redis 5.0.9安裝
1、解壓和安裝
解壓複製到tar -zxvf /usr/local/redis-5.0.9.tar.gz -C /usr/local/redis
跳轉目錄至cd /usr/local/redis/redis-5.0.9
預先安裝gcc和make這兩個軟件,whereis gcc make查看軟件是否安裝
編譯和安裝make && make install
查看編譯好的命令文件:ls /usr/local/bin/redis-*
注意:gcc版本和redis版本會有對應關係,不然報錯,4.8.5版本的gcc對應redis5.0.x,4.9.2版本的gcc對應redis6.0.x
2、文件配置
vim /usr/local/redis/redis-5.0.9/redis.conf
#Bind 127.0.0.1如果需要遠程訪問,可將此行註釋,或綁定一個真實ip
protected-mode no關閉保護模式,不然遠程連接不了
daemonize yes設爲允許後臺運行
#requirepass foobared 密碼設置
logfile “/usr/local/redis/redis-5.0.9/redis_log.log” 修改redis日誌存放位置dir /usr/local/redis/redis-5.0.9 修改redis安裝位置
開放指定的端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
3、啓動、設置開機啓動、調試
redis-server /usr/local/redis/redis-5.0.9/redis.conf 使用指定配置啓動[後臺啓動模式]
啓動成功測試
ps axu|grep redis
redis-cli shutdown 沒有設置密碼,運行此行代碼
redis-cli -a 123456 shutdown 設置密碼,運行此行
vim /etc/systemd/system/redis.service文件不存在,則會創建此文件
[Unit]
Description=redis-server
After=network.target
[Service]
#服務運行參數的設置
#[Service]的啓動、重啓、停止命令全部要求使用絕對路徑
#forking是後臺運行的形式
Type=forking
#服務的具體運行命令
ExecStart=/usr/local/redis/redis-5.0.9/src/redis-server /usr/local/redis/redis-5.0.9/redis.conf
#ExecReload重啓命令
#ExecStop爲停止命令
#PrivateTmp=True表示給服務分配獨立的臨時空間
PrivateTmp=true
[Install]
#運行級別下服務安裝的相關設置,可設置爲多用戶,即系統運行級別爲3
WantedBy=multi-user.target
保存後執行chkconfig redis on
此命令用於重新加載修改後的啓動腳本
systemctl daemon-reload
顯示概要systemctl status redis.service
查看啓動詳情journalctl -xe
顯示實時日誌journalctl -f
查看本機監聽端口netstat -tunlp|grep redis
啓動systemctl start redis.service
本地測試連接是否成功