美文网首页
Centos7下编译安装Nginx、Mysql、PHP

Centos7下编译安装Nginx、Mysql、PHP

作者: 杜永龙 | 来源:发表于2018-01-25 05:28 被阅读0次

    后续继续优化


    1.操作环境

    Centos 7 x64位

    hostname:nagios1

    #为部署nagios而搭建的lnmp环境

    IP地址:192.168.122.217

    Nginx:1.12.0

    Mysql:5.7.18

    PHP:7.1.4

    yum源:aliyun源

    2.下载需要的安装包

     2.1创建存放目录

      [root@nagios1 ~]# mkdir /software

      [root@nagios1 ~]# cd /software/

      [root@nagios1 software]# pwd

      /software

      [root@nagios1 software]#

      2.2 下载安装包

        wget https://sourceforge.net/projects/pcre/files/pcre/8.40/pcre-8.40.tar.gz

        wget http://nginx.org/download/nginx-1.12.0.tar.gz

        wget http://hk1.php.net/distributions/php-7.1.4.tar.gz

        wget https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.18.tar.gz

    3.关闭系统限制

      3.1关闭系统防火墙

                   [root@nagios1 software]# systemctl stop firewalld.service

                   [root@nagios1 software]# systemctl disable firewalld.service

                   Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.

                   Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

      3.2关闭selinux

                    [root@nagios1 software]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

                    [root@nagios1 software]# setenforce 0

    4.安装nginx

        4.1 创建nginx的用户

               [root@nagios1 software]# useradd nginx -s /sbin/nologin

     4.2 安装依赖包

               yum -y install pcre pcre-devel zlib zlib-devel gcc-c++ gcc openssl*

     4.3 解压nginx

               [root@nagios1 software]# ls

               mysql-boost-5.7.18.tar.gz   nginx-1.12.0.tar.gz  pcre-8.40.tar.gz  php-7.1.4.tar.gz

               [root@nagios1 software]# pwd

                /software

               [root@nagios1 software]# tar zxf nginx-1.12.0.tar.gz

                [root@nagios1 software]# ls

               mysql-boost-5.7.18.tar.gz    nginx-1.12.0/  nginx-1.12.0.tar.gz  pcre-8.40.tar.gz  php-7.1.4.tar.gz

        4.4 配置nginx

                     [root@nagios1 software]# cd nginx-1.12.0

                     [root@nagios1 nginx-1.12.0]# pwd

                      /software/nginx-1.12.0

                     ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre

        4.5 编译nginx

              [root@nagios1 nginx-1.12.0]# make

       4.6 安装nginx

             [root@nagios1 nginx-1.12.0]# make install

      4.7 启动nginx

             [root@nagios1 nginx-1.12.0]# /usr/local/nginx/sbin/nginx

       4.7 测试nginx

       4.8 关闭nginx进程

       [root@nagios1 nginx-1.12.0]# /usr/local/nginx/sbin/nginx -s stop

       [root@nagios1 nginx-1.12.0]# ps -ef |grep nginx

       root    18725 16002  0 17:00 pts/0    00:00:00 grep --color=auto nginx

       4.9 创建软连接命令方便后续使用

       [root@nagios1 nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /sbin/nginx

       [root@nagios1 nginx-1.12.0]# ll /sbin/nginx

       lrwxrwxrwx. 1 root root 27 1月  24 17:00 /sbin/nginx -> /usr/local/nginx/sbin/nginx

       4.10 编写nginx启动脚本

       [root@nagios1 nginx-1.12.0]# ll /usr/lib/systemd/system/nginx.service

       -rw-r--r--. 1 root root 407 1月  24 17:03 /usr/lib/systemd/system/nginx.service

       [root@nagios1 nginx-1.12.0]# cat !$

       cat /usr/lib/systemd/system/nginx.service

       [Unit]

       Description=nginx - high performance web server

       Documentation=http://nginx.org/en/docs/

       After=network-online.target remote-fs.target nss-lookup.target

       [Service]

       Type=forking

       PIDFile=/usr/local/nginx/logs/nginx.pid

       ExecStartPre=/usr/sbin/nginx -t

       ExecStart=/usr/sbin/nginx

       ExecReload=//usr/sbin/nginx -s reload

       ExecStop=/usr/sbin/nginx -s stop

       PrivateTmp=true

       [Install]

       WantedBy=multi-user.target

       4.11 加载nginx服务

       [root@nagios1 nginx-1.12.0]# systemctl daemon-reload

       4.12 使用systemctl启动nginx

       [root@nagios1 nginx-1.12.0]# systemctl start nginx

       [root@nagios1 nginx-1.12.0]# systemctl status nginx

       ● nginx.service - nginx - high performance web server

         Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)

         Active: active (running) since 三 2018-01-24 17:05:16 EST; 10s ago

           Docs: http://nginx.org/en/docs/

          Process: 18772 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)

          Process: 18770 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)

        Main PID: 18774 (nginx)

          CGroup: /system.slice/nginx.service

                ├─18774 nginx: master process /usr/sbin/nginx

                └─18775 nginx: worker process

        1月 24 17:05:15 nagios1 systemd[1]: Starting nginx - high performance web server...

        1月 24 17:05:16 nagios1 nginx[18770]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

        1月 24 17:05:16 nagios1 nginx[18770]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

        1月 24 17:05:16 nagios1 systemd[1]: Failed to read PID from file /usr/local/nginx/logs/nginx.pid: Invalid argument

        1月 24 17:05:16 nagios1 systemd[1]: Started nginx - high performance web server.

       4.13设置开机启动

       [root@nagios1 nginx-1.12.0]# systemctl enable nginx

       Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

    5.

    相关文章

      网友评论

          本文标题:Centos7下编译安装Nginx、Mysql、PHP

          本文链接:https://www.haomeiwen.com/subject/fdemaxtx.html