天天看點

linux伺服器常用企業服務的安裝(二)

作者:dz菜園子

CentOS7伺服器JDK8安裝實戰

下載下傳jdk官網:

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

全局環境變量的配置檔案:vi /etc/profifile

export JAVA_HOME=/usr/local/jdk1.8 #這個路徑要改,其餘不需要改

export JRE_HOME=$JAVA_HOME/jre

export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

加載環境變量:source /etc/profifile

java -version

java version "1.8.0_211"

Java(TM) SE Runtime Environment (build 1.8.0_211-b12)

Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

CentOS7 實戰部署tomcat網站伺服器

Tomcat:是一個開源免費的Web應用伺服器,性能穩定,是目前比較流行的Web應用伺服器

tomcat官網下載下傳:

https://tomcat.apache.org/download-80.cgi

下載下傳:

yum install -y wget

wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.43/bin/apache-tomcat-8.5.43.tar.gz

解壓:tar -xf apache-tomcat-8.5.43.tar.gz

mv apache-tomcat-8.5.43 /usr/local/tomcat8

檢查java環境:java -version

tomcat重要目錄介紹

[root@localhost tomcat8]# ls -lrt /usr/local/tomcat8

total 132

drwxr-x---. 7 root root 76 Jul 5 04:53 webapps

-rw-r-----. 1 root root 16262 Jul 5 04:56 RUNNING.txt

-rw-r-----. 1 root root 7139 Jul 5 04:56 RELEASE-NOTES

-rw-r-----. 1 root root 3255 Jul 5 04:56 README.md

-rw-r-----. 1 root root 1726 Jul 5 04:56 NOTICE

-rw-r-----. 1 root root 57011 Jul 5 04:56 LICENSE

-rw-r-----. 1 root root 5407 Jul 5 04:56 CONTRIBUTING.md

-rw-r-----. 1 root root 19534 Jul 5 04:56 BUILDING.txt

drwxr-x---. 2 root root 4096 Aug 1 23:33 lib

drwxr-x---. 2 root root 29 Aug 1 23:33 temp

drwxr-x---. 2 root root 4096 Aug 1 23:33 bin

drwx------. 3 root root 4096 Aug 1 23:43 conf

drwxr-x---. 2 root root 4096 Aug 1 23:43 logs

drwxr-x---. 3 root root 21 Aug 1 23:43 work

bin:存放可執行指令,比如開啟和關閉;

conf:配置檔案;

Context.xml:Tomcat公用的環境配置,tomcat 伺服器會定時去掃描這個檔案

web.xml:Web應用程式描述檔案,都是關于是Web應用程式的配置檔案

server.xml:可以設定tomcat的端口号,添加虛拟機這些的,是對伺服器的設定

tomcat-users.xml:使用者配置檔案

webapps:釋出web應用;

lib:庫檔案;

關閉防火牆

systemctl stop firewalld.service

啟動tomcat

sh startup.sh

檢視是否監聽tomcat

linux伺服器常用企業服務的安裝(二)

測試能否通路測試頁面:IP位址:8080

linux伺服器常用企業服務的安裝(二)

CentOS7 實戰源碼部署apache網站伺服器

Apache簡介:

Apache軟體基金會的一個開源免費的網頁伺服器,也是目前世界上使用最廣泛的一種web server ,apache最出名的是它跨平台,高效和穩定,可以運作在幾乎所有廣泛使用的計算機平台上。其特點是簡單、速度快、性能穩定,并可做代

理伺服器來使用,并且可通過簡單的 API 擴充,将 Perl/Python 等解釋器編譯到伺服器中

源碼編譯安裝 Apache:

  • 下載下傳元件apr并解壓:
元件apr官方網站:http://apr.apache.org/download.cgi 
wget http://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz 
tar -xf apr-1.7.0.tar.gz           
  • 下載下傳元件apr-util并解壓:
元件apr-util官方網站:http://apr.apache.org/download.cgi
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar -xf apr-util-1.6.1.tar.gz           
  • 下載下傳apache并解壓:
apache官方網站:http://httpd.apache.org/download.cgi
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.39.tar.gz
tar -xf httpd-2.4.39.tar.gz           
  • 安裝gcc環境:
