RHEL5 利用 CentOS的yum 安装openssl gc++及Nginx

来源:互联网 发布:宾馆 网络布线收费 编辑:程序博客网 时间:2024/04/30 10:03

1.确保RHEL5中已经安装了yum
[root@xupo~]# rpm -qa |grep yum
2.修改源配置文件 #vim /etc/yum.repos.d/CentOS-Base.repo

Config代码 复制代码
  1. [base]   
  2. name=CentOS-5-Base   
  3. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever5&arch=$basearch&repo=os   
  4. #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/   
  5. baseurl=http://ftp.sjtu.edu.cn/centos/5/os/$basearch/   
  6. gpgcheck=1  
  7. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5   
  8.   
  9. #released updates   
  10. [update]   
  11. name=CentOS-5-Updates   
  12. #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=updates   
  13. baseurl=http://ftp.sjtu.edu.cn/centos/5/updates/$basearch/   
  14. gpgcheck=1  
  15. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5   
  16.   
  17. #packages used/produced in the build but not released   
  18. [addons]   
  19. name=CentOS-5-Addons   
  20. #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=addons   
  21.   
  22. baseurl=http://ftp.sjtu.edu.cn/centos/5/addons/$basearch/   
  23. gpgcheck=1  
  24. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5   
  25.   
  26. #additional packages that may be useful   
  27. [extras]   
  28. name=CentOS-5-Extras   
  29. #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=extras   
  30.   
  31. baseurl=http://ftp.sjtu.edu.cn/centos/5/extras/$basearch/   
  32. gpgcheck=1  
  33. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5   
  34.   
  35. #additional packages that extend functionality of existing packages   
  36. [centosplus]   
  37. name=CentOS-5-Plus   
  38. #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=centosplus   
  39. baseurl=http://ftp.sjtu.edu.cn/centos/5/centosplus/$basearch/   
  40. gpgcheck=1  
  41. enabled=0  
  42. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5   
  43.   
  44. #contrib - packages by Centos Users   
  45. [contrib]   
  46. name=CentOS-5-Contrib   
  47. #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=contrib   
  48. baseurl=http://ftp.sjtu.edu.cn/centos/5/contrib/$basearch/   
  49. gpgcheck=1  
  50. enabled=0  
  51. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5   
  52.   
  53. # vi dag.repo   
  54. [dag]   
  55. name=Dag RPM Repository for RHEL5   
  56. baseurl=http://ftp.riken.jp/Linux/dag/redhat/el5/en/$basearch/dag/   
  57. enabled=1  
  58. gpgcheck=1  
  59. gpgkey=http://ftp.riken.jp/Linux/dag/packages/RPM-GPG-KEY.dag.txt  

 
3. 导入key
 #rpm --import http://ftp.sjtu.edu.cn/centos/5/os/x86_64/RPM-GPG-KEY-CentOS-5
  #rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
注:这是两个key,导入一个就行了。

4. 运行,测试
 #yum update

5.#yum clean all

若以上方法不可行,可以尝试下面的:

修改源配置文件 #vim /etc/yum.repos.d/rhel-debuginfo.repo

Config代码 复制代码
  1. [rhel-debuginfo]   
  2. name=Red Hat Enterprise Linux $releasever - $basearch - Debug   
  3. baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/   
  4. enabled=0  
  5. gpgcheck=1  
  6. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release   
  7. [rhel-debuginfo-beta]   
  8. name=Red Hat Enterprise Linux $releasever Beta - $basearch - Debug   
  9. baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/$basearch/Debuginfo/   
  10. enabled=0  
  11. gpgcheck=1  
  12. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release   
  13.   
  14. [base]   
  15. name=Red Hat Enterprise Linux $releasever -Base   
  16. baseurl=http://ftp.twaren.net/Linux/CentOS/5/os/$basearch/   
  17. gpgcheck=1  
  18. gpgkey=http://ftp.twaren.net/Linux/CentOS/RPM-GPG-KEY-CentOS-5  
  19. [update]   
  20. name=Red Hat Enterprise Linux $releasever -Updates   
  21. baseurl=http://ftp.twaren.net/Linux/CentOS/5/updates/$basearch/   
  22. gpgcheck=1  
  23. gpgkey=http://ftp.twaren.net/Linux/CentOS/RPM-GPG-KEY-CentOS-5  
  24. [extras]   
  25. name=Red Hat Enterprise Linux $releasever -Extras   
  26. baseurl=http://ftp.twaren.net/Linux/CentOS/5/extras/$basearch/   
  27. gpgcheck=1  
  28. gpgkey=http://ftp.twaren.net/Linux/CentOS/RPM-GPG-KEY-CentOS-5  
  29. [addons]   
  30. name=Red Hat Enterprise Linux $releasever -Addons   
  31. baseurl=http://ftp.twaren.net/Linux/CentOS/5/addons/$basearch/   
  32. gpgcheck=1    
  33. gpgkey=http://ftp.twaren.net/Linux/CentOS/RPM-GPG-KEY-CentOS-5  

 
