无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Shell 自動安裝Apache

2023-08-13 11:11 作者:小步2023  | 我要投稿

詳情地址:? https://www.xiaobuteach.com/shell/auto/install-apache.html?from=bili

Shell 自動安裝Apache

我們先回顧手動安裝Apache(通過源碼安裝包)的步驟,然后分析、將手動執(zhí)行代碼轉化為shell腳本。

手工安裝Apache

參考?第9章 軟件安裝—Apache源碼安裝?。

我們先下載好安裝文件并上傳到指定目錄/software/httpd-2.4.57.tar.bz2,不用在Shell里下載。

步驟1:解壓

tar -xvf /software/httpd-2.4.57.tar.bz2 -C /usr/local/src/

步驟2:安裝依賴

yum -y install gcc apr-devel apr-util-devel pcre-devel

步驟3:編繹

cd /usr/local/src/httpd-2.4.57 ./configure --prefix=/usr/local/httpd

步驟4:編繹與安裝

make && make install

步驟5:配置后臺服務

1)復制程序到后臺服務目錄

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

【重點】2)編輯文件httpd

vim /etc/init.d/httpd

#!/bin/sh下添加如下兩行

#chkconfig: 345 85 15 #description:apache start and stop

步驟6:添加服務,設置為自動啟動

chkconfig --add httpd chkconfig httpd on

步驟7:啟動服務

systemctl start httpd

步驟8:測試

curl localhost

自動安裝Apache

目標

通過執(zhí)行一個腳本文件,自動完成上述所有動作。


分析

第5步:2)編輯文件httpd

vim /etc/init.d/httpd

#!/bin/sh下添加行

#chkconfig: 345 85 15

這里需要修改文件,找到相應內容,追加1行,可以通過 sed命令完成。

sed -i \ '/#!\/bin\/sh/a#chkconfig: 345 85 15' \ /etc/init.d/httpd

-i表示修改會保存到文件;

前兩行結尾的\用于將一條命令分多行;

'/字符串1/a字符串2'表示搜索字符串1,在下一行添加字符串2;

字符串#!/bin/s含有特殊字符/,/前加\進行轉義。

sed命令更多用法見下節(jié)。


完整代碼

01apache-install.sh

tar -xvf /software/httpd-2.4.57.tar.bz2 -C /usr/local/src/ echo '解壓完成' yum -y install gcc apr-devel apr-util-devel pcre-devel echo '依賴包安裝完成' cd /usr/local/src/httpd-2.4.57 ./configure --prefix=/usr/local/httpd make && make install echo '編繹安裝完成' cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd sed -i \ '/#!\/bin\/sh/a#chkconfig: 345 85 15' \ /etc/init.d/httpd chkconfig --add httpd chkconfig httpd on echo '服務配置完成' systemctl start httpd echo '服務啟動完成' curl localhost echo '測試完成'

執(zhí)行

sh 01apache-install.sh

運行效果


Shell 自動安裝Apache的評論 (共 條)

分享到微博請遵守國家法律
泸溪县| 高平市| 东莞市| 滁州市| 汝南县| 邵东县| 博罗县| 揭阳市| 宁陵县| 安义县| 丰县| 安平县| 辛集市| 宽城| 班戈县| 雷山县| 阳东县| 五家渠市| 名山县| 寿光市| 土默特左旗| 南靖县| 宁晋县| 霍城县| 深州市| 鄂州市| 龙井市| 清水县| 宁远县| 开鲁县| 海丰县| 农安县| 田阳县| 行唐县| 长沙市| 镇宁| 泗阳县| 昭觉县| 九龙城区| 六安市| 呼伦贝尔市|