yum install -y gcc*           
  • 安裝zlib-devel庫:
yum install -y zlib-devel           
  • 安裝xml 的解析器:
yum install -y expat-devel           
  • 下載下傳并安裝pcre正規表達式庫:
下載下傳位址:https://ftp.pcre.org/pub/pcre/
tar -xf pcre-8.43.tar.gz
cd pcre-8.43
mkdir -p /usr/local/pcre
./configure --prefix=/usr/local/pcre
make && make install           
  • 把元件apr與元件apr-util拷貝到apache安裝包裡:
cp -rf apr-1.7.0 /root/test/httpd-2.4.39/srclib/apr
cp -rf apr-util-1.6.1 /root/test/httpd-2.4.39/srclib/apr-util           
  • 進入apache解壓包進行./confifigure進行環境收集檢驗與配置相關子產品:
cd /root/test/httpd-2.4.39
mkdir -p /usr/local/apache
----------------------------------------------------------------------------------
./configure \--prefix=/usr/local/apache \--sysconfdir=/usr/local/apache/etc \--with-
apr=/home/test/apr-1.7.0 \--with-apr-util=/home/test/apr-util-1.6.1 \--with-
included-apr \--with-pcre=/usr/local/pcre \--enable-deflate \--enable-expires \--
enable-headers \--enable-so \--enable-modules=most \--with-mpm=worker \--enable-
rewrite
----------------------------------------------------------------------------------
選項說明:
--prefix                                    #指定安裝目錄
--sysconfdir                            #指定配置檔案的路徑
--with-apr                               #指定依賴檔案的路徑
--with-apr-util                        #指定依賴檔案的路徑
--with-included-apr               #增加編譯效率的
--with-pcre                            #指定pcre正規表達式庫安裝路徑
--enable-deflate                    #開啟壓縮檔案提高速度節約帶寬
--enable-expires                    #開啟讓浏覽器緩存,減輕伺服器壓力,提高通路速度
--enable-headers                   #使得支援http頭
--enable-so                            #使得支援動态子產品
--enable-modules=most       #使得支援大多數子產品
--with-mpm=worker             #使得Apache工作在worker模式下
--enable-rewrite                    #使得支援位址重寫           
  • 編譯并安裝apache:
make -j4 && make install           
  • 設定伺服器名稱:
vi /usr/local/apache/etc/httpd.conf
輸入:ServerName進行搜尋
添加:
ServerName www.sddzcyz.cn           
  • 測試并啟停apache伺服器:
