本文主要介绍ubuntu如何编译安装nginx以及遇到的问题 和 配置系统自动启动服务

查看操作系统版本
cat /etc/issue 
Ubuntu 18.04.3 LTS \n \l 
 
更改镜像源步骤:
1. 首先做一个备份,这是个好习惯,修改配置文件前先备份,以便于事后可以恢复
sudo su  进入root用户安装
cd /etc/apt
mv sources.list sources.list.bak
touch sources.list
chmod 777 sources.list
vim sources.list
2. 中科大最新镜像源配置内容复制写入

deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
## Not recommended
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

3.更新镜像源
apt update
4.更新软件
apt list --upgradable
 
安装nginx大概需要如下依赖库 gcc  pcre  zlib openssl libssl-dev libperl-dev zlib等依赖,安装过程中或许会出现报错,需要什么依赖安装什么依赖。
apt install tar
apt install gcc
apt install libpcre3 libpcre3-dev
apt install openssl libssl-dev libperl-dev
apt install zlib1g zlib1g-dev

下载安装nginx步骤

1.下载nginx稳定版本,并安装。如下:

wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1

执行:
./configure

执行:

make

最后执行:

make install

就安装好了!

此处整理安装nginx过程中nginx所需要的类库没有安装出现的报错:

./configure
报错:
checking for OS
+ Linux 5.0.0-32-generic x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
执行:apt install gcc
./configure
报错:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
执行
apt install libpcre3 libpcre3-dev
出错:镜像源中没有找到 pcre-devel 库
root@ubuntu:~/nginx-1.16.1# apt install pcre-devel
Reading package lists... Done
Building dependency tree 
Reading state information... Done
E: Unable to locate package pcre-devel
./configure
出错
ubuntu error: the HTTP rewrite module requires the PCRE library.
apt install libpcre3 libpcre3-dev
./configure
出错:
./configure: error: the HTTP gzip module requires the zlib library.
apt install libssl-dev libperl-dev
./configure: error: the HTTP gzip module requires the zlib library.
apt install zlib1g zlib1g-dev
./configure
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
make
make install

接下来配置nginx的自动启动管理服务

配置之前先啰嗦几句对ubuntu系统的应有的了解:

Ubuntu 16.10开始不再使用initd管理系统,改用systemd,包括用systemctl命令来替换了service和chkconfig的功能。

比如以前启动mysql服务用sudo service mysql start,现在用sudo systemctl start mysqld.service。

systemd 默认读取 /etc/systemd/system 下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件。

1.建立服务文件
vim lib/systemd/system/nginx.service

复制如下内容写入到nginx.service中
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target

[Unit]:服务的说明
Description:描述服务
After:依赖,当依赖的服务启动之后再启动自定义的服务

