centos7搭建LNMP环境编译安装 yum安装超详细
发布时间:2023-02-17 14:01:11 所属栏目:LNMP 来源:互联网
导读:文章目录 1. 首先了解编译安装和yum安装的区别。 2. yum安装准备工作---切换阿里云yum源 3. 编译安装lnmp **很不建议使用编译安装,麻烦且容易报错。** 4.yum安装lnmp **可以先执行一下 yum update** 5. lnmp一键安装 [参考网站](https://lnmp.org/) **不喜
文章目录 1. 首先了解编译安装和yum安装的区别。 2. yum安装准备工作---切换阿里云yum源 3. 编译安装lnmp **很不建议使用编译安装,麻烦且容易报错。** 4.yum安装lnmp **可以先执行一下 yum update** 5. lnmp一键安装 [参考网站](https://lnmp.org/) **不喜欢这种方式,所以没测试过,可以看这篇文章** 6. 一些报错 7. 笔记 8. 参考文章 1. 首先了解编译安装和yum安装的区别。 windows下安装centos虚拟机,之前写过。传送门~~ 编译安装: 可以按需安装,想安在哪个目录下就安在哪个目录下。 可以设定参数 可安装自己想要的版本 yum安装: 安装的方便快捷 不需要考虑包的依赖 可以直接使用service Nginx start 等命令。 2. yum安装准备工作—切换阿里云yum源 # 1.备份原有的yum源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup # 2.下载新的CentOS-Base.repo 到/etc/yum.repos.d/ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # 3.清理缓存 yum clean all # 4.生成缓存 yum makecache 如果想查看当前yum源是否切换成功,可随便使用yum安装一个东西即可看到。 yum install vim base: mirrors.aliyun.com 这一行就代表了yum源地址 3. 编译安装lnmp 很不建议使用编译安装,麻烦且容易报错。 Nginx 1.1 查看本地有没有安装过Nginx rpm -qa | grep Nginx 如果安装过,则执行如下命令,卸载原有的Nginx rpm -e Nginx-* 1.2 安装 Nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装 yum install gcc-c++ 1.3 PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。Nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。Nginx也需要此库。命令: yum install -y pcre pcre-devel 1.4 zlib 库提供了很多种压缩和解压缩的方式, Nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。 yum install -y zlib zlib-devel 1.5 OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。 Nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。 yum install -y openssl openssl-devel 1.6 官网下载 tar.gz安装包,地址~ Mainline version:主线版本 Stable version:稳定版本 Legacy versions:旧版本 # 我们lnmp环境全部安装在这个目录下 cd /usr/local # 下载 wget -c https://Nginx.org/download/Nginx-1.20.0.tar.gz # 解压 tar -zxvf Nginx-1.20.0.tar.gz cd Nginx-1.20.0 # 编译 ./configure --prefix=/usr/local/Nginx # 安装 make && make install # make[1]: 离开目录“/usr/local/Nginx-1.20.0” 最后显示这个是编译安装成功的意思! 启动、停止Nginx cd /usr/local/Nginx/sbin/ ./Nginx ./Nginx -s stop ./Nginx -s quit ./Nginx -s reload # 查看ngin进程 ps aux | grep Nginx 配置Nginx的service服务 首先 先停掉Nginx服务 killall -9 Nginx 或者使用 cd /usr/local/Nginx/sbin/ && ./Nginx -s stop 然后编辑Nginx.service配置文件 vim /etc/init.d/Nginx 在里面写入以下配置: #!/bin/sh # # Nginx - this script starts and stops the Nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse # proxy and IMAP/POP3 proxy server # processname: Nginx # config: /etc/Nginx/Nginx.conf # config: /etc/sysconfig/Nginx # pidfile: /var/run/Nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 # 配置Nginx命令的位置 # 修改为你的Nginx可执行命令的路径如: /usr/local/Nginx/sbin/Nginx Nginx="/usr/local/Nginx/sbin/Nginx" prog=$(basename $Nginx) # 指向你的配置文件路径,如:/usr/local/Nginx/conf/Nginx.conf Nginx_CONF_FILE="/usr/local/Nginx/conf/Nginx.conf" [ -f /etc/sysconfig/Nginx ] && . /etc/sysconfig/Nginx lockfile=/var/lock/subsys/Nginx make_dirs() { # make required directories user=`$Nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=([^ ]*).*/1/g' -` if [ -n "$user" ]; then if [ -z "`grep $user /etc/passwd`" ]; then useradd -M -s /bin/nologin $user fi options=`$Nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done fi } start() { [ -x $Nginx ] || exit 5 [ -f $Nginx_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $Nginx -c $Nginx_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |