linux实践——编译安装两个apache

linux系统安装两个apache

系统: linux ubuntu 14.04 64位

使用版本apache 2.4.10其他软件mysql、php等自行安装

编译安装apache1
1、安装依赖
  

apt-get -y update 
apt-get -y install unzip build-essential libncurses5-dev libfreetype6-dev libxml2-dev libssl-dev libcurl4-openssl-dev libjpeg62-dev libpng12-dev libfreetype6-dev libsasl2-dev libpcre3-dev autoconf libperl-dev libtool libaio* 
apt-get -y install --only-upgrade bash 
iptables -F

 

2、优化联网(已经优化忽略此步)

cp /etc/sysctl.conf /etc/sysctl.conf.bak
sed -i 's/net\.ipv4\.tcp_syncookies.*/net\.ipv4\.tcp_syncookies = 1/' /etc/sysctl.conf
cat >> /etc/sysctl.conf <<EOF
fs.file-max=65535
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 5
net.ipv4.tcp_syn_retries = 5
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 5010 641280 5010 128
net.core.wmem_default=262144
net.core.wmem_max=262144
net.core.rmem_default=4194304
net.core.rmem_max=4194304
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_window_scaling = 0
net.ipv4.tcp_sack = 0
kernel.hung_task_timeout_secs = 0
EOF
sysctl -p
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf

 

3、添加对应用户及目录环境

useradd -g www -M -d /alidata/www -s /usr/sbin/nologin www &> /dev/null
mkdir -p /alidata
mkdir -p /alidata/server
mkdir -p /alidata/www
mkdir -p /alidata/log
chown -R www:www /alidata/log
mkdir -p /alidata/server/httpd-2.4.10
mkdir -p /alidata/log/httpd
mkdir -p /alidata/log/httpd/access
ln -s /alidata/server/httpd-2.4.10 /alidata/server/httpd

 

4、编译库

CPU_NUM=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ ! -f libiconv-1.13.1.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/libiconv-1.13.1.tar.gz
fi
rm -rf libiconv-1.13.1
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local
if [ $CPU_NUM -gt 1 ];then
make -j$CPU_NUM
else
make
fi
make install
cd ..

