centos7.1 安装 lnmp

centos 7.1 安装 lnmp

  1. 安装nginx

    1. 准备安装(安装相应环境):
    yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel vim
    
    1. 设置vim永久显示行号:vim ~/.vimrc
    set number
    
    1. 配置ssh链接时间:

      1. 服务器端:vim /etc/ssh/ssh_config
      GSSAPIAuthentication no
      ServerAliveInterval 3600
      ServerAliveCountMax 3
      
      1. 客户端:vim /etc/ssh/sshd_config
      ClientAliveInterval 50
      ClientAliveCountMax 3
      
    2. 安装nginx

      1. 检查是否已经安装过nginx如果有,则删除
      find -name nginx
      yum remove nginx
      
      1. 下载nginx、解压缩、编译安装
      wget -c http://nginx.org/download/nginx-1.14.1.tar.gz
      tar -zxvf nginx-1.14.1.tar.gz
      cd nginx-1.14.1
      ./configure
      make -j 4 && make install
      
      1. 安装成功后检查路径whereis nignx,默认在/usr/local/nginx

      2. 安装路径下:/nginx/sbin/nginx -t

      3. 查看进程:ps -ef | grep nginx

      4. 启动,重启,停止:

      命令说明
      ./nginx启动
      ./nginx -s reload重启
      ./nginx -s stop停止(自动杀死进程)
      ./nginx -s quit停止
    3. 开放防火墙端口:

      1. 检查防火墙运行状态:systemctl status firewalld
      2. 启动防火墙:systemctl start firewalld
      3. 添加端口:firewall-cmd --zone=public --add-port=80/tcp --permanent
      4. 再次通过systemctl status firewalld查看firewalld状态,显示running即已开启了。
    4. 为域名创建配置:vim /usr/local/nginx/conf/nginx.conf,增加:include vhost/*.conf

    5. 创建nginx启动命令脚本:vim /etc/init.d/nginx

      1. 插入内容
      #! /bin/bash
      # chkconfig: - 85 15
      PATH=/usr/local/nginx
      DESC="nginx daemon"
      NAME=nginx
      DAEMON=$PATH/sbin/$NAME
      CONFIGFILE=$PATH/conf/$NAME.conf
      PIDFILE=$PATH/logs/$NAME.pid
      SCRIPTNAME=/etc/init.d/$NAME
      set -e
      [ -x "$DAEMON" ] || exit 0
      do_start() {
      $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
      }
      do_stop() {
      $DAEMON -s stop || echo -n "nginx not running"
      }
      do_reload() {
      $DAEMON -s reload || echo -n "nginx can't reload"
      }
      case "$1" in
      start)
      echo -n "Starting $DESC: $NAME"
      do_start
      echo "."
      ;;
      stop)
      echo -n "Stopping $DESC: $NAME"
      do_stop
      echo "."
      ;;
      reload|graceful)
      echo -n "Reloading $DESC configuration..."
      do_reload
      echo "."
      ;;
      restart)
      echo -n "Restarting $DESC: $NAME"
      do_stop
      do_start
      echo "."
      ;;
      *)
      echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
      exit 3
      ;;
      esac
      exit 0
      
      1. 设置执行权限:chmod a+x /etc/init.d/nginx
      2. 注册成服务:chkconfig --add nginx
      3. 设置开机启动:chkconfig nginx on
      4. 重启服务器:shutdown -h 0 -r
      5. 检查是否自动重启:netstat -apn|grep nginx
      6. 针对nginx服务执行命令
      命令说明
      systemctl start nginx.service启动
      systemctl stop nginx.service停止
      systemctl restart nginx.service重启
      systemctl reload nginx.service不重启,重新加载配置,直接生效
  2. 安装mysql
    1.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值