起因

最近想玩nginx了,本来用yum -y install nginx安装也启动好了,但是买了本《Nginx高性能Web服务器详解》,我咋能辜负我的书费呢?于是我就直接ps -ef |grep nginx kill -QUIT master的pid,然后yum -y remove nginx了。没错,就是这么帅。

经过

下载nginx

当然是去nginx(http://nginx.org/en/download.html)主页了,没错我现在安装的就是稳定版1.14.2了。

进入放置nginx的目录,我是/usr/local/tools/nginx

输入命令: wget http://nginx.org/download/nginx-1.14.2.tar.gz,这儿就等着吧。

解压

接下来解压targz包,你要是喜欢看动画呢,就输入 tar -zxvf nginx-1.14.2.tar.gz ,你要是不看呢就输入tar xf nginx-1.14.2.tar.gz

安装nginx

安装必要的工具:yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel open openssl-devel gd-devel perl-devel perl-ExtUtils-Embed .

接下来未来保证源文件和二进制文件不重复,我进行了一波骚操作: mv nginx-1.14.2 nginx-1.14.2-installer mkdir nginx-1.14.2。就是把源码文件夹重命名,新建了一个nginx按照目录,现在的源码在/usr/local/tools/nginx\nginx-1.14.2-installer,我要安装在/usr/local/tools/nginx/nginx-1.14.2目录里。

进入源码文件: cd nginx-1.14.2-installer,

编译文件:./configure --prefix=/usr/local/tools/nginx/nginx-1.14.2,注意这儿改成你的目录就行了,有两点你的注意。其一、你的nginx.lock位置是在/var/lock/nginx.lock;其二、只安装了标准模块;其三、用户不限制,任何人都能启动nginx

我的完整的配置选项是这样子的(如果你也是用的修改的配置,一定要把这个配置信息记下来,否则以后查错,该配置你会哭的。):/configure --prefix=安装目录 --sbin-path=sbin/nginx --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --error-log-path=logs/error.log --http-log-path=logs/access.log --lock-path=logs/lock/subsys/nginx --user=你要启动nginx的用户 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-ld-opt="-Wl,-E" --with-http_image_filter_module,--prefix是安装目录,一定要使用绝对路径;我把lock文件也放在了安装目录下的logs下;启用了几个基本模块

一定要注意这时候是不是报错了。

然后就是 make && make install

测试安装成功

进入安装目录:cd ../nginx-1.14.2,

执行启动: ./sbin/nginx,如果启动报错的话,看下错误信息,一般情况下是啥也没有。

查看服务: ps -ef |grep nginx

停止服务:kill -QUIT 7555,这个7555对应的是上图master process的进程编号,为了后续启动这儿一定要停了服务

查看服务: ps -ef |grep nginx

配置系统服务

配置系统服务:vim /etc/init.d/nginx

将下面这段复制进去(这是官网提供的加入系统服务脚本,链接 Red Hat NGINX Init Script ,找到nginx="/usr/local/tools/nginx/nginx-1.14.2/sbin/nginx" NGINX_CONF_FILE="/usr/local/tools/nginx/nginx-1.14.2/conf/nginx.conf"这两句改成你自己的目录):

  1. #!/bin/sh
  2. # nginx - this script starts and stops the nginx daemon
  3. #
  4. # chkconfig: - 85 15
  5. # description: NGINX is an HTTP(S) server, HTTP(S) reverse \
  6. # proxy and IMAP/POP3 proxy server
  7. # processname: nginx
  8. # config: /usr/local/tools/nginx/nginx-1.14.2/conf/nginx.conf
  9. # config: /etc/sysconfig/nginx
  10. # pidfile: /usr/local/tools/nginx/nginx-1.14.2/logs/nginx.pid
  11. # Source function library.
  12. . /etc/rc.d/init.d/functions
  13. # Source networking configuration.
  14. . /etc/sysconfig/network
  15. # Check that networking is up.
  16. [ "$NETWORKING" = "no" ] && exit 0
  17. nginx="/usr/local/tools/nginx/nginx-1.14.2/sbin/nginx"
  18. prog=$(basename $nginx)
  19. NGINX_CONF_FILE="/usr/local/tools/nginx/nginx-1.14.2/conf/nginx.conf"
  20. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  21. lockfile=/usr/local/tools/nginx/nginx-1.14.2/logs/lock/subsys/nginx
  22. make_dirs() {
  23. # make required directories
  24. user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
  25. if [ -n "$user" ]; then
  26. if [ -z "`grep $user /etc/passwd`" ]; then
  27. useradd -M -s /bin/nologin $user
  28. fi
  29. options=`$nginx -V 2>&1 | grep 'configure arguments:'`
  30. for opt in $options; do
  31. if [ `echo $opt | grep '.*-temp-path'` ]; then
  32. value=`echo $opt | cut -d "=" -f 2`
  33. if [ ! -d "$value" ]; then
  34. # echo "creating" $value
  35. mkdir -p $value && chown -R $user $value
  36. fi
  37. fi
  38. done
  39. fi
  40. }
  41. start() {
  42. [ -x $nginx ] || exit 5
  43. [ -f $NGINX_CONF_FILE ] || exit 6
  44. make_dirs
  45. echo -n $"Starting $prog: "
  46. daemon $nginx -c $NGINX_CONF_FILE
  47. retval=$?
  48. echo
  49. [ $retval -eq 0 ] && touch $lockfile
  50. return $retval
  51. }
  52. stop() {
  53. echo -n $"Stopping $prog: "
  54. killproc $prog -QUIT
  55. retval=$?
  56. echo
  57. [ $retval -eq 0 ] && rm -f $lockfile
  58. return $retval
  59. }
  60. restart() {
  61. configtest || return $?
  62. stop
  63. sleep 1
  64. start
  65. }
  66. reload() {
  67. configtest || return $?
  68. echo -n $"Reloading $prog: "
  69. killproc $nginx -HUP
  70. RETVAL=$?
  71. echo
  72. }
  73. force_reload() {
  74. restart
  75. }
  76. configtest() {
  77. $nginx -t -c $NGINX_CONF_FILE
  78. }
  79. rh_status() {
  80. status $prog
  81. }
  82. rh_status_q() {
  83. rh_status >/dev/null 2>&1
  84. }
  85. case "$1" in
  86. start)
  87. rh_status_q && exit 0
  88. $1
  89. ;;
  90. stop)
  91. rh_status_q || exit 0
  92. $1
  93. ;;
  94. restart|configtest)
  95. $1
  96. ;;
  97. reload)
  98. rh_status_q || exit 7
  99. $1
  100. ;;
  101. force-reload)
  102. force_reload
  103. ;;
  104. status)
  105. rh_status
  106. ;;
  107. condrestart|try-restart)
  108. rh_status_q || exit 0
  109. ;;
  110. *)
  111. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  112. exit 2
  113. esac

