国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
芷江| 石城县| 霍邱县| 精河县| 崇州市| 兴安盟| 乌拉特前旗| 陇川县| 德令哈市| 西丰县| 西华县| 伊金霍洛旗| 济源市| 托克托县| 色达县| 莱西市| 郎溪县| 惠州市| 漳州市| 柞水县| 宁国市| 文登市| 托克逊县| 望江县| 绥中县| 贺州市| 佛坪县| 时尚| 华阴市| 定兴县| 灯塔市| 三门峡市| 林芝县| 西吉县| 榆社县| 天峻县| 望江县| 兴国县| 交口县| 松滋市| 台前县|