然后
#yum update
#yum clean all

 

 

开始安装gc++(注意,在安装nginx的依赖pcre时出现./libtool: line 990: g++: command not found错误时,往往是由于少了此包造成的)

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

 

开始安装openssl :

#yum install openssl  (很快你就发现openssl实际上是不需要安装的)

 

 

 

 

 

下面开始安装nginx

 

安装pcre
[root@localhost soft]#tar -zxvf pcre-8.01.tar.gz
[root@localhost soft]#cd pcre-8.01
[root@localhost pcre-8.01]#./configure
[root@localhost pcre-8.01]#make && make install
[root@localhost pcre-8.01]#cd ..
[root@localhost soft]#

 

安装nginx
[root@localhost soft]#tar -zxvf nginx-0.8.49.tar.gz
[root@localhost soft]#cd nginx-0.8.49
[root@localhost nginx-0.8.49]#./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --with-openssl=/usr/lib/openssl/(其实openssl路径应该填gz包解压后的地址,见附)
如果出现如下错误:

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using –without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using –with-zlib=<path> option.

[root@rhel nginx-1.0.5]# yum install -y zlib-devel

 


[root@localhost nginx-0.8.49]#make
[root@localhost nginx-0.8.49]#make install
[root@localhost nginx-0.8.49]#useradd nginx   //编译时指定了默认用户和组为nginx,所以还要创建一下。

[root@localhost nginx-0.8.49]# cd /usr/sbin
[root@localhost sbin]# nginx   //现在你访问就可以看到“welcome to nginx”的页面了

 

如果启动出错:nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
则需要创建这个目录

 mkdir /var/tmp/nginx
mkdir /var/tmp/nginx/client

如果说用户无法运行,则

vim /etc/nginx/nginx.conf

将#user nobody

改成user nobody

 

这里的nginx是通过下载gz包,解压后安装完成的,如果用yum安装nginx包,有文章介绍如下:

 

Nginx (pronounced “Engine X”) is a lightweight web server that offers speed and flexibility without all of the extra features that larger web servers like Apache offer. Although it is a free and open source application, CentOS does not offer the latest version in its default YUM repository. To install it, you need to add the EPEL (Extra Packages for Enterprise Linux) repository, which is part of the Fedora Project.

1. Install the EPEL repository:

# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-3.noarch.rpm(URL已失效)

2. Install nginx

# yum install nginx

3. You will be asked to install the gpg-key for EPEL. Answer yes

4. Start Nginx

# /etc/init.d/nginx start

5. Check the installation by going to your web server’s default site, either using your ip address or domain name.

 

 

附:常见问题

 