配置启动脚本权限:chmod a+x /etc/init.d/nginx

启动nginx: /etc/init.d/nginx start

停止nginx: /etc/init.d/nginx stop

加入系统服务:chkconfig --add /etc/init.d/nginx

使用systemctl启动nginx: systemctl start nginx

使用systemctl停止nginx: systemctl stop nginx

开机启动

配置开机启动:vi /etc/rc.local在最后加一句/etc/init.d/nginx start

结尾

打完收功!

CentOS7.3编译安装Nginx设置开机启动的更多相关文章

  1. Windows 安装nginx并开机启动

    Win安装nginx并 开机启动 下载nginx安装包 nginx-1.12.2.zip,解压到D盘. https://pan.baidu.com/s/1InQa527yq35Q68c73RBb-A# ...

  2. CentOS7 nginx 最简单的安装以及设置开机启动

    1. 下载tar包. 2. 解压缩tar包 3. 安装必须的部分 yum包 yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd ...

  3. CentOS7.6编译安装nginx

    配置阿里云yum源 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak wget -O /etc/yu ...

  4. docker安装并设置开机启动(CentOS7/8)

    CentOS7.2 docker分为CE和EE版本,EE版本收费,一般我们使用CE版本就满足要求了 docker安装及启动 docker安装很简单,直接使用如下命令安装即可,安装后的docker版本即 ...

  5. centos7安装redis设置开机启动

    1. 首先下载redis源码,并使用tar进行解压缩 wget http://download.redis.io/releases/redis-4.0.8.tar.gztar xvzf redis-4 ...

  6. CentOs7.2编译安装Nginx服务器

    1. 安装nginx依赖 首先安装nginx的依赖 yum install gcc gcc-c++ openssl openssl-devel cyrus-sasl-md5 2,创建nginx用户 如 ...

  7. yum 安装nginx(配置开机启动)

    yum install -y nginx 通过yum安装的时候提示下面的错误 [root@localhost yum.repos.d]# yum install nginx 已加载插件:fastest ...

  8. docker安装并设置开机启动(Linux)

    docker 开机启动: systemctl enable docker 使用的linux系统为CentOS7.2 docker分为CE和EE版本,EE版本收费,一般我们使用CE版本就满足要求了 do ...

  9. linux下安装nginx后开机启动篇

    众所周知nginx安装后需要手动去启动,每次开机之后都要执行nginx的启动命令很蛋疼.那么我们来让nginx开机启动吧 1.先創建一個nginx文件把 [root@localhost ~]# vi ...

