记录下本身学习经历的一个过程,以便往后查看。javascript
我的github: https://github.com/hwgq2005
笔记来源:http://www.bookcss.com/note/12/14
复制代码
从根目录建立data目录,cd data
进入目录,开始执行一下操做php
wget https://nodejs.org/dist/v8.11.1/node-v8.11.1-linux-x64.tar.xz
复制代码
xz -d node-v8.11.1-linux-x64.tar.xz
或者
tar -xzvf node-v8.11.1-linux-x64.tar.gz
复制代码
tar -xvf node-v8.11.1-linux-x64
复制代码
ln -s /data/node-v8.11.1-linux-x64/bin/node /usr/local/bin/node
复制代码
ln -s /data/node-v8.10.0-linux-x64/bin/npm /usr/local/bin/npm
复制代码
PM2是node进程管理工具,能够利用它来简化不少node应用管理的繁琐任务,如性能监控、自动重启、负载均衡等,并且使用很是简单。css
npm install pm2 -g
复制代码
ln -s /data/node-v8.11.1-linux-x64/bin/pm2 /usr/local/bin/pm2
复制代码
安装 nginx 须要先将官网下载的源码进行编译,编译依赖 gcc 环境,若是没有 gcc 环境,则须要安装:html
yum install gcc-c++
复制代码
安装 PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,因此须要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre开发的一个二次开发库。nginx也须要此库。vue
yum install -y pcre pcre-devel
复制代码
zlib 库提供了不少种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,因此须要在 Centos 上安装 zlib 库。java
yum install -y zlib zlib-devel
复制代码
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、经常使用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。 nginx 不只支持 http 协议,还支持 https(即在ssl协议上传输http),因此须要在 Centos 安装 OpenSSL 库。node
yum install -y openssl openssl-devel
复制代码
wget https://nginx.org/download/nginx-1.16.0.tar.gz
复制代码
tar -xzvf node-v8.11.1-linux-x64.tar.gz
cd nginx-1.10.1
复制代码
使用默认就行了,如需复制请找相关资料查看mysql
./configure
复制代码
make
make install
复制代码
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
复制代码
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
复制代码
进入目录/usr/local/nginx/conf/ 打开 vim nginx.conf
linux
http {
#引入服务
include /etc/nginx/vhost/*.conf;
#开启压缩
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
...
#更多配置请查看nginx相关文档
}
复制代码
include /etc/nginx/vhost/*.conf 对应是每一个服务。 如:web.confnginx
server {
listen 80; # 监听端口
server_name 域名1 域名2; # 站点域名
root /var/www/项目1; # 站点根目录
index index.html; # 默认导航页
#这个是配合vue.js路由模式history,防止刷新页面404
location / {
try_files $uri $uri/ /index.html;
}
}
复制代码
如:api.conf
server {
listen 80;
server_name 域名3;
location / {
#容许跨域,后台不须要再加Access-Control-Allow-Origin
set $origin '*';
add_header Access-Control-Allow-Origin $origin;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
proxy_pass http://localhost:3000;
}
}
复制代码
vim /usr/lib/systemd/system/nginx.service
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
复制代码
参数 | 说明 |
---|---|
Description | 描述服务 |
After | 依赖,当依赖的服务启动以后再启动自定义的服务 |
[Service] | 服务运行参数的设置 |
Type=forking | 是后台运行的形式 |
ExecStart | 为服务的具体运行命令(须要根据路径适配) |
ExecReload | 为重启命令(须要根据路径适配) |
ExecStop | 为中止命令(须要根据路径适配) |
PrivateTmp=True | 表示给服务分配独立的临时空间 |
注意:启动、重启、中止命令所有要求使用绝对路径 [Install]服务安装的相关设置,可设置为多用户
systemctl disable nginx.service 关闭开机自启
systemctl enable nginx.service 开启开机自启
systemctl status nginx.service 查看状态
systemctl restart nginx.service 重启服务
systemctl list-units --type=service 查看全部服务
复制代码
安装mysql有2种方式,一种是tar.gz包、一种是经过yum安装,我用的是yum方式安装。
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install mysql-server
复制代码
chown mysql:mysql -R /var/lib/mysql
复制代码
mysqld --initialize
复制代码
systemctl start mysqld
复制代码
systemctl status mysqld
复制代码
Mysql安装成功后,默认的root用户密码为空,你可使用如下命令来建立root用户的密码:
mysqladmin -u root password "new_password";
复制代码
链接到Mysql服务器
[root@host]# mysql -u root -p
Enter password:*******
复制代码
Linux下Mysql操做数据库时中文乱码
首先进入msyql,而后使用show variables like 'character%'
,查看编码状况。
打开 etc/my.cnf 文件,加入如下语句:
[client]
default-character-set=utf8 //添加该语句
[mysqld]
character_set_server=utf8 //添加该语句
[mysql]
default-character-set=utf8 //添加该语句
复制代码
drop database
数据库名,删除建立的数据库systemctl start mysqld
复制代码