Linux 目录:
前面进入Linux系统后,一般会在 root(~) 目录下 [root@xxxxxxxxxxx ~]#, cd ..可以即回到根目录,ls查看当前目录下文件
[root@xxxxxxxxxxx ~]#
[root@xxxxxxxxxxx ~]# cd ..
[root@xxxxxxxxxxx /]#
[root@xxxxxxxxxxx /]# ls
bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@xxxxxxxxxxx /]# cd root
[root@xxxxxxxxxxx ~]#
[root@xxxxxxxxxxx ~]# ls
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz ......
2. 解压文件
tar -xzvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@xxxxxxxxxxx ~]# ls
mysql-5.7.20-linux-glibc2.12-x86_64 (解压得到的目录)
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
// 拷贝解压到目录到 /usr/local 目录下,并改名为 mysql
[root@xxxxxxxxxxx ~]# cp mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql -r
[root@xxxxxxxxxxx ~]# cd /usr/local/mysql
[root@xxxxxxxxxxx mysql]# ls
bin COPYING docs include lib man README share support-files
3. 添加系统mysql组和mysql用户
[root@xxxxxxxxxxx ~]# groupadd mysql #建立一个mysql的组
[root@xxxxxxxxxxx ~]# useradd -r -g mysql mysql #建立mysql用户,并且把用户放到mysql组
4. 在 mysql 下添加 data 目录
[root@xxxxxxxxxxx mysql]# mkdir data
5. 更改mysql目录下所有的目录及文件夹所属组合用户
[root@xxxxxxxxxxx mysql]# cd /usr/local/
[root@xxxxxxxxxxx local]# chown -R mysql mysql/
[root@xxxxxxxxxxx local]# chgrp -R mysql mysql/
[root@xxxxxxxxxxx local]# cd mysql/
[root@xxxxxxxxxxx mysql]# ls -l
total 56
drwxr-xr-x 2 mysql mysql 4096 Nov 9 16:00 bin
-rw-r--r-- 1 mysql mysql 17987 Nov 9 16:00 COPYING
drwxr-xr-x 6 mysql mysql 4096 Nov 9 18:41 data
drwxr-xr-x 2 mysql mysql 4096 Nov 9 16:00 docs
drwxr-xr-x 3 mysql mysql 4096 Nov 9 16:01 include
drwxr-xr-x 5 mysql mysql 4096 Nov 9 16:01 lib
drwxr-xr-x 4 mysql mysql 4096 Nov 9 16:00 man
-rw-r--r-- 1 mysql mysql 2478 Nov 9 16:00 README
drwxr-xr-x 28 mysql mysql 4096 Nov 9 16:00 share
drwxr-xr-x 2 mysql mysql 4096 Nov 9 18:06 support-files
6. 安装和初始化数据库
很多老的教程中都是运行 ./scripts/mysql_install_db --user=mysql 进行安装,但在新版本的mysql中已经没了 scripts 目录,
mysql_install_db 放在了 bin 目录下
[root@xxxxxxxxxxx mysql]# cd bin
[root@xxxxxxxxxxx bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/--datadir=/usr/local/mysql/data/
2017-11-09T09:09:52.826209Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-09T09:09:54.885578Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/--datadir=/usr/local/mysql/data/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' con
figuration directive.2017-08-31T08:50:24.709286Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-09T09:09:55.105938Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-09T09:09:55.218562Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c0844cc4-c52d-11e7-b74f-00163e0ae84e.
2017-11-09T09:09:55.221300Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-11-09T09:09:55.221784Z 1 [Note] A temporary password is generated for root@localhost: uf)qP3+C?jpJ
// 进入项目目录
[root@izwz9e9bjg74ljcpzr7stvz ~]# cd /root/project/myblog
[root@izwz9e9bjg74ljcpzr7stvz myblog]# ls
dist server
初始化创建 package.json,这一步也可以在本地创建编辑好后上传到服务器目录即可
[root@izwz9e9bjg74ljcpzr7stvz myblog]# npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (myblog)
version: (1.0.0)
description:
entry point: (index.js)
testcommand:
git repository:
keywords:
author:
license: (ISC)
About to write to /root/project/test/myblog/package.json:
{
"name": "myblog",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this ok? (yes) yes
// 全部回车即可
[root@izwz9e9bjg74ljcpzr7stvz myblog]# ls
dist package.json server
// 打开 package.json 编辑(也可在 Xftp 中右键文件编辑)
[root@izwz9e9bjg74ljcpzr7stvz myblog]# vim package.json
{
"name": "my-blog",
"version": "1.0.0",
"description": "A Vue.js project",
"author": "ChenLiang <236338364@qq.com>",
"private": true,
"scripts": {
"dev": "node build/dev-server.js",
"start": "node build/dev-server.js",
"build": "node build/build.js"
},
"dependencies": {
"body-parser": "^1.17.2",
"cookie-parser": "^1.4.3",
"express": "^4.16.2",
"express-session": "^1.15.5",
"formidable": "^1.1.1",
"highlight.js": "^9.12.0",
"marked": "^0.3.6",
"mysql": "^2.14.0",
"node-sass": "^4.5.3",
"node-uuid": "^1.4.8"
},
"engines": {
"node": ">= 4.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
[root@izwz9e9bjg74ljcpzr7stvz download]# tar zxvf zlib-1.2.11.tar.gz
[root@izwz9e9bjg74ljcpzr7stvz download]# tar tar zxvf pcre-8.41.tar.gz
[root@izwz9e9bjg74ljcpzr7stvz download]# tar zxvf openssl-fips-2.0.16.tar.gz
[root@izwz9e9bjg74ljcpzr7stvz download]# tar zxvf nginx-1.13.7.tar.gz
先安装3个依赖包,分别进入各自解压目录
// 看清各个目录下的是 configure 还是 config
[root@izwz9e9bjg74ljcpzr7stvz zlib-1.2.11]# ./configuer && make && make install
[root@izwz9e9bjg74ljcpzr7stvz pcre-8.41]# ./configuer && make && make install
[root@izwz9e9bjg74ljcpzr7stvz openssl-fips-2.0.16]# ./config && make && make install
[root@izwz9e9bjg74ljcpzr7stvz nginx-1.13.7]# ./configure --with-pcre=../pcre-8.41/ --with-zlib=../zlib-1.2.11/ --with-openssl=../openssl-fips-2.0.16/
[root@izwz9e9bjg74ljcpzr7stvz nginx-1.13.7]# make && make install
安装 C++ 编译环境 (上面安装过程中如若有报错,可以看看是不是因为没有安装这个,可提前安装)
yum install gcc-c++
运行Nginx
安装好的Nginx路径在 /usr/local/nginx
[root@izwz9e9bjg74ljcpzr7stvz ~]# cd /usr/local/nginx
[root@izwz9e9bjg74ljcpzr7stvz nginx]# ls
client_body_temp conf fastcgi_temp html logs nginx.conf proxy_temp sbin scgi_temp uwsgi_temp
配置文件路径:
/usr/local/nginx/conf/nginx.conf
运行Nginx:
[root@izwz9e9bjg74ljcpzr7stvz ~]# cd /usr/local/nginx/sbin
[root@izwz9e9bjg74ljcpzr7stvz sbin]# ./nginx
// 查看是否运行成功
[root@izwz9e9bjg74ljcpzr7stvz sbin]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3525/nginx: master
#! /bin/sh# chkconfig: 2345 55 25# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and# run 'update-rc.d -f nginx defaults', or use the appropriate command on your# distro. For CentOS/Redhat run: 'chkconfig --add nginx'### BEGIN INIT INFO# Provides: nginx# Required-Start: $all# Required-Stop: $all# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts the nginx web server# Description: starts nginx using start-stop-daemon### END INIT INFO# Author: licess# website: http://lnmp.org
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
case"$1"in
start)
echo -n "Starting $NAME... "if netstat -tnpl | grep -q nginx;thenecho"$NAME (pid `pidof $NAME`) already running."exit 1
fi$NGINX_BIN -c $CONFIGFILEif [ "$?" != 0 ] ; thenecho" failed"exit 1
elseecho" done"fi
;;
stop)
echo -n "Stoping $NAME... "if ! netstat -tnpl | grep -q nginx; thenecho"$NAME is not running."exit 1
fi$NGINX_BIN-s stop
if [ "$?" != 0 ] ; thenecho" failed. Use force-quit"exit 1
elseecho" done"fi
;;
status)
if netstat -tnpl | grep -q nginx; then
PID=`pidof nginx`
echo"$NAME (pid $PID) is running..."elseecho"$NAME is stopped"exit 0
fi
;;
force-quit)
echo -n "Terminating $NAME... "if ! netstat -tnpl | grep -q nginx; thenecho"$NAME is not running."exit 1
fikill `pidof $NAME`
if [ "$?" != 0 ] ; thenecho" failed"exit 1
elseecho" done"fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
reload)
echo -n "Reload service $NAME... "if netstat -tnpl | grep -q nginx; then$NGINX_BIN-s reload
echo" done"elseecho"$NAME is not running, can't reload."exit 1
fi
;;
configtest)
echo -n "Test $NAME configure files... "$NGINX_BIN -t
;;
*)
echo"Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"exit 1
;;
esac
修改脚本权限
chmod a+x /etc/init.d/nginx
注册成服务
chkconfig --add nginx
设置开机启动
chkconfig nginx on
这样就可以在任意目录通过service启动、关闭nginx
[root@izwz9e9bjg74ljcpzr7stvz ~]# service nginx start
[root@izwz9e9bjg74ljcpzr7stvz ~]# service nginx stop
[root@izwz9e9bjg74ljcpzr7stvz ~]# service nginx restart