zoukankan      html  css  js  c++  java
  • RedHat6.2 x86手动配置LNMP环境

    因为公司要求用RedHat配,顺便让我练习一下Linux里面的操作什么的。

    折腾来折腾去终于搞好了,其实也没那么难嘛。但是也要记录一下。

    首先,是在服务器里面用VMware搭建的RedHat6.2 x86系统。在RedHat里面yum里面的源基本是收费的。CentOS呢,是RedHat的衍生版,目的就是打破redhat的收费,所以两者也没啥区别。直接就用CentOS6的yum包来配置了。

    首先,在终端里输入:

    cd /etc/yum.repos.d/

    这里面是放yum源的地方。默认里面会有一个rhel-source.repo后缀的文件,咱们把他删了或者重命名成.bak

    然后下一步就是添加centos的源了。新建一个centos.base.repo文件。在里面输入:

    # CentOS-Base.repo
    #
    # The mirror system uses the connecting IP address of the client and the
    # update status of each mirror to pick mirrors that are updated to and
    # geographically close to the client.  You should use this for CentOS updates
    # unless you are manually picking other mirrors.
    #
    # If the mirrorlist= does not work for you, as a fall back you can try the 
    # remarked out baseurl= line instead.
    #
     
    [base]
    name=CentOS-6 - Base - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos/6/os/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
    gpgcheck=0
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
     
    #released updates 
    [updates]
    name=CentOS-6 - Updates - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos/6/updates/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
    gpgcheck=0
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
     
    #additional packages that may be useful
    [extras]
    name=CentOS-6 - Extras - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos/6/extras/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
    gpgcheck=0
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
     
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-6 - Plus - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos/6/centosplus/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
    gpgcheck=0
    enabled=0
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
     
    #contrib - packages by Centos Users
    [contrib]
    name=CentOS-6 - Contrib - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos/6/contrib/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
    gpgcheck=0
    enabled=0
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

    保存之后,我们就有一个centos的源了。执行一下:yum -y update  试一下吧!

    下面是安装Nginx了。我们需要执行:

    yum -y --enablerepo=remi,remi-test install nginx 

    有些朋友可能会遇到:No Nginx package!,这很简单就能解决。

    在刚才创建源的yum.repos.d文件夹里面,再创建一个nginx.repo文件。输入以下内容:

    [nginx]  
    name=nginx repo  
    baseurl=http://nginx.org/packages/centos/6/$basearch/  
    gpgcheck=0  
    enabled=1

    OK,这是单独添加一个Nginx的源。再执行一次上面的安装Nginx的命令就Ok了!

    继续,安装php以及php-fpm

    yum -y --enablerepo=remi,remi-test install php php-fpm php-common  

    安装PHP5.4.4模块扩展,有些会提示No package,这些都是没用的,不要管它!

    yum -y --enablerepo=remi,remi-test install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml  

    这样就OK了。运行下面的命令,如果出现错误,说明你上面的步骤出错了。

    启动Nginx:
    service nginx start
    启动php-fpm:
    service php-fpm start

    下面是配置Nginx使用php-fpm,进入:

    /etc/nginx/conf.d/

    打开:default.conf 文件。找到:

    location / {  
           root   /usr/share/nginx/html;  #这一行是网站的根目录,你的网站文件就放在这个里面!
           index  index.html index.htm;  #这一行是添加网站的默认主页的。当然,你也可以添加一个index.php!
       }  

    再找到下面的内容,把它们前面的#去掉:

    #location ~ .php$ {  
    #       root           html;  
    #       fastcgi_pass   127.0.0.1:9000;  
    #       fastcgi_index  index.php;  
    #       fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;  
    #        include        fastcgi_params;  
    #}  

    然后把redhat的防火墙文件打开,把80端口添加进白名单:

    cd /etc/sysconfig/

    打开iptables文件,输入以下内容:

    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  

    重启防火墙:

    service iptables restart 

    到此为止,php与Nginx已经搭建好了。我们来试一下。先重启Nginx与php-fpm:

    service nginx restart  
    service php-fpm restart

    在你RedHat网页里输入:http://localhost/,成功出现 Welcome to nginx!则Nginx安装成功。

    然后进入你网站的根目录:/usr/share/nginx/html

    新建一个phpinfo.php文件:

    <?php
    phpinfo();
    ?>

    然后访问http://localhost/phpinfo.php

    看是不是出现php配置的页面了。如果出现就说明php安装成功了。

    开始安装mysql!!!!!在终端里输入:

    yum -y --enablerepo=remi,remi-test install mysql mysql-server 

    启动mysql and 设置自启动:

    service mysqld start  
    chkconfig --levels 235 mysqld on

    然后,进入/usr/bin/文件夹,运行mysql_secure_installation文件:

    cd /usr/bin/
    ./mysql_secure_installation

    这是配置mysql的安全模式。第一次装mysql最好都配置一下。增加安全性!

    执行上面的文件之后,会出现一些配置问题。

    1、Enter current password for root (enter for none): (输入当前的root密码) 当前的密码是空,所以直接回车。

    2、Set root password? [Y/n] (是否设置密码)输入Y 回车。

    3、New password:  (新密码)

    4、Re-enter new password:  (再输一次)

    5、Remove anonymous users? [Y/n]  (删除匿名账户) 

    6、Disallow root login remotely? [Y/n] (禁止root用户远程登录)

    7、Remove test database and access to it? [Y/n] (删除默认创建的test数据库)

    8、Reload privilege tables now? [Y/n] (重载权限表)

    安全模式配置完毕!

    然后把redhat的防火墙文件打开,把3306端口添加进白名单:

    cd /etc/sysconfig/

    打开iptables文件,输入以下内容:

    -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT 

    重启防火墙:

    service iptables restart 

    OK!LNMP配置完毕!

  • 相关阅读:
    阿里云:面向5G时代的物联网无线连接服务
    走近科学,探究阿里闲鱼团队通过数据提升Flutter体验的真相
    Redis 5.0新功能介绍
    阿里云发布 Redis 5.0 缓存服务:全新 Stream 数据类型带来不一样缓存体验
    荣获“5G MEC优秀商用案例奖”,阿里云边缘计算发力新零售
    阿里云亮相2019联通合作伙伴大会,边缘计算等3款云产品助力5G时代产业数字化转型
    noip2014 寻找道路
    noip2014 无线网络发射器选址
    noip2014 联合权值
    noip2013 华容道
  • 原文地址:https://www.cnblogs.com/im404/p/redhat6_x86_lnmp.html
Copyright © 2011-2022 走看看