構建LAMP網站服務 第一步 編譯安裝httpd服務器
- 1、安裝前準備
- 2、編譯安裝apr
- 3、編譯安裝expat
- 4、編譯安裝apr-util
- 5、編譯安裝pcre
- 6、編譯安裝httpd
- 7、selinux配置
- 8、防火墻配置
- 9、修改主組態檔httpd.conf
- 10、http.conf 語法檢查
- 11、啟動httpd服務
- 12、測驗
- 13、測驗本機httpd服務器的性能
1、安裝前準備
解壓apr apr-util pcre httpd expat包
[root@localhost app]# tar -xvf apr-1.6.5.tar.xz -C /app/
[root@localhost app]# tar -xvf apr-util-1.6.1.tar.xz -C /app/
[root@localhost app]# tar -xvf pcre-8.42.tar.xz -C /app/
[root@localhost app]# tar -xvf httpd-2.4.46.tar.xz -C /app/
[root@localhost app]# ls
apr-1.6.5 apr-util-1.6.1 httpd-2.4.46 packages pcre-8.42
安裝軟體支持
[root@localhost apr-1.6.5]# dnf -y install gcc gcc-c++ make cmake gdb libstdc++*
2、編譯安裝apr
[root@localhost apr-1.6.5]# pwd
/app/apr-1.6.5
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.5]# make && make install
這里運行編譯檔案時可能會報錯
rm: cannot remove 'libtoolT': No such file or directory
解決:
[root@localhost apr-1.6.5]# vim configure
#把RM='$RM'改為RM='$RM -f'
3、編譯安裝expat
[root@localhost expat-2.2.3]# pwd
/app/expat-2.2.3
[root@localhost expat-2.2.3]# ./configure --prefix=/usr/local/expat
make && make install
4、編譯安裝apr-util
[root@localhost apr-util-1.6.1]# pwd
/app/apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-expat=/usr/local/expat
make && make install
5、編譯安裝pcre
[root@localhost pcre-8.42]# pwd
/app/pcre-8.42
[root@localhost pcre-8.42]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.42]# make && make install
6、編譯安裝httpd
[root@localhost httpd-2.4.46]# pwd
/app/httpd-2.4.46
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite --enable-ssl --with-ssl=/usr/lib --enable-auth-digest --enable-cgi --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache/htdocs
#這里的編譯選項應當是需要什么加什么,具體選項見說明檔案
httpd服務的目錄結構
服務目錄:/usr/local/apache/
主組態檔:/usr/local/apache/conf/httpd.conf
網頁目錄:/usr/local/apache/htdocs/
服務腳本:/usr/local/apache/bin/apachectl
執行程式:/usr/local/apache/bin/httpd
訪問日志: /usr/local/apache/log/access_log
錯誤日志: /usr/local/apache/log/error_log
7、selinux配置
[root@localhost httpd-2.4.46]# getsebool -a | grep httpd
httpd_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> off
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> off
httpd_run_ipa --> off
httpd_run_preupgrade --> off
httpd_run_stickshift --> off
httpd_serve_cobbler_files --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_sys_script_anon_write --> off
httpd_tmp_exec --> off
httpd_tty_comm --> off
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_fusefs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
httpd_use_opencryptoki --> off
httpd_use_openstack --> off
httpd_use_sasl --> off
httpd_verify_dns --> off
[root@localhost httpd-2.4.46]# setsebool -P httpd_anon_write on
[root@localhost httpd-2.4.46]# setsebool -P httpd_can_check_spam on
[root@localhost httpd-2.4.46]# setsebool -P httpd_can_network_connect on
[root@localhost httpd-2.4.46]# setsebool -P httpd_can_network_connect_db on
[root@localhost httpd-2.4.46]# setsebool -P httpd_can_network_relay on
[root@localhost httpd-2.4.46]# setsebool -P httpd_tmp_exec on
[root@localhost httpd-2.4.46]# setsebool -P httpd_ssi_exec on
[root@localhost httpd-2.4.46]# setsebool -P httpd_enable_cgi on
8、防火墻配置
[root@localhost httpd-2.4.46]# firewall-cmd --add-port=80/tcp --permanent
success
[root@localhost httpd-2.4.46]# firewall-cmd --add-port=443/tcp --permanent
success
[root@localhost httpd-2.4.46]# firewall-cmd --add-port=8080/tcp --permanent
success
[root@localhost httpd-2.4.46]# firewall-cmd --add-port=8888/tcp --permanent
success
[root@localhost httpd-2.4.46]# firewall-cmd --add-service=http --permanent
success
[root@localhost httpd-2.4.46]# firewall-cmd --add-service=https --permanent
success
[root@localhost httpd-2.4.46]# firewall-cmd --reload
success
9、修改主組態檔httpd.conf
[root@localhost conf]# pwd
/usr/local/apache/conf
[root@localhost conf]# vim httpd.conf
ServerAdmin mufeng.yu@qq.com #管理員郵箱
ServerName www.mufeng.com:80 #站點名稱
ServerRoot:服務目錄
ServerAdmin:管理員郵箱
User:運行服務的用戶身份
Group:運行服務的組身份
ServerName:網站服務器的域名
DocumentRoot:網頁檔案的根目錄
Listen:監聽的IP地址、埠號
PidFile:保存httpd行程PID號的檔案
DirectoryIndex:默認的索引頁檔案
ErrorLog:錯誤日志檔案的位置
CustomLog:訪問日志檔案的位置
LogLevel:記錄日志的級別,默認為warn
Timeout:網路連接超時,默認為300秒
KeepAlive:是否保持連接,可選On或Off
MaxKeepAliveRequests:每次連接最多請求檔案數
KeepAliveTimeout:保持連接狀態時的超時時間
Include:需要包含進來的其他組態檔
10、http.conf 語法檢查
[root@localhost conf]# /usr/local/apache/bin/apachectl -t
Syntax OK
11、啟動httpd服務
[root@localhost conf]# /usr/local/apache/bin/apachectl start
12、測驗
[root@localhost conf]# wget www.mufeng.com
--2020-12-01 08:41:48-- http://www.mufeng.com/
Resolving www.mufeng.com (www.mufeng.com)... 192.35.35.1
Connecting to www.mufeng.com (www.mufeng.com)|192.35.35.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45 [text/html]
Saving to: ‘index.html’
index.html 100%[==========================================================>] 45 --.-KB/s in 0s
2020-12-01 08:41:48 (7.99 MB/s) - ‘index.html’ saved [45/45]
[root@localhost conf]# vim index.html
<html><body><h1>It works!</h1></body></html>
這個測驗完全可以通過ip地址來實作,如果想通過域名訪問,需要配置自己的DNS域名服務器bind
13、測驗本機httpd服務器的性能
ab命令格式說明
ab [-q] -c 并發請求數 -n 總的請求數 [http://]域名[:埠]/路徑
[root@localhost conf]# ulimit -n 3600
[root@localhost bin]# pwd
/usr/local/apache/bin
[root@localhost bin]# ./ab -q -c 2000 -n 4000 http://www.mufeng.com/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.mufeng.com (be patient).....done
Server Software: Apache/2.4.46
Server Hostname: www.mufeng.com
Server Port: 80
Document Path: /
Document Length: 45 bytes
Concurrency Level: 2000
Time taken for tests: 0.519 seconds
Complete requests: 4000
Failed requests: 0
Total transferred: 1156000 bytes
HTML transferred: 180000 bytes
Requests per second: 7703.79 [#/sec] (mean)
Time per request: 259.613 [ms] (mean)
Time per request: 0.130 [ms] (mean, across all concurrent requests)
Transfer rate: 2174.21 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 9 17.2 4 71
Processing: 0 17 46.8 8 428
Waiting: 0 16 46.7 7 428
Total: 0 26 58.4 12 498
Percentage of the requests served within a certain time (ms)
50% 12
66% 13
75% 15
80% 16
90% 24
95% 81
98% 283
99% 288
100% 498 (longest request)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/229345.html
標籤:其他
下一篇:Linux必備的命令
