Centos7下编译安装Nginx、Mysql、PHP

后续继续优化


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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,716评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,558评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,431评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,127评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,511评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,692评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,915评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,664评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,412评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,616评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,105评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,424评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,098评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,096评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,869评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,748评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,641评论 2 271