ln -s /usr/local/apache/bin/* /usr/sbin/ #設定軟連接配接
echo "export PATH=/usr/local/apache/bin:$PATH" >> /etc/profile #設定環境變量
source /etc/profile
#加載環境變量
httpd -t
#測試配置檔案文法有沒有錯誤
httpd -k start #啟動apache服務
httpd -k stop #關閉apache服務
在防火牆關閉的條件下,打開浏覽器,輸入IP位址,成功打開apache測試頁面           
  • 相關報錯收集與解決辦法:
(1)make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Entering directory `/home/test/apr-util-1.6.1'
/bin/sh /usr/local/apache/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -
pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/home/test/apr-
util-1.6.1/include -I/home/test/apr-util-1.6.1/include/private -
I/usr/local/apache/apr/include/apr-1 -o xml/apr_xml.lo -c xml/apr_xml.c &&
touch xml/apr_xml.lo
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
# include <expat.h> ^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/home/test/apr-util-1.6.1'
make: *** [all-recursive] Error 1
錯誤原因:缺少xml 的解析器
解決方法:yum -y install expat-devel
----------------------------------------------------------------------------------
(2)configure 時 error: APR not found
錯誤詳情:
configure:
checking for APR… no
configure: error: APR not found. Please read the documentation.
錯誤原因:沒有指定 Apache 必需元件 APR 或沒有加–with-apr 選項指定 APR
的安裝位置。
解決方法:安裝 APR 并且加-–with-apr 選項指定正确的位置。
----------------------------------------------------------------------------------
(3)configure 時-–with-apr 選項不正确
錯誤詳情:
configure:
checking for APR… configure: error: –with-apr requires a directory
or file to be provided
configure:
checking for APR… configure: error: the –with-apr parameter is
incorrect. It must specify an install prefix, a build directory, or
an apr-config file.
錯誤原因:-–with-apr 選項不能為空或者指定的 APR 的位置不正确
解決方法:指定正确的 APR 選項。其實系統中已經使用 yum 安裝了 APR,卻不
知道如何指定 yum 安裝的 APR 的位置,故出此錯誤,也可以進行手動源代碼編譯安裝
APR來解決這個錯誤。
----------------------------------------------------------------------------------
(4)configure 時 error: APR-util not found
錯誤詳情:
configure:
checking for APR-util… no
configure: error: APR-util not found. Please read the documentation.
錯誤原因:沒有安裝 Apache 必需元件 APR-util 或沒有加–with-apr-util 選
項指定 APR-util 的位置
解決方法:-–with-apr-util 選項指定正确的安裝位置
----------------------------------------------------------------------------------
(5)configure 時 error: pcre-config for libpcre not found
錯誤詳情:
checking for pcre-config… false
configure: error: pcre-config for libpcre not found. PCRE is required
and available from http://pcre.org/
錯誤原因:沒有安裝 Apache 必需元件 PCRE 或沒有加–with-pcre 選項指定
PCRE 的安裝位置。
解決方法:安裝 PCRE 并且加–with-pcre 選項指定正确的安裝位置
----------------------------------------------------------------------------------
(6)configure 時 error: Did not find pcre-config script at
/usr/local/pcre2
錯誤詳情:
checking for pcre-config… false
configure: error: Did not find pcre-config script at /usr/local/pcre2
錯誤原因: httpd 2.4.39 不支援 pcre2?
解決方法:下載下傳 pcre-8.43 安裝即可。
----------------------------------------------------------------------------------
(7)啟動 Apache 時提示設定 ServerName
錯誤詳情:
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
錯誤原因:沒有設定伺服器名稱
解決方法:vi /usr/local/apache/etc/httpd.conf           

CentOS7 實戰源碼部署nginx網站伺服器

  • nginx 簡介:

Nginx是一款高性能的 HTTP 和反向代理伺服器

  • Nginx的優點:

1.高并發量:根據官方給出的資料,能夠支援高達 50,000 個并發連接配接數的響應

2.記憶體消耗少:處理靜态檔案,同樣起web 服務,比apache 占用更少的記憶體及資源,所有它是輕量級的

3.簡單穩定:配置簡單,基本在一個conf檔案中配置,性能比較穩定,可以7*24小時長時間不間斷運作

4.子產品化程度高:Nginx是高度子產品化的設計,編寫子產品相對簡單

5.負載均衡伺服器:Nginx可以做高并發的負載均衡,且Nginx是開源免費的,如果使用F5等硬體來做負載均衡,硬體成本比較高

6.可移植性高:Nginx代碼完全用C語言編寫

  • Nginx的缺點:

1.動态處理差:nginx處理靜态檔案好,耗費記憶體少,但是處理動态頁面比較差

2.rewrite弱:雖然nginx支援rewrite功能,但是相比于Apache來說,Apache比nginx 的rewrite 強大。

  • 編譯安裝:

安裝gcc編譯環境:

yum install -y gcc-c++           

安裝zlib-devel庫:

yum install -y zlib-devel           

安裝OpenSSL密碼庫:

yum install -y openssl openssl-devel           

安裝pcre正規表達式庫:

下載下傳位址:https://ftp.pcre.org/pub/pcre/
tar -xf pcre-8.43.tar.gz
cd pcre-8.43
mkdir -p /usr/local/pcre
./configure --prefix=/usr/local/pcre
make && make install           

下載下傳編譯安裝nginx:

nginx下載下傳官網:http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.16.0.tar.gz
mkdir -p /usr/local/nginx
tar -xf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-
http_stub_status_module --with-pcre
make && make install           

啟停nginx服務:

啟動:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
測試:
/usr/local/nginx/sbin/nginx -t
關閉:
/usr/local/nginx/sbin/nginx -s stop           

打開浏覽器測試能否通路到測試頁面

linux伺服器常用企業服務的安裝(二)

參考個人部落格:cyz

繼續閱讀