随机推荐

  1. maven release插件将一版本发布到仓库中时Return code is: 401, ReasonPhrase:Unauthorized

    需要在maven的setting.xml中配置servers.server节点,其值为nexus的对应的repository的id以及用户名及密码 <servers> <server ...

  2. linux 批量修改文件名 文件名只保留部分,去掉部分

    问题:linux系统中文件名包含中文,导致页面访问不了文件.就是上条博客中的解决方法二遗留问题. 文件名中有以下格式:TC2_诺而达铜管(中山)有限公司.pdf ,要改为TC2.pdf,去掉中文部分 ...

  3. jQuery的ready与js的load事件的区别

    摘自:http://www.cnblogs.com/see7di/archive/2011/07/15/2239677.html 为了理解这两个事件的异同,读者应该先了解HTML文档加载的顺序. DO ...

  4. wamp下mysql错误提示乱码的解法

    出处:http://blog.csdn.net/jsship/article/details/42914217 运行mysql命令时,出现的错误提示是乱码 :    [Err] 1064 - Erre ...

  5. Python之基础练习题

    Python之基础练习题 1.执行 Python 脚本的两种方式 2.简述位.字节的关系 解:8位是一个字节 3.简述 ascii.unicode.utf-8.gbk 的关系 4.请写出 “李杰” 分 ...

  6. Python之FTP实现

    Python之FTP实现 上传下载: import socket import struct import json import subprocess import os class MYTCPSe ...

  7. python爬取百度文库所有内容

    转载自 GitHub 的 Jack-Cherish 大神 基本环境配置 版本:python3 系统:Windows 相关模块: import requests import re import jso ...

  8. [bzoj1208][HNOI2004][宠物收养所] (平衡树)

    Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物.每个领养者都希望领养到自己满意的宠物,阿Q根据领养者的要求通过他自己发明的一个特 ...

  9. [bzoj3668][Noi2014][起床困难综合症] (按位贪心)

    Description 21 世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm 一直坚持与起床困难综合症作斗争.通过研究相关文献,他找 ...

  10. IDEA常用插件记录

    让我们来记录一下常用的IDEA插件:(从其他博客中取了许多图片,出处见图片水印) 1.JRebel for IntelliJ 热部署神器2.Free MyBatis plugin 实现dao层方法与x ...