您的当前位置:首页nginx+keepalived安装

nginx+keepalived安装

来源:小侦探旅游网


nginx+keepalived安装

1. 准备安装包

pcre-8.32.zip

zlib-1.2.7.tar.gz

openssl-1.0.0e.tar.gz

nginx-1.5.8.tar.gz

keepalived-1.2.8.tar.gz

将安装包统一放在/usr/local目录下面:

#mv ./pcre-8.32.zip /usr/local

2. 安装pcre库

cd /usr/local

[root@localhost local]# unzip pcre-8.32.zip

[root@localhost local]# cd pcre-8.32

[root@localhost pcre-8.32]# ./configure

[root@localhost pcre-8.32]# make

[root@localhost pcre-8.32]# make install

#上述操作无报错,此时pcre库安装完成;

3. 安装zlib库

[root@localhost pcre-8.32]# cd /usr/local/

[root@localhost local]# tar -zxvf zlib-1.2.7.tar.gz

[root@localhost local]# cd zlib-1.2.7

[root@localhost zlib-1.2.7]# ./configure

[root@localhost zlib-1.2.7]# make

[root@localhost zlib-1.2.7]# make install

#上述操作无报错,此时zlib库安装完成;

4. 安装openssl

[root@localhost zlib-1.2.7]# cd /usr/local/

[root@localhost local]# tar -zxvf openssl-1.0.0e.tar.gz

[root@localhost local]# cd openssl-1.0.0e ./config -fPIC

[root@localhost openssl-1.0.0e]# ./config

[root@localhost openssl-1.0.0e]# make

[root@localhost openssl-1.0.0e]# make install

#上述操作无报错,此时openssl安装完成;

5. 安装nginx

yum install gcc yum install -y gcc gcc-c++

[root@localhost openssl-1.0.0e]# cd /usr/local/

[root@localhost local]# tar -zxvf nginx-1.5.8.tar.gz

[root@localhost local]# cd nginx-1.5.8

[root@localhost nginx-1.5.8]# ./configure --prefix=/usr/local/nginx --with-openssl=/usr/include --with-http_stub_status_module

ssl版本:

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-openssl=/usr/local/openssl-1.0.0e --with-http_ssl_module

[root@localhost local]#make

[root@localhost nginx-1.5.8]# make install

#上述操作无报错,此时nginx安装完成;

更多的安装配置:

./configure --prefix=/usr/local/nginx

--with-openssl=/usr/include (启用ssl)

--with-pcre=/usr/include/pcre/ (启用正规表达式)

--with-http_stub_status_module (安装可以查看nginx状态的程序)

--with-http_memcached_module (启用memcache缓存)

--with-http_rewrite_module (启用支持url重写)

6. Nginx的启动和关闭以及常用功能

启动nginx服务:

[root@localhost ~]# /usr/local/nginx/sbin/nginx

查看nginx运行状态:

[root@localhost ~]# ps -ef|grep nginx

root 639 1 0 17:44 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody 641 639 0 17:44 ? 00:00:00 nginx: worker process

root 644 14248 0 17:44 pts/3 00:00:00 grep nginx

看到如上内容说明nginx正在运行;

关闭nginx:

[root@localhost ~]# killall -9 nginx

重启nginx:kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

确认Nginx配置文件的语法是正确的,可通过如下命令测试配置文件是否正确:

/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

看到如下内容说明nginx的配置是正确的

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

如果nginx启动报错:

/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

添加软连接:

ln -s /usr/local/lib/libpcre.so.1 /lib64/

7. Keepalived安装

[root@localhost local]# tar -zxvf keepalived-1.2.8.tar.gz

[root@localhost local]# cd keepalived-1.2.8

[root@localhost keepalived-1.2.8]# ./configure --prefix=/usr/local/keepalived && make && make install

[root@localhost keepalived-1.2.8]# cp

/usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

[root@localhost keepalived-1.2.8]# cp

/usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/

[root@localhost keepalived-1.2.8]# mkdir /etc/keepalived

[root@localhost keepalived-1.2.8]# cp

/usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

[root@localhost keepalived-1.2.8]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

[root@localhost ~]# service keepalived status 可以看到keepalived已经是系统服务

keepalived is stopped

[root@localhost ~]# service keepalived start 开始keepalived

[root@localhost ~]# chkconfig --level 345 keepalived on 加入开机服务

1、如果./configure时报:

checking openssl/ssl.h usability... no

checking openssl/ssl.h presence... no

checking for openssl/ssl.h... no

configure: error:

!!! OpenSSL is not properly installed on your system. !!!

!!! Can not include OpenSSL headers files.

解决:

yum install -y openssl openssl-devel

如果是离线安装,请手工上传以下包,并保证以下包齐全:

keyutils-libs、keyutils-libs-devel、libsepol-devel、libselinux、

libselinux-devel、 krb5-libs、 krb5-devel 、libcom_err、libcom_err-devel、zlib-devel、openssl、 openssl-devel

2、如果./configure时报:

checking for poptGetContext in -lpopt... no

configure: error: Popt libraries is required

解决:

未安装popt的开发包:yum -y install popt-devel

因篇幅问题不能全部显示,请点此查看更多更全内容