1. Nginx服务
1.1. 编译环境
yum install -y gcc gcc-c++ pcre pcre-devel \
zlib zlib-devel openssl openssl-devel gd gd-devel
1.2. 编译安装
wget https://nginx.org/download/nginx-1.24.0.tar.gz -P /opt/src
cd /opt/src && tar xf nginx-1.24.0.tar.gz
mkdir -p /opt/apps/nginx/{logs,temp/{client_body,fastcgi,proxy,scgi,uwsgi}}
cd /opt/src/nginx-1.24.0
./configure --prefix=/opt/apps/nginx \
--user=nginx \
--group=nginx \
--error-log-path=/opt/apps/nginx/logs/error.log \
--http-log-path=/opt/apps/nginx/logs/access.log \
--pid-path=/opt/apps/nginx/logs/nginx.pid \
--http-client-body-temp-path=/opt/apps/nginx/temp/client_body \
--http-fastcgi-temp-path=/opt/apps/nginx/temp/fastcgi \
--http-proxy-temp-path=/opt/apps/nginx/temp/proxy \
--http-scgi-temp-path=/opt/apps/nginx/temp/scgi \
--http-uwsgi-temp-path=/opt/apps/nginx/temp/uwsgi \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module
make -j4 && make install
1.3. 管理服务
cd /opt/apps
mv nginx nginx-1.24.0
ln -s nginx-1.24.0 nginx
groupadd nginx && useradd nginx -g nginx -s /sbin/nologin -M
chown -R nginx:nginx /opt/apps/nginx*
cat <<EOF >/usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
Environment="CONFFILE=/opt/apps/nginx/conf/nginx.conf"
ExecStart=/opt/apps/nginx/sbin/nginx -c \$CONFFILE
ExecReload=/opt/apps/nginx/sbin/nginx -s reload
ExecStop=/opt/apps/nginx/sbin/nginx -s quit
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
1.4. 主机拆分
vim /opt/apps/nginx/conf/nginx.conf
user nginx;
worker_processes 8;
error_log /opt/apps/nginx/logs/error.log;
pid /opt/apps/nginx/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
include /opt/apps/nginx/conf/conf.d/*.conf;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /opt/apps/nginx/logs/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
}
mkdir -p /opt/apps/nginx/conf/conf.d
tee > /opt/apps/nginx/conf/conf.d/nginx.conf <<EOF
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
EOF
chown -R nginx:nginx /opt/apps/nginx*
[root@localhost conf]
nginx: the configuration file /opt/apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/apps/nginx/conf/nginx.conf test is successful
1.5. 服务验证
systemctl start nginx
curl -Is localhost| head -n 1
2. Apache服务
2.1. 编译环境
yum install -y gcc gcc-c++ pcre pcre-devel \
zlib zlib-devel openssl openssl-devel gd gd-devel
2.2. 编译安装
wget https://archive.apache.org/dist/apr/apr-1.6.5.tar.gz -P /opt/src
cd /opt/src && tar xf apr-1.6.5.tar.gz
cd /opt/src/apr-1.6.5
./configure --prefix=/usr/local/apr
make -j4 && make install
wget https://archive.apache.org/dist/apr/apr-util-1.6.0.tar.gz -P /opt/src
cd /opt/src && tar xf apr-util-1.6.0.tar.gz
cd /opt/src/apr-util-1.6.0
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make -j4 && make install
mkdir -p /opt/apps
wget https://archive.apache.org/dist/httpd/httpd-2.4.57.tar.gz -P /opt/src
cd /opt/src && tar xf httpd-2.4.57.tar.gz
cd /opt/src/httpd-2.4.57
./configure --prefix=/opt/apps/httpd \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--with-pcre --with-zlib --with-mpm=prefork \
--enable-modules=all --enable-mpms-shared=all \
--enable-so --enable-rewrite --enable-ssl --enable-cgi
make -j4 && make install
2.3. 管理服务
cd /opt/apps
mv httpd httpd-2.4
ln -s httpd-2.4 httpd
groupadd apache && useradd httpd -g apache -s /sbin/nologin -M
chown -R httpd:apache /opt/apps/httpd*
sed -i -e 's/User daemon/User httpd/g' /opt/apps/httpd/conf/httpd.conf
sed -i -e 's/Group daemon/Group apache/g' /opt/apps/httpd/conf/httpd.conf
cat > /lib/systemd/system/httpd.service <<EOF
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=forking
ExecStart=/opt/apps/httpd/bin/apachectl start
ExecReload=/opt/apps/httpd/bin/apachectl graceful
ExecStop=/opt/apps/httpd/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
2.4. 服务验证
systemctl start httpd
curl -Is localhost| head -n 1