配置網絡YUM源和第三方YUM源及編譯安裝Apache
配置網絡YUM源和第三方YUM源及編譯安裝Apache
系統軟硬件環境平臺:
VMware Workstation Pro 12.5.5 build-5234757
CentOS Linux release 7.3.1611
內核版本:3.10.0-514.el7.x86_64
測試時間:2017年6月13日
實驗1:實現網絡YUM源
1.準備相關系統光盤,搭建網絡服務ftp或http
[執行命令]#ls /mnt [執行命令]#mount | grep "/dev/sr0" [執行命令]#mount /dev/sr0 /mnt mount: /dev/sr0 is write-protected, mounting read-only [執行命令]#cd /mnt/Packages/ [執行命令]#rpm -ivh vsftpd-3.0.2-21.el7.x86_64.rpm warning: vsftpd-3.0.2-21.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:vsftpd-3.0.2-21.el7 ################################# [100%] [執行命令]#netstat -ntl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::111 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN [執行命令]#systemctl start vsftpd //啟動服務
#########################
vsftpd服務的設置
centos6版本路徑/etc/rc.d/init.d/vsftpd
/etc/rc.d/init.d/vsftpd start //啟動服務
service vsftpd start //同上
chkconfig vsftpd on //設置開機自動啟動服務
centos7版本路徑/usr/lib/systemd/system/vsftpd.service
systemctl start vsftpd //啟動服務
systemctl enable vsftpd //設置開機自動啟動服務
iptables防火墻的設置
centos6
service iptables stop //禁用
chkconfig iptables off //下次開機禁用
centos7
systemctl stop firewalld.service //禁用
systemctl disable firewalld.service //下次開機禁用
############################
[執行命令]#netstat -ntl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::111 :::* LISTEN tcp6 0 0 :::21 :::* LISTEN //顯示FTP的端口號,說明服務啟動成功 tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN [執行命令]#iptables -vnL Chain INPUT (policy ACCEPT 2092 packets, 171K bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT udp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:53 0 0 ACCEPT tcp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:53 0 0 ACCEPT udp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:67 0 0 ACCEPT tcp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:67 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT all -- * virbr0 0.0.0.0/0 192.168.122.0/24 ctstate RELATED,ESTABLISHED 0 0 ACCEPT all -- virbr0 * 192.168.122.0/24 0.0.0.0/0 0 0 ACCEPT all -- virbr0 virbr0 0.0.0.0/0 0.0.0.0/0 0 0 REJECT all -- * virbr0 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable 0 0 REJECT all -- virbr0 * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT 1714 packets, 189K bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT udp -- * virbr0 0.0.0.0/0 0.0.0.0/0 udp dpt:68 [執行命令]#iptables -F //建議清空防火墻,避免影響實驗效果 [執行命令]#iptables -vnL Chain INPUT (policy ACCEPT 5 packets, 356 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 4 packets, 384 bytes) pkts bytes target prot opt in out source destination [執行命令]#getenforce Enforcing [執行命令]#setenforce 0 //建議關閉selinux,避免影響實驗效果 [執行命令]#getenforce Permissive [執行命令]#systemctl stop firewalld.service //如果ftp仍然不能訪問的話,可以直接關閉防火墻服務 [執行命令]#systemctl disable firewalld.service [執行命令]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)
2.復制元數據repodata和rpm包文件到網絡服務的目錄下,客戶端可以正常遠程訪問
cd /var/ftp/pub/ ls mkdir 6 7 cd 7 cp -r /mnt/repodata . ls repodata/ mkdir Packages cp -r /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm Packages/ ls Packages/ ls cd ../6 mkdir Packages umount /dev/sr0 ls /mnt/ mount /dev/sr0 /mnt ls df -h mount /dev/sr0 /mnt cp -r /mnt/repodata . ls cp /mnt/Packages/tree-1.5.3-3.el6.x86_64.rpm Packages/ ls cd
目錄和文件列表顯示如下,這裏搭建了centos6和7的yum源,為了測試各自只復制了一個rpm包,如需搭建完整的環境則需要復制光盤Packages下的所有軟件包
[執行命令]#ls /var/ftp/pub 6/ 7/ test.txt [執行命令]#ll /var/ftp/pub/6/Packages/ total 40 drwxr-xr-x. 2 root root 41 Jun 12 20:10 ./ drwxr-xr-x. 4 root root 38 Jun 12 20:09 ../ -r--r--r--. 1 root root 36884 Jun 12 20:10 tree-1.5.3-3.el6.x86_64.rpm [執行命令]#ll /var/ftp/pub/7/Packages/ total 48 drwxr-xr-x. 2 root root 42 Jun 12 20:07 ./ drwxr-xr-x. 4 root root 38 Jun 12 20:06 ../ -rw-r--r--. 1 root root 47508 Jun 12 20:07 tree-1.6.0-10.el7.x86_64.rpm [執行命令]#ll /var/ftp/pub/6/repodata/ total 27064 dr-xr-xr-x. 2 root root 4096 Jun 12 20:09 ./ drwxr-xr-x. 4 root root 38 Jun 12 20:09 ../ -r--r--r--. 1 root root 6621696 Jun 12 20:09 4344a2a6bf5b36982d263c6bdd097cb92e57910dee985a1ab445609788600c0d-filelists.sqlite.bz2 -r--r--r--. 1 root root 4880323 Jun 12 20:09 4bdfb96905d87533542b3d8b5f9b60c3909ceffa99eb7a3f873adbdee907bf1c-primary.sqlite.bz2 -r--r--r--. 1 root root 2893552 Jun 12 20:09 59379012d189411213fb362e26b449fe6bd49949bf184e77285ec36154f65074-other.sqlite.bz2 -r--r--r--. 1 root root 3145272 Jun 12 20:09 71569ab4b90fb6a4855e9a2f63f17f284f6d6a224773450e135f92816308b447-other.xml.gz -r--r--r--. 1 root root 231283 Jun 12 20:09 aa8289f99bf8aedf9426be9da6339eed4db430a72d9740b4a502cb1ec150aff8-c6-x86_64-comps.xml.gz -r--r--r--. 1 root root 1260372 Jun 12 20:09 d0df041d26b67f7e9b5c5828e5126ddbfeb3a998ec8e8426de2d260d8e 15f6-c6-x86_64-comps.xml ▽r--r--r--. 1 root root 2776232 Jun 12 20:09 d3b2352ce1e09ca85dc0897d47c381be1beacd93f33b88a584a3c7ae8b725a5e-primary.xml.gz -r--r--r--. 1 root root 5879460 Jun 12 20:09 f9a33e31c3fb73eab7900fa086b25220d412c0618bf4596c22b325bf9a4832fe-filelists.xml.gz -r--r--r--. 1 root root 4063 Jun 12 20:09 repomd.xml -r--r--r--. 1 root root 2575 Jun 12 20:09 TRANS.TBL [執行命令]#ll /var/ftp/pub/7/repodata/ total 13708 drwxr-xr-x. 2 root root 4096 Jun 12 20:06 ./ drwxr-xr-x. 4 root root 38 Jun 12 20:06 ../ -rw-r--r--. 1 root root 1495137 Jun 12 20:06 5635df73647e7bb1ac9a289c27f3a84db1db2e33d3644bf506b85562c2a3d392-primary.xml.gz -rw-r--r--. 1 root root 3103702 Jun 12 20:06 6ec2bb89ebc4b716fe62ea930164b179f2cd90e1bdf1a504cdd7832153392b1e-filelists.sqlite.bz2 -rw-r--r--. 1 root root 3069068 Jun 12 20:06 889dab2d016c523397f24315cacb947484b06607924cc7e4716017842515df52-filelists.xml.gz -rw-r--r--. 1 root root 971157 Jun 12 20:06 8d04a279fb66b24cab67e8ebc33ef0ddb4fd7d37f9d9608585598a1b80138f53-other.xml.gz -rw-r--r--. 1 root root 3122198 Jun 12 20:06 b1b2cb9f67759ef5d143a211c2399d800fa58cf3ab12c205188e3c13d1b3d41d-primary.sqlite.bz2 -rw-r--r--. 1 root root 159099 Jun 12 20:06 c55e5b7bbe933fa8dac2cffca4596c265812b74ed12ef3968d487dd6eb22ad93-c7-x86_64-comps.xml.gz -rw-r--r--. 1 root root 748686 Jun 12 20:06 d918936f5019be3fb66e9981a28cb2a41477a2963d741d454f79377a22214f43-c7-x86_64-comps.xml -rw-r--r--. 1 root root 1339096 Jun 12 20:06 e4e51f819c9dfc35ad68a2745f1e39020d003741cbb1346d93f776d13e44351c-other.sqlite.bz2 -rw-r--r--. 1 root root 3732 Jun 12 20:06 repomd.xml -r--r--r--. 1 root root 2575 Jun 12 20:06 TRANS.TBL
3.配置客戶端YUM源,測試安裝軟件
yum客戶端配置文件:
[ftpbase] //不能重名
name=centos7 //描述信息
baseurl=URL //http,ftp,file文件路徑
enabled={1|0} //1啟用,0禁用
gpgcheck={1|0} //是否開啟驗證
[執行命令]#mkdir /etc/yum.repos.d/back //首先需要備份原來的*.repo文件 [執行命令]#cd /etc/yum.repos.d/back [執行命令]#mv C* back/ [執行命令]#vi /etc/yum.repos.d/ftp.repo [ftpbase] name=ftp yum server baseurl=ftp://192.168.x.x/pub/$releasever gpgcheck=0 [執行命令]#yum repolist //查詢yum源是否設置成功 Loaded plugins: fastestmirror, langpacks ftpbase | 3.6 kB 00:00:00 (1/2): ftpbase/7/group_gz | 155 kB 00:00:00 (2/2): ftpbase/7/primary_db | 3.0 MB 00:00:00 Loading mirror speeds from cached hostfile repo id repo name status ftpbase/7 ftp yum server 3,831 repolist: 3,831 [執行命令]#rpm -qa tree tree-1.6.0-10.el7.x86_64 [執行命令]#rpm -e tree [執行命令]#tree bash: tree: command not found... [執行命令]#yum install tree //通過yum源安裝軟件 Loaded plugins: fastestmirror, langpacks base | 3.6 kB 00:00:00 Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package tree.x86_64 0:1.6.0-10.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================= Package Arch Version Repository Size ======================================================================================================= Installing: tree x86_64 1.6.0-10.el7 base 46 k Transaction Summary ======================================================================================================= Install 1 Package Total download size: 46 k Installed size: 87 k Is this ok [y/d/N]: y Downloading packages: tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : tree-1.6.0-10.el7.x86_64 1/1 Verifying : tree-1.6.0-10.el7.x86_64 1/1 Installed: tree.x86_64 0:1.6.0-10.el7 Complete! [執行命令]#yum list | grep tree //查看軟件是否安裝成功 tree.x86_64 1.6.0-10.el7 @base texlive-pst-tree.noarch 2:svn24142.1.12-38.el7 base [執行命令]#cd [執行命令]#yum remove tree //卸載軟件 Loaded plugins: fastestmirror, langpacks Resolving Dependencies --> Running transaction check ---> Package tree.x86_64 0:1.6.0-10.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================= Package Arch Version Repository Size ======================================================================================================= Removing: tree x86_64 1.6.0-10.el7 @base 87 k Transaction Summary ======================================================================================================= Remove 1 Package Installed size: 87 k Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : tree-1.6.0-10.el7.x86_64 1/1 Verifying : tree-1.6.0-10.el7.x86_64 1/1 Removed: tree.x86_64 0:1.6.0-10.el7 Complete! [執行命令]#tree -bash: /usr/bin/tree: No such file or directory
實驗2:實現第三方YUM源
1.搭建網絡服務,客戶端可以正常遠程訪問,實驗1已經實現,這裏省略
2.復制第三方軟件到網絡服務的目錄下,並創建元數據
umount /mnt df -h mount /dev/sr0 /mnt ls /mnt/ cd /var/ftp/pub/ mkdir app cp /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm app cd createrepo /var/ftp/pub/app/ //通過creatrepo命令創建元數據repodata cd /var/ftp/pub/app/ ls repodata/ cd
3.配置客戶端YUM源,測試安裝軟件
[執行命令]#vi /etc/yum.repos.d/ftp.repo [app] name=app yum server baseurl=ftp://192.168.10.14/pub/app gpgcheck=0 [執行命令]#yum repolist [執行命令]#yum install tree.x86_64 //測試安裝軟件
實驗3:源碼編譯安裝Apache
1.下載Apache源碼包並解壓
tar -xvf httpd-2.4.25.tar.bz2 ls cd httpd-2.4.25/ ls
2.安裝開發工具包組 Development Tools
[執行命令]#vi /etc/yum.repos.d/ftp.repo //更改yum源為光盤 [cdrom] name=cdrom yum baseurl=file:///mnt gpgcheck=0 [執行命令]#yum repolist yum groups install Development\ Tools 安裝devel包組
3.查看README和INSTALL幫助文件,確定編譯安裝的參數設置
more README
more INSTALL
4.configure,即配置安裝路徑和參數,如出現錯誤,則安裝對應的包,一般為提示的文件名後加-devel即為需要安裝的包名,如
rpm -qa filename
yum search filename
yum install filename-devel
./configure --prefix=/app/apache24 //提示依賴關系,缺少apr的包 rpm -qa apr //查詢apr來自哪個rpm包文件 yum search apr //查詢yum源是否有這個包文件,顯示如下 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile ========================================== N/S matched: apr =========================================== apr-devel.x86_64 : APR library development kit apr-util-devel.x86_64 : APR utility library development kit apr.x86_64 : Apache Portable Runtime library apr-util.x86_64 : Apache Portable Runtime Utility library haproxy.x86_64 : TCP/HTTP proxy and load balancer for high availability environments Name and summary matches only, use "search all" for everything. yum install apr-devel //安裝包文件,包名為apr-devel ./configure --prefix=/app/apache24 //繼續配置過程 //提示缺少apr-util包,重復上述操作,依次解決所有依賴問題 rpm -qa apr-util yum search apr-util yum install apr-util-devel ./configure --prefix=/app/apache24 rpm -qa pcre-config rpm -qa pcre yum search pcre yum install pcre-devel ./configure --prefix=/app/apache24 //配置成功
5.make && make install,編譯安裝
cd cd httpd-2.4.25/ ls make && make install //編譯安裝httpd
6.啟動服務並測試軟件是否安裝成功
cd /app/apache24/ iptables -vnL /app/apache24/bin/apachectl start netstat -ntl cd /app/apache24/htdocs/ //這裏是存放網站的目錄 ls
測試頁面顯示 “it works!”
可以將httpd的啟動文件添加到PATH目錄中,這樣就可以直接運行,而不用指定絕對路徑。
echo "PATH=$PATH:$dirname/bin" > /etc/profile.d/apache2.sh;cd /etc/profile.d/;. apache2.sh;cd
下次就可以直接運行命令
apachectl start | stop | restart | status
本文出自 “rackie” 博客,請務必保留此出處http://rackie386.blog.51cto.com/11279229/1934923
配置網絡YUM源和第三方YUM源及編譯安裝Apache