[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令(需要根据路径适配)
ExecReload为重启命令(需要根据路径适配)
ExecStop为停止命令(需要根据路径适配)
PrivateTmp=True表示给服务分配独立的临时空间
注意:启动、重启、停止命令全部要求使用绝对路径

[Install]服务安装的相关设置,可设置为多用户

Type
Type=simple(默认值):systemd认为该服务将立即启动。服务进程不会fork。如果该服务要启动其他服务,不要使用此类型启动,除非该服务是socket激活型。
Type=forking:systemd认为当该服务进程fork,且父进程退出后服务启动成功。对于常规的守护进程(daemon),除非你确定此启动方式无法满足需求,使用此类型启动即可。使用此启动类型应同时指定 PIDFile=,以便systemd能够跟踪服务的主进程。
Type=oneshot:这一选项适用于只执行一项任务、随后立即退出的服务。可能需要同时设置 RemainAfterExit=yes使得systemd在服务进程退出之后仍然认为服务处于激活状态
Type=notify:与 Type=simple相同,但约定服务会在就绪后向systemd发送一个信号。这一通知的实现由 libsystemd-daemon.so提供。
Type=dbus:若以此方式启动,当指定的 BusName 出现在DBus系统总线上时,systemd认为服务就绪。
PIDFile : pid文件路径
ExecStartPre :启动前要做什么,上文中是测试配置文件 -t
2.保存目录
/usr/lib/systemd/system
3.设置开机自启动
systemctl enable nginx.service //任意目录下执行
4.使用命令

systemctl start nginx.service      //启动nginx服务
systemctl enable nginx.service   //设置开机自动启动
systemctl disable nginx.service  //停止开机自动启动
systemctl status nginx.service   //查看状态
systemctl restart nginx.service  //重启服务
systemctl list-units --type=service  //查看所有服务

Ubuntu编译安装nginx以及配置自动启动的更多相关文章

  1. Ubuntu编译安装nginx,php,mysql

    摘要: 整理的Ubuntu编译安装nginx,php,mysql的步骤,主要来自对驻云的sh-1.4.1中脚本的整理,随时代进步,内容中的软件或者命令请自行更新 目录准备 创建用户 userdel w ...

  2. Ubuntu 编译安装 nginx

    有关博客: <Windows 编译安装 nginx 服务器 + rtmp 模块>.<Ubuntu 编译安装 nginx>.<Arm-Linux 移植 Nginx> ...

  3. 【转】linux 编译安装nginx,配置自启动脚本

    linux 编译安装nginx,配置自启动脚本 本文章来给各位同学介绍一篇关于linux 编译安装nginx,配置自启动脚本教程,希望有需要了解的朋友可一起来学习学习哦. 在公司的suse服务器装ng ...

  4. linux 编译安装nginx,配置自启动脚本

    本文章来给各位同学介绍一篇关于linux 编译安装nginx,配置自启动脚本教程,希望有需要了解的朋友可一起来学习学习哦. 在公司的suse服务器装nginx,记录下安装过程: 参照这篇文章:Linu ...

  5. 编译安装nginx时配置开机自启

    详细编译安装nginx请参考[Nginx目录结构与配置文件详解]以及[Nginx安装部署],在这里就进行简单安装 安装Nginx 环境介绍 操作系统: [root@localhost ~]# cat ...

  6. CentOS 7 安装Nginx 并配置自动启动

    1.官网下载安装包 http://nginx.org/en/download.html,选择适合Linux的版本,这里选择最新的版本,下载到本地后上传到服务器或者centos下直接wget命令下载. ...

  7. ubuntu编译安装nginx

    下载nginx源码, ./configure --prefix=/usr/local/nginx/1.8 --with-http_ssl_module --with-http_dav_module - ...

  8. Windows 编译安装 nginx 服务器 + rtmp 模块

    有关博客: <Windows 编译安装 nginx 服务器 + rtmp 模块>.<Ubuntu 编译安装 nginx>.<Arm-Linux 移植 Nginx> ...

  9. ubuntu 12.04 编译安装 nginx

    下载源码包 nginx 地址:http://nginx.org/en/download.html 编译前先安装两个包: 直接编译安装会碰到缺少pcre等问题,这时候只要到再安装两个包就ok sudo ...

随机推荐

  1. CVPR 2019 论文解读 | 小样本域适应的目标检测

    引文 ​ 最近笔者也在寻找目标检测的其他方向,一般可以继续挖掘的方向是从目标检测的数据入手,困难样本的目标检测,如检测物体被遮挡,极小人脸检测,亦或者数据样本不足的算法.这里笔者介绍一篇小样本(few ...

  2. 基于C#的机器学习--机器学习建模的基础

    构建ML模型的步骤 现在我们已经看了解到了一些ML应用程序的例子,问题是,我们如何构建这样的ML应用程序和系统? 下图总结了我们使用ML开发应用程序的方法,我们将在下面更详细地讨论这个问题: 如上图所 ...

  3. 序列标注(BiLSTM-CRF/Lattice LSTM)

    前言 在三大特征提取器中,我们已经接触了LSTM/CNN/Transormer三种特征提取器,这一节我们将介绍如何使用BiLSTM实现序列标注中的命名实体识别任务,以及Lattice-LSTM的模型原 ...

  4. 整理基础的CentOS常用命令

    如何知道apache装在哪里? which httpd 1.查看系统使用端口并释放端口 [root@my_nn_01 WEB-INF]# lsof -w -n -i tcp:80 COMMAND    ...

  5. Webstorm轻松部署项目至服务器

    wo大前端在开发环境下,需要将项目部署到测试环境,webstorm进行基础配置操作就可实现. 一.在Deployment选项下配置远程服务器地址 点击加号,选择type类型,Name自己填,帮你找到这 ...

  6. 瀑布流实例及懒加载(echo.js)

    瀑布流布局: 图片等宽,不定高,按最低高度来顺序排列:实现方法:获取每次获取四行中最低高度对应的一行,将下一张加载的图片放在该位置,每次加载前都获取最低高度: ①请求图片的接口    地址此php文件 ...

  7. 从零开始入门 K8s | 应用存储和持久化数据卷:核心知识

    作者 | 至天 阿里巴巴高级研发工程师 一.Volumes 介绍 Pod Volumes 首先来看一下 Pod Volumes 的使用场景: 场景一:如果 pod 中的某一个容器在运行时异常退出,被 ...

  8. abp(net core)+easyui+efcore实现仓储管理系统——EasyUI之货物管理三 (二十一)

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...

  9. Thymeleaf模板引擎的使用

    Thymeleaf模板引擎的使用 1.模板引擎 JSP.Velocity.Freemarker.Thymeleaf 2.springboot推荐使用Thymeleaf模板引擎 特点:语法更简单,功能更 ...

  10. lua多线程解决方案

    直观的讲:lua并不支持多线程,lua语言本身具有携程功能,但携程仅仅是一种中继器. lua多线程的目的:有并发需求时,共享一些数据. 例如使用lua写一个并发服务器.用户登陆之后,用户数据储存在lu ...