if [ ! -f zlib-1.2.3.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/zlib-1.2.3.tar.gz
fi
rm -rf zlib-1.2.3
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
if [ $CPU_NUM -gt 1 ];then
make CFLAGS=-fpic -j$CPU_NUM
else
make CFLAGS=-fpic
fi
make install
cd ..

if [ ! -f freetype-2.1.10.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/freetype-2.1.10.tar.gz
fi
rm -rf freetype-2.1.10
tar zxvf freetype-2.1.10.tar.gz
cd freetype-2.1.10
./configure --prefix=/usr/local/freetype.2.1.10
if [ $CPU_NUM -gt 1 ];then
make -j$CPU_NUM
else
make
fi
make install
cd ..

if [ ! -f libpng-1.2.50.tar.gz ];then
#wget http://soft.phpwind.me/web/libpng-1.2.8.tar.gz
wget http://oss.aliyuncs.com/aliyunecs/onekey/libpng-1.2.50.tar.gz
fi
rm -rf libpng-1.2.50
tar zxvf libpng-1.2.50.tar.gz
cd libpng-1.2.50
./configure --prefix=/usr/local/libpng.1.2.50
if [ $CPU_NUM -gt 1 ];then
make CFLAGS=-fpic -j$CPU_NUM
else
make CFLAGS=-fpic
fi
make install
cd ..

if [ ! -f libevent-1.4.14b.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/libevent-1.4.14b.tar.gz
fi
rm -rf libevent-1.4.14b
tar zxvf libevent-1.4.14b.tar.gz
cd libevent-1.4.14b
./configure
if [ $CPU_NUM -gt 1 ];then
make -j$CPU_NUM
else
make
fi
make install
cd ..

if [ ! -f libmcrypt-2.5.8.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/libmcrypt-2.5.8.tar.gz
fi
rm -rf libmcrypt-2.5.8
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --disable-posix-threads
if [ $CPU_NUM -gt 1 ];then
make -j$CPU_NUM
else
make
fi
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../..

if [ ! -f pcre-8.12.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/pcre-8.12.tar.gz
fi
rm -rf pcre-8.12
tar zxvf pcre-8.12.tar.gz
cd pcre-8.12
./configure
if [ $CPU_NUM -gt 1 ];then
make -j$CPU_NUM
else
make
fi
make install
cd ..

if [ ! -f jpegsrc.v6b.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/jpegsrc.v6b.tar.gz
fi
rm -rf jpeg-6b
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
if [ -e /usr/share/libtool/config.guess ];then
cp -f /usr/share/libtool/config.guess .
elif [ -e /usr/share/libtool/config/config.guess ];then
cp -f /usr/share/libtool/config/config.guess .
fi
if [ -e /usr/share/libtool/config.sub ];then
cp -f /usr/share/libtool/config.sub .
elif [ -e /usr/share/libtool/config/config.sub ];then
cp -f /usr/share/libtool/config/config.sub .
fi
./configure --prefix=/usr/local/jpeg.6 --enable-shared --enable-static
mkdir -p /usr/local/jpeg.6/include
mkdir /usr/local/jpeg.6/lib
mkdir /usr/local/jpeg.6/bin
mkdir -p /usr/local/jpeg.6/man/man1
if [ $CPU_NUM -gt 1 ];then
make -j$CPU_NUM
else
make
fi
make install-lib
make install
cd ..

#load /usr/local/lib .so
touch /etc/ld.so.conf.d/usrlib.conf
echo "/usr/local/lib" > /etc/ld.so.conf.d/usrlib.conf
/sbin/ldconfig

 

5、编译apache

#!/bin/bash
rm -rf httpd-2.4.10 apr-1.5.0 apr-util-1.5.3
if [ ! -f httpd-2.4.10.tar.gz ];then
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/httpd/httpd-2.4.10.tar.gz
fi
tar zxvf httpd-2.4.10.tar.gz

if [ ! -f apr-1.5.0.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz
fi
tar -zxvf apr-1.5.0.tar.gz
cp -rf apr-1.5.0 httpd-2.4.10/srclib/apr

if [ ! -f apr-util-1.5.3.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz
fi
tar -zxvf apr-util-1.5.3.tar.gz
cp -rf apr-util-1.5.3 httpd-2.4.10/srclib/apr-util

cd httpd-2.4.10
./configure --prefix=/alidata/server/httpd \
--with-mpm=prefork \
--enable-so \
--enable-rewrite \
--enable-mods-shared=all \
--enable-nonportable-atomics=yes \
--disable-dav \
--enable-deflate \
--enable-cache \
--enable-disk-cache \
--enable-mem-cache \
--enable-file-cache \
--enable-ssl \
--with-included-apr \
--enable-modules=all \
--enable-mods-shared=all
CPU_NUM=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ $CPU_NUM -gt 1 ];then
make -j$CPU_NUM
else
make
fi
make install
cp support/apachectl /etc/init.d/httpd
chmod u+x /etc/init.d/httpd
cd ..

cp /alidata/server/httpd/conf/httpd.conf /alidata/server/httpd/conf/httpd.conf.bak

sed -i "s;#LoadModule rewrite_module modules/mod_rewrite.so;LoadModule rewrite_module modules/mod_rewrite.so\nLoadModule php5_module modules/libphp5.so;" /alidata/server/httpd/conf/httpd.conf
sed -i "s#User daemon#User www#" /alidata/server/httpd/conf/httpd.conf
sed -i "s#Group daemon#Group www#" /alidata/server/httpd/conf/httpd.conf
sed -i "s;#ServerName www.example.com:80;ServerName www.example.com:80;" /alidata/server/httpd/conf/httpd.conf
sed -i "s#/alidata/server/httpd/htdocs#/alidata/www#" /alidata/server/httpd/conf/httpd.conf
sed -i "s#<Directory />#<Directory \"/alidata/www\">#" /alidata/server/httpd/conf/httpd.conf
sed -i "s#AllowOverride None#AllowOverride all#" /alidata/server/httpd/conf/httpd.conf
sed -i "s#DirectoryIndex index.html#DirectoryIndex index.html index.htm index.php#" /alidata/server/httpd/conf/httpd.conf
sed -i "s;#Include conf/extra/httpd-mpm.conf;Include conf/extra/httpd-mpm.conf;" /alidata/server/httpd/conf/httpd.conf
sed -i "s;#Include conf/extra/httpd-vhosts.conf;Include conf/extra/httpd-vhosts.conf;" /alidata/server/httpd/conf/httpd.conf

echo "HostnameLookups off" >> /alidata/server/httpd/conf/httpd.conf
echo "AddType application/x-httpd-php .php" >> /alidata/server/httpd/conf/httpd.conf

echo "Include /alidata/server/httpd/conf/vhosts/*.conf" > /alidata/server/httpd/conf/extra/httpd-vhosts.conf


mkdir -p /alidata/server/httpd/conf/vhosts/

#adjust httpd-mpm.conf
sed -i 's/StartServers 5/StartServers 10/g' /alidata/server/httpd/conf/extra/httpd-mpm.conf
sed -i 's/MinSpareServers 5/MinSpareServers 10/g' /alidata/server/httpd/conf/extra/httpd-mpm.conf
sed -i 's/MaxSpareServers 10/MaxSpareServers 30/g' /alidata/server/httpd/conf/extra/httpd-mpm.conf
sed -i 's/MaxRequestWorkers 150/MaxRequestWorkers 255/g' /alidata/server/httpd/conf/extra/httpd-mpm.conf

/etc/init.d/httpd start

 

到这里第一个apache1就装完了,端口默认80,接下来安装第二个端口为8081
编译安装apache2

1、目录环境

mkdir -p /alidata/server/httpd-2.4.10-1 #这里区分第一个apache
mkdir -p /alidata/log/httpd2
mkdir -p /alidata/log/httpd2/access
ln -s /alidata/server/httpd-2.4.10-1 /alidata/server/httpd2

 

2、编译apache2

#!/bin/bash
if [ ! -f httpd-2.4.10.tar.gz ];then
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/httpd/httpd-2.4.10.tar.gz
fi
tar zxvf httpd-2.4.10.tar.gz

if [ ! -f apr-1.5.0.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz
fi
tar -zxvf apr-1.5.0.tar.gz
cp -rf apr-1.5.0 httpd-2.4.10/srclib/apr

if [ ! -f apr-util-1.5.3.tar.gz ];then
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz
fi
tar -zxvf apr-util-1.5.3.tar.gz
cp -rf apr-util-1.5.3 httpd-2.4.10/srclib/apr-util

cd httpd-2.4.10
./configure --prefix=/alidata/server/httpd2 \
--with-mpm=prefork \
--enable-so \
--enable-rewrite \
--enable-mods-shared=all \
--enable-nonportable-atomics=yes \
--disable-dav \
--enable-deflate \
--enable-cache \
--enable-disk-cache \
--enable-mem-cache \
--enable-file-cache \
--enable-ssl \
--with-included-apr \
--enable-modules=all \
--enable-mods-shared=all
CPU_NUM=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ $CPU_NUM -gt 1 ];then
make -j$CPU_NUM
else
make
fi
make install
cp support/apachectl /etc/init.d/httpd2
chmod u+x /etc/init.d/httpd2
cd ..

cp /alidata/server/httpd2/conf/httpd.conf /alidata/server/httpd2/conf/httpd.conf.bak

sed -i "s;#LoadModule rewrite_module modules/mod_rewrite.so;LoadModule rewrite_module modules/mod_rewrite.so\nLoadModule php5_module modules/libphp5.so;" /alidata/server/httpd2/conf/httpd.conf
sed -i "s#User daemon#User www#" /alidata/server/httpd2/conf/httpd.conf
sed -i "s#Group daemon#Group www#" /alidata/server/httpd2/conf/httpd.conf
sed -i "s#Listen 80#Listen 8081#" /alidata/server/httpd2/conf/httpd.conf
sed -i "s;#ServerName www.example.com:80;ServerName www.example.com:80;" /alidata/server/httpd2/conf/httpd.conf
sed -i "s#/alidata/server/httpd2/htdocs#/alidata/www#" /alidata/server/httpd2/conf/httpd.conf
sed -i "s#<Directory />#<Directory \"/alidata/www\">#" /alidata/server/httpd2/conf/httpd.conf
sed -i "s#AllowOverride None#AllowOverride all#" /alidata/server/httpd2/conf/httpd.conf
sed -i "s#DirectoryIndex index.html#DirectoryIndex index.html index.htm index.php#" /alidata/server/httpd2/conf/httpd.conf
sed -i "s;#Include conf/extra/httpd-mpm.conf;Include conf/extra/httpd-mpm.conf;" /alidata/server/httpd2/conf/httpd.conf
sed -i "s;#Include conf/extra/httpd-vhosts.conf;Include conf/extra/httpd-vhosts.conf;" /alidata/server/httpd2/conf/httpd.conf

echo "HostnameLookups off" >> /alidata/server/httpd2/conf/httpd.conf
echo "AddType application/x-httpd-php .php" >> /alidata/server/httpd2/conf/httpd.conf

echo "Include /alidata/server/httpd/conf/vhosts/*.conf" > /alidata/server/httpd2/conf/extra/httpd-vhosts.conf

mkdir -p /alidata/server/httpd2/conf/vhosts/

#adjust httpd-mpm.conf
sed -i 's/StartServers 5/StartServers 10/g' /alidata/server/httpd2/conf/extra/httpd-mpm.conf
sed -i 's/MinSpareServers 5/MinSpareServers 10/g' /alidata/server/httpd2/conf/extra/httpd-mpm.conf
sed -i 's/MaxSpareServers 10/MaxSpareServers 30/g' /alidata/server/httpd2/conf/extra/httpd-mpm.conf
sed -i 's/MaxRequestWorkers 150/MaxRequestWorkers 255/g' /alidata/server/httpd2/conf/extra/httpd-mpm.conf

/etc/init.d/httpd2 start

 

ps:参考aliyun环境配置

posted @ 2015-11-03 18:05  艾小麦  阅读(1417)  评论(0编辑  收藏  举报