编译和安装
稍微复杂一些的程序和服务都是提供源码
这样就就不能通过rpm和yum来安装软件
必须自己编译和安装程序
make项目管理器
- c、c++
- configure脚本 --> Makefile.in --> makefile
- ./configure 执行脚本
1.1. 可以传递参数,指定其中特性、安装路径等;执行时会参考用户的指定以及Makefile.in文件生成Makefile
1.2. 检查依赖到的外部环境,如依赖的软件包
- make 根据Makefile文件,构建应用程序
- make install 复制文件到相应路径
maven
- java
前提工作
- 关闭防火墙
centos6: service iptables stop; chkconfig iptables off
centos7: systemctl stop firewalld; systemctl disable firewalld
- 关闭SELinux
setenforce 0
vim /etc/selinux/config SELINUX=disable
- 安装相应的包和包组,如一般需要安装开发包yum groupinstall “Development tools”
编译
下载源码至服务器上,解包后查看目录
目录中可看到configure脚本、Makefile.in
帮助文档README和安装说明INSTALL
[root@centos7 httpd-2.2.34]#ls
ABOUT_APACHE BuildAll.dsp config.layout emacs-style httpd.spec LAYOUT LICENSE NOTICE README.platforms srclib
acinclude.m4 BuildBin.dsp configure httpd.dep include libhttpd.dep Makefile.in NWGNUmakefile README-win32.txt support
Apache.dsw buildconf configure.in httpd.dsp INSTALL libhttpd.dsp Makefile.win os ROADMAP test
build CHANGES docs httpd.mak InstallBin.dsp libhttpd.mak modules README server VERSIONING
运行脚本
./configure --help #查看帮助
./configure \ #运行脚本
–prefix=/app \ #设置默认安装路径
–sysconfdir=/etc/httpd222 \ #把配置文件单独设置目录
–enable-ssl \ #开启SSL服务
如果缺包会检测不成功,打包完之后继续运行直到$?=0
[root@centos7 httpd-2.2.34]#./configure --prefix=/app --sysconfdir=/etc/httpd222 --enable-ssl
make
-j 2 使用两个CPU来运行
echo -e “\a” 发出一声响声
[root@centos7 httpd-2.2.34]#make -j 2 && echo -e "\a";sleep 1;echo -e "\a";sleep 1;echo -e "\a";sleep 1;echo -e "\a"
make install
[root@centos7 app]#ls
bin build cgi-bin error htdocs icons include lib logs man manual modules
[root@centos7 app]#cd /etc/httpd222/
[root@centos7 httpd222]#ls
extra httpd.conf magic mime.types original
[root@centos7 httpd222]#
启用服务
把/app/bin加入PATH变量,然后直接启动http服务
有报错,但是80服务起来了,去浏览器验证
安装目录中ntdocs,存放web站点
[root@centos6 httpd-2.2.34]$apachectl start
httpd: apr_sockaddr_info_get() failed for centos6.localdomain
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@centos6 httpd-2.2.34]$ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::44230 :::*
LISTEN 0 128 *:47495 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
[root@centos6 httpd-2.2.34]$
作业:
1 一键安装脚本centos6 编译安装httpd2.2.34,centos7 编译安装httpd2.4.25
在本机远程执行install.sh
curl http://testsrv/install.sh |bash
一键安装或卸载httpd2.4
install remove
remove 是删除安装目录 和源码包
# 1. 关闭httpd服务
echo "Remove httpd starting "
echo "stopping httpd"
apachectl stop &> /dev/null
# 2. 删除安装目录 /app
echo "deleting httpd dir."
rm -rf /app &> /dev/null
# 3. 删除源码和PATH变量
echo "deleting httpd source file."
find / -regex ".*httpd-2.4.27.*" |sed -r 's@(.*/httpd-2.4.27)/.*@\1@' | uniq |xargx rm -rf &> null
echo "deleting httpd path file"
rm -rf /etc/profile.d/httpdpath.sh &>/dev/null
echo "httpd has removed."
install
# 1. 配置YUM
rm -rf /etc/yum.repos.d/*
cat >/etc/yum.repos.d/base.repo <<EOF
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpcheck=0
[base]
name=base
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/x86_64/
enabled=1
gpcheck=0
EOF
yum clean all &> /dev/null
yum list &> /dev/null
yum makecache &> /dev/null
# 2. 安装包
yum -y groupinstall "Development tools" &> /dev/null
yum -y install apr-devel &> /dev/null
yum -y install apr-util-devel &> /dev/null
# 3. 获取httpd
echo "Getting the httpd.tar form network,please wait."
wget http://archive.apache.org/dist/httpd/httpd-2.4.27.tar.gz &>/dev/null
tar -zxvf httpd-2.4.27.tar.gz &> /dev/null
cd httpd-2.4.27
# 编译安装
echo "Begin install httpd server,please wait."
./configure --prefix=/app &> /dev/null && make &>/dev/null && make isntall &> /dev/null
echo "httpd service has been finished."
echo "httpd service is starting "
cat >/etc/profile.d/httpdpath.sh<<EOF
PATH=/app/bin:$PATH
EOF
PATH=/app/bin:$PATH
apachectl start &> /dev/null
echo "Apache httpd service is working!"