配置网络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
原文地址:http://rackie386.blog.51cto.com/11279229/1934923