CentOS 6 nginx(Tengine2.1.2)源码编译一键部署脚本
目標:一鍵部署nginx
軟件:tengine-2.1.2.tar.gz(nginx的分支)
備注:只適用于CentOS 6 64位系統,附帶線上生產環境的nginx配置文件
軟件包:鏈接:http://pan.baidu.com/s/1jIyZrRS 密碼:q9uu
[root@salt-master home]# cat nginx.sh?
#!/bin/bash
#
#適用版本CentOS 6 64位
#2017.5.11
. /etc/init.d/functions
dir=/root/test
user=www
group=www
del_dir() {
read -p "需要刪除${dir} 是否刪除[Y|y/N|n]:" del
case $del in
Y|y)
rm -rf $dir
mkdir $dir
cd $dir
;;
N|n)
echo "安裝終止"
exit 7
;;
*)
echo "請輸入正確的值"
exit 8
;;
esac
}
[ ! -d $dir ] && {
mkdir $dir
cd $dir
} || del_dir
wget http://172.2.0.68/tengine-2.1.2.tar.gz
wget?http://172.2.0.68/nginx.txt
wget http://172.2.0.68/pcre-8.31.tar.bz2
yum -y install gcc gcc-c++ ?pcre-devel openssl-devel
[ ! `grep $group /etc/group &>/dev/null` ] && {
groupadd www
}
[ ! `grep $user /etc/passwd &>/dev/null` ] && {
useradd -M -g www -s /sbin/nologin www
}
echo "###########安裝pcre######################"
sleep 4
tar -jxvf pcre-8.31.tar.bz2
[ $? -eq 0 ] && cd pcre-8.31 || exit 6
./configure --prefix=/usr/local/pcre
make && make install
#######################################
cd ..
[ -e $dir/tengine-2.1.2.tar.gz ] && {
tar -zxvf tengine-2.1.2.tar.gz
cd tengine-2.1.2
}
./configure --user=www --group=www --prefix=/mnt/tengine/tengine-2.1.2 --with-http_stub_status_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_upstream_check_module --with-ipv6
[ $? -eq 0 ] && {
make && make install
} || {
echo "編譯出錯"
exit 7
}
[ -f $dir/nginx.txt ] && {
mv /mnt/tengine/tengine-2.1.2/conf/nginx.conf /mnt/tengine/tengine-2.1.2/conf/nginx.confbak
cat $dir/nginx.txt >/mnt/tengine/tengine-2.1.2/conf/nginx.conf
} || {
echo "配置文件填寫錯誤,請檢查配置文件nginx.conf"
exit 5
}
echo "###啟動服務####"
/mnt/tengine/tengine-2.1.2/sbin/nginx -t
[ $? -eq 0 ] && {
/mnt/tengine/tengine-2.1.2/sbin/nginx
} || {
echo "啟動服務失敗"
exit 8
}
###########################################################################################
[root@linux-node8 html]# cat nginx.txt?
user ?www www;
worker_processes ?1;
pid /mnt/tengine/tengine-2.1.2/logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
? ? use epoll;
? ? worker_connections ?4096; ??
}
http {
? ? include ? ? ? mime.types;
? ? default_type ?application/octet-stream;
? ? #charset utf-8;
? ? access_log off;
? ? error_log logs/error.log notice;
? ? log_format ?main ?'$remote_addr - $remote_user [$time_local] "$request" '
? ? ? ? ? ? ? ? ? ? ? '$status $body_bytes_sent "$http_referer" '
? ? ? ? ? ? ? ? ? ? ?'"$http_user_agent" "$http_x_forwarded_for"$request_time"';
? ??
? ? server_names_hash_bucket_size 128;
? ? client_header_buffer_size 32k;
? ? large_client_header_buffers 4 32k;
? ? client_max_body_size 300m;
? ? sendfile ? ? ? ?on;
? ? tcp_nopush ? ? ?on;
? ? keepalive_timeout ?65;
? ? tcp_nodelay ? ? on;
? ? server_tokens ? off;
? ? client_body_buffer_size 512k;
? ? proxy_connect_timeout 5;
? ? proxy_read_timeout ? ?60;
? ? proxy_send_timeout ? ?5;
? ? proxy_buffer_size ? ? 16k;
? ? proxy_buffers ? ? ? ? 4 64k;
? ? proxy_busy_buffers_size 128k;
? ? proxy_temp_file_write_size 128k;
? ??
? ? gzip on;
? ? gzip_min_length 1k;
? ? gzip_buffers 4 16k;
? ? gzip_http_version 1.1;
? ? gzip_comp_level 2;
? ? gzip_types text/plain application/x-javascript text/css application/xml;
? ? gzip_vary ? on;
? ? 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;
? ? ? ? }
? ? }
? ? ??
upstream backend_server {
? ? ? ip_hash;?
? ? ? server ?192.168.1.10:80 max_fails=2 fail_timeout=30s;?
? ? ? server ?192.168.1.20:80 max_fails=2 fail_timeout=30s;
}?
server{?
? ? listen 80;?
? ? server_name www.abc.com;
? ? server_name abc.com;
? ? server_name testindex.abc.com;
? ? ?location / {?
? ? ? ? proxy_redirect off;
? ? ? ? #proxy_next_upstream http_502 http_504 error timeout invalid_header;
? ? ? ? proxy_set_header ? Host ? ? ? ? ? ? $host;?
? ? ? ? proxy_set_header ? X-Real-IP ? ? ? ?$remote_addr;?
? ? ? ? proxy_set_header ? X-Forwarded-For ?$proxy_add_x_forwarded_for;
? ? ? ? proxy_pass ? ? ? ? http://backend_server;?
? ? }?
}
upstream sqzone_api{
? ? ? ip_hash;?
? ? ? server ?192.168.0.10:80 max_fails=2 fail_timeout=30s;?
? ? ? server ?192.168.0.20:80 max_fails=2 fail_timeout=30s;
}?
??
server{?
? ? listen 80;?
? ? server_name sqZone.test.com;
? ? server_name sqapi.test.com;
? ? server_name sqapiby.test.com;
? ? server_name sqapiby1.test.com;
? ? server_name sqapitixing.test.com;
? ? server_name sqapitixingby.test.com;
? ? server_name sqapitixingby1.test.com;
? ? ?location / {
? ? ? ? proxy_redirect off;?
? ? ? ? proxy_set_header ? Host ? ? ? ? ? ? $host;?
? ? ? ? proxy_set_header ? X-Real-IP ? ? ? ?$remote_addr;?
? ? ? ? proxy_set_header ? X-Forwarded-For ?$proxy_add_x_forwarded_for;
? ? ? ? proxy_pass ? ? ? ? http://sqzone_api;?
? ? }?
}
}
轉載于:https://blog.51cto.com/250919938/1924859
總結
以上是生活随笔為你收集整理的CentOS 6 nginx(Tengine2.1.2)源码编译一键部署脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: topcoder srm 714 div
- 下一篇: 用eclipse修改web工程的访问路径