centos 7.1 安装 lnmp
-
安装nginx
- 准备安装(安装相应环境):
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel vim
- 设置vim永久显示行号:
vim ~/.vimrc
set number
-
配置ssh链接时间:
- 服务器端:
vim /etc/ssh/ssh_config
GSSAPIAuthentication no ServerAliveInterval 3600 ServerAliveCountMax 3
- 客户端:
vim /etc/ssh/sshd_config
ClientAliveInterval 50 ClientAliveCountMax 3
- 服务器端:
-
安装nginx
- 检查是否已经安装过nginx如果有,则删除
find -name nginx yum remove nginx
- 下载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
-
安装成功后检查路径
whereis nignx
,默认在/usr/local/nginx
-
安装路径下:
/nginx/sbin/nginx -t
-
查看进程:
ps -ef | grep nginx
-
启动,重启,停止:
命令 说明 ./nginx 启动 ./nginx -s reload 重启 ./nginx -s stop 停止(自动杀死进程) ./nginx -s quit 停止 -
开放防火墙端口:
- 检查防火墙运行状态:
systemctl status firewalld
- 启动防火墙:
systemctl start firewalld
- 添加端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
- 再次通过
systemctl status firewalld
查看firewalld
状态,显示running
即已开启了。
- 检查防火墙运行状态:
-
为域名创建配置:
vim /usr/local/nginx/conf/nginx.conf
,增加:include vhost/*.conf
-
创建nginx启动命令脚本:
vim /etc/init.d/nginx
- 插入内容
#! /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
- 设置执行权限:
chmod a+x /etc/init.d/nginx
- 注册成服务:
chkconfig --add nginx
- 设置开机启动:
chkconfig nginx on
- 重启服务器:
shutdown -h 0 -r
- 检查是否自动重启:
netstat -apn|grep nginx
- 针对nginx服务执行命令
命令 说明 systemctl start nginx.service
启动 systemctl stop nginx.service
停止 systemctl restart nginx.service
重启 systemctl reload nginx.service
不重启,重新加载配置,直接生效
-
安装mysql
1.