Centos 6.5 Install haproxy-nginx
来源:互联网 发布:现代优化设计方法举例 编辑:程序博客网 时间:2024/05/10 21:36
yum install zlib pcre pcre-devel openssl openssl-devel -y
yum install gcc -y
yum install gcc-c++ -y
创建nginx用户
useradd -s /sbin/nologin nginx
下载nginx
wget http://nginx.org/download/nginx-1.10.0.tar.gz
解压nginx
tar -zxvf nginx-1.10.0.tar.gz
cd / nginx-1.10.0
./configure \
--user=nginx \
--group=nginx \
--prefix=/opt/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/tmp/nginx/client_body \
--http-proxy-temp-path=/tmp/nginx/proxy \
--http-fastcgi-temp-path=/tmp/nginx/fastcgi \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/subsys/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre \
--with-http_realip_module \
--with-http_sub_module
make
make install
#########################################################################################
Nginx 编译参数
--user 指定启动程序所属用户
--group 指定组
--prefix 指定安装路径
--sbin-path 设置nginx二进制文件的路径名
--conf-path 指定配置文件路径
--error-log-path 错误日志文件路径
--http-log-path 指定访问日志文件路径
--http-client-body-temp-path 设置存储HTTP客户端请求主体的临时文件路径
--http-proxy-temp-path 设置存储HTTP代理临时文件的路径
--http-fastcgi-temp-path 设置存储HTTP fastcgi的临时文件的路径
--pid-path 设置nginx.pid文件路径
--lock-path 设置nginx.lock文件路径
--with-openssl 启用SSL
--with-pcre 启用正则表达式
--with-http_stub_status_module 安装可以监控nginx状态的模块
--with-http_ssl_module 启用SSL支持
--with-http_gzip_static_module 启用gzip压缩
#########################################################################################
nginx端口状态
netstat -ntlp | grep nginx
控制nginx服务的命令
1、启动:nginx
2、停止:nginx -s stop
3、退出:nginx -s quit
4、重启:nginx -s reopen
5、重新加载:nginx -s reload
6、平滑启动:kill -HUP pid(kill -HUP `cat /var/run/nginx.pid`)
创建nginx自启动脚本
vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 18 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/sbin/nginx"
NGINX_CONF="/etc/nginx/nginx.conf"
NGINX_PID="/var/run/nginx.pid"
RETVAL=0
prog="Nginx"
#Source networking configuration
. /etc/sysconfig/network
# Check networking is up
[ ${NETWORKING} = "no" ] && exit 0
[ -x $NGINX_SBIN ] || exit 0
start() {
echo -n $"Starting $prog: "
touch /var/lock/subsys/nginx
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /var/lock/subsys/nginx /var/run/nginx.pid
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
创建这个目录不然报错,无法启动服务
mkdir -p /tmp/nginx/client_body
赋予nginx脚本权限
chmod -R 777 /etc/init.d/nginx
设置nginx开机启动
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
service nginx stop
防火墙设置通过nginx
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
查看nginx版本
nginx -v
测试nginx访问
在浏览器输入http://Your-IP/
配置代理
cd /etc/nginx/
vi nginx.conf
upstream lottery {
server 10.11.12.143:8080;
server 10.11.12.139:8080;
}
location / {
root /var/www/benet;
index index.html index.htm;
proxy_pass http://tomcat;
}
下载haproxy
cd /usr/local/
wget http://www.haproxy.org/download/1.6/src/haproxy-1.6.9.tar.gz
解压haproxy
tar zxvf haproxy-1.6.9.tar.gz
mv haproxy-1.6.9 haproxy
cd haproxy
查看系统版本号
uname -a
编译安装
make TARGET=linux26 prefix=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
配置系统服务
cd /etc/init.d/
创建启动脚本
vim haproxy
#!/bin/bash
### BEGIN INIT INFO
#Manage the HAProxy
### END INIT INFO
#chkconfig: 2345 10 90
#description:haproxy
bin=/usr/local/haproxy/sbin/haproxy
config=/usr/local/haproxy/conf/haproxy.cfg
pid=/usr/local/haproxy/var/run/haproxy.pid
opts=" -f ${config} -p ${pid} -D -V "
sleep_time=1
start() {
echo -e "Starting HAProxy......"
${bin} ${opts}
if [ "$?" != "0" ] ; then
sleep ${sleep_time}
echo " failed"
exit 1
else
sleep ${sleep_time}
echo " done"
fi
}
stop() {
if [ ! -e ${pid} ] ; then
echo -e "HAProxy is not running"
exit 0
fi
echo -e "Shutting down HAProxy......"
kill $(cat ${pid})
if [ -e ${pid} ] ; then
rm -f ${pid}
fi
if [ "$?" != "0" ] ; then
sleep ${sleep_time}
echo " failed"
exit 1
else
sleep ${sleep_time}
echo " done"
fi
}
reload(){
${bin} -f ${config} -st $(cat ${pid})
echo -e "HAProxy is reload......"
}
checkconfig(){
${bin} -c -f ${config}
echo -e "haproxy file is ok"
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
checkconfig)
checkconfig
;;
*)
echo "Usage: $0 {start|stop|restart|reload|checkconfig}"
exit 1
;;
esac
赋予权限
chmod -R 777 /etc/init.d/haproxy
设置开机启动
chkconfig haproxy on
查看服务状态
netstat -anplt | grep haproxy
查看服务状态及目录结构
ps -ef |grep haproxy |grep -v grep
- Centos 6.5 Install haproxy-nginx
- centos install nginx
- Centos Install Nginx PHP
- install nginx in centos
- install nginx in centos
- centos 6 install nginx php
- centos install nginx mysql php
- CentOS 6.5上部署Haproxy
- CentOS直接yum install nginx 办法
- centos 6.5 install redis
- Centos 6.5 Install MariaDB
- Centos 6.5 Install Vim
- Centos 6.5 Install KVM
- Centos 6.5 Install icingaweb2
- Centos 6.5 Install Xrdp
- Centos 6.5 Install JDK7
- Centos 6.5 Install Telnet
- Centos 6.5 Install SCP
- Access-Control-Allow-Origin与Ajax跨域
- 算法总结(3)--k-Sum求和,找到和为定值的多个数
- 4- noip交流赛 DAY2
- 数据库连接池的选择 Druid
- python 的pandas DataFrame大全
- Centos 6.5 Install haproxy-nginx
- 1002. switch text
- jquery获取标签名称:prop('tagName')
- HDU 5527 Too Rich(dfs贪心)
- JAVA从菜鸟【入门】到新手【实习】一一潮流:大数据算法(“技术储备”)
- 【LeetCode】10. Regular Expression Matching
- 软件测试人员分工
- Python学习笔记(四)-- 函数中的参数传递
- 怎样对CorelDRAW 中轮廓和填充进行默认设置