Note代码 复制代码
  1. 1.注意:OPENSSL不需要安装,只需要解压出来就行。不然在编译时会提示类似以下的错误:   
  2.   
  3. make[1]: Entering directory `/root/nginx-0.7.65'   
  4. cd /server/openssl \   
  5.         && make clean \   
  6.         && ./config --prefix=/server/openssl/openssl no-shared no-threads \   
  7.         && make \   
  8.         && make install   
  9. make[2]: Entering directory `/server/openssl'   
  10. make[2]: *** No rule to make target `clean'. Stop.   
  11. make[2]: Leaving directory `/server/openssl'   
  12. make[1]: *** [/server/openssl/openssl/include/openssl/ssl.h] Error 2  
  13. make[1]: Leaving directory `/root/nginx-0.7.65'   
  14. make: *** [build] Error 2  
  15.   
  16.   
  17. 2.安装Nginx的时候,把openssl路径指定到解压出来的路径:   
  18.   
  19. ./configure --with-http_stub_status_module --with-http_ssl_module --with-openssl=/root/openssl-1.0.0 --with-http_gzip_static_module --with-http_stub_status_module --prefix=/usr/local/nginx   
  20.   
  21. 如果是64位服务器的需要vi /usr/local/nginx-0.7.65/objs/Makefile   
  22.   
  23. -lcrypt /usr/local/openssl-1.0.0/.openssl/lib64/libssl.a /usr/local/openssl-1.0.0/.openssl/lib64/libcrypto.a -ldl -lz   
  24.   
  25. 之后make是一个漫长的等待时间   
  26.   
  27. make install   
  28.   
  29. 3、生成RSA密钥的方法   
  30.   
  31. openssl genrsa -des3 -out privkey.pem 2048  
  32. 这个命令会生成一个2048位的密钥,同时有一个des3方法加密的密码,如果你不想要每次都输入密码,可以改成:   
  33. openssl genrsa -out privkey.pem 2048  
  34. 建议用2048位密钥,少于此可能会不安全或很快将不安全。   
  35.   
  36. 4、生成一个证书请求   
  37. openssl req -new -key privkey.pem -out cert.csr   
  38. 这个命令将会生成一个证书请求,当然,用到了前面生成的密钥privkey.pem文件   
  39. 这里将生成一个新的文件cert.csr,即一个证书请求文件,你可以拿着这个文件去数字证书颁发机构(即CA)申请一个数字证书。CA会给你一个新的文件cacert.pem,那才是你的数字证书。   
  40.   
  41. 如果是自己做测试,那么证书的申请机构和颁发机构都是自己。就可以用下面这个命令来生成证书:   
  42. openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095  
  43. 这个命令将用上面生成的密钥privkey.pem生成一个数字证书cacert.pem   
  44.   
  45. 5.Nginx配置中,需要修改的地方:   
  46.   
  47. server {   
  48.         listen       443;   
  49.         server_name localhost;   
  50.   
  51.         ssl                  on;   
  52.     ssl_certificate /usr/local/nginx/conf/cacert.pem;   
  53.     ssl_certificate_key /usr/local/nginx/conf/privkey.pem;   
  54.     server_name 192.168.10.70  
  55. ssl_session_timeout 5m;   
  56. }   
  57.   
  58. 6.在iptables中打开ssl使用到的443端口,重启iptables.   
  59.   
  60. 7.测试。访问时,发现有提示需要证书,应该成功了。  
Note代码 复制代码
  1. nginx   //启动时会报错:[emerg]: mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)   
  2. mkdir -p /var/tmp/nginx/client  

 

 

 

nginx启动,重启,关闭命令

 

 

停止操作
停止操作是通过向nginx进程发送信号(什么是信号请参阅linux文 章)来进行的
步骤1:查询nginx主进程号
ps -ef | grep nginx
在进程列表里 面找master进程,它的编号就是主进程号了。
步骤2:发送信号
从容停止Nginx:
kill -QUIT 主进程号
快速停止Nginx:
kill -TERM 主进程号
强制停止Nginx:
pkill -9 nginx

另外, 若在nginx.conf配置了pid文件存放路径则该文件存放的就是Nginx主进程号,如果没指定则放在nginx的logs目录下。有了pid文 件,我们就不用先查询Nginx的主进程号,而直接向Nginx发送信号了,命令如下:
kill -信号类型 '/usr/nginx/logs/nginx.pid'

平滑重启
如果更改了配置就要重启Nginx,要先关闭Nginx再打开?不是的,可以向Nginx 发送信号,平滑重启。
平滑重启命令:
kill -HUP 住进称号或进程号文件路径

或者使用

/usr/nginx/sbin/nginx -s reload


注意,修改了配置文件后最好先检查一下修改过的配置文件是否正 确,以免重启后Nginx出现错误影响服务器稳定运行。判断Nginx配置是否正确命令如下:
nginx -t -c /usr/nginx/conf/nginx.conf

或者

/usr/nginx/sbin/nginx -t

平滑升级
如果服务器正在运行的Nginx要进行升级、添加或删除模块时,我们需 要停掉服务器并做相应修改,这样服务器就要在一段时间内停止服务,Nginx可以在不停机的情况下进行各种升级动作而不影响服务器运行。
步骤1:
如 果升级Nginx程序,先用新程序替换旧程序文件,编译安装的话新程序直接编译到Nginx安装目录中。
步 骤2:执行命令
kill -USR2 旧版程序的主进程号或进程文件名
此时旧的Nginx主进程将会把自己的进程文件改名为.oldbin,然后执行新版 Nginx。新旧Nginx会同市运行,共同处理请求。
这时要逐步停止旧版 Nginx,输入命令:
kill -WINCH 旧版主进程号
慢慢旧的工作进程就都会随着任务执行完毕而退出,新版的Nginx的工作进程会逐渐取代旧版 工作进程。

此 时,我们可以决定使用新版还是恢复到旧版。
不重载配置启动新/旧工作进程
kill -HUP 旧/新版主进程号
从容关闭旧/新进程
kill -QUIT 旧/新主进程号
如果此时报错,提示还有进程没有结束就用下面命令先关闭旧/新工作进程,再关闭主进程号:
kill -TERM 旧/新工作进程号

这样下来,如果要恢复到旧版本,只需要上面的几个步 骤都是操作新版主进程号,如果要用新版本就上面的几个步骤都操作旧版主进程号就行了。

上面就是Nginx的一些基本的操作,希望以后Nginx能有更好的方法来处理这些操作, 最好是Nginx的命令而不是向Nginx进程发送系统信号。

原创粉丝点击