# google浏览器 远程配置地址
https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt
安装图形界面
# 先安装 MATE Desktop
yum groups install "MATE Desktop"
命令输入之后,会列出一大堆文字的,然后显示这个y/d/n,输入y,按回车下载安装;
安装完成,显示下面图片complete
# 安装好 MATE Desktop 后,再安装 X Window System。
yum groups install "X Window System"
# 设置默认通过桌面环境启动服务器:
systemctl set-default graphical.target
systemctl set-default multi-user.target //设置成命令模式
在安装 “X Window System” 的时候出现问题,提示 “no packegs”。于是决定更换 yum
更换yum(换成“aliyun”)
# 备份本地yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
# 获取阿里yum源配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 更新cache
yum makecache
# 查看
yum -y update
# 最后你就可以链接国内镜像了,其实就是那个什么城XXX的 。。。
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum -y update
然而并没有什么卵用!!!
- [x] 现在添加 中科大\163\sohu 的yum源(也没有什么卵用,换系统后就好了)
cd /etc/yum.repos.d
# 备份系统自带的yum源
mv CentOS-Base.repo CentOS-Base.repo.save
# 下载其他更快的yum源
# 中科大的yum源:
wget http://centos.ustc.edu.cn/CentOS-Base.repo
# 163的yum源:
wget http://mirrors.163.com/.help/CentOS-Base-163.repo
# sohu的yum源
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo
按照流程安装err
yum groups install "MATE Desktop"
错误:软件包:2:postfix-2.10.1-6.el7.x86_64 (base)
需要:libmysqlclient.so.18(libmysqlclient_18)(64bit)
错误:软件包:2:postfix-2.10.1-6.el7.x86_64 (base)
需要:libmysqlclient.so.18()(64bit)
您可以尝试添加 --skip-broken 选项来解决该问题
您可以尝试执行:rpm -Va --nofiles --nodigest
# linux 删除命令
# 删除文件夹实例:
rm -rf /var/log/httpd/access
将会删除/var/log/httpd/access目录以及其下所有文件、文件夹
# 删除文件使用实例:
rm -f /var/log/httpd/access.log
将会强制删除/var/log/httpd/access.log这个文件
检查mysql “mysql-community-server” 是否安装成功
安装命令:yum install mysql-community-server -y
[CentOS7.0使用yum安装MySQL及使用遇到的问题]http://www.linuxidc.com/Linux/2016-09/134992.htm)
这样就安装完成mysql了,我们可以用命令查看一下是否安装成功了
命令是:rpm -qa | grep mysql
显示:
mysql-community-release-el7-5.noarch
发现安装成功了
# 在命令后加--skip-broken
yum groups install "MATE Desktop" --skip-broken
添加用户
username(root)/password
创建新用户 创建一个用户名为:username
[root@localhost ~]# adduser username
为这个用户初始化密码,linux会判断密码复杂度,不过可以强行忽略:
[root@localhost ~]# passwd password
授权
个人用户的权限只可以在本home下有完整权限,其他目录要看别人授权。而经常需要root用户的权限,这时候sudo可以化身为root来操作。我记得我曾经sudo创建了文件,然后发现自己并没有读写权限,因为查看权限是root创建的。
新创建的用户并不能使用sudo命令,需要给他添加授权。
sudo命令的授权管理是在sudoers文件里的。可以看看sudoers:
[root@localhost ~]# sudoers
bash: sudoers: 未找到命令...
[root@localhost ~]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz
找到这个文件位置之后再查看权限:
[root@localhost ~]# ls -l /etc/sudoers
-r--r----- 1 root root 4251 9月 25 15:08 /etc/sudoers
只有只读的权限,如果想要修改的话,需要先添加w权限:
[root@localhost ~]# chmod -v u+w /etc/sudoers
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)
然后就可以添加内容了,在下面的一行下追加新增的用户:
[root@localhost ~]# vim /etc/sudoers
## Allow root to run any commands anywher
root ALL=(ALL) ALL
linuxidc ALL=(ALL) ALL #这个是新增的用户
wq保存退出,这时候要记得将写权限收回:
[root@localhost ~]# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)
这时候使用新用户登录,使用sudo:
[linuxidc@localhost ~]$ sudo cat /etc/passwd
[sudo] password for linuxidc:
CentOS 7.3下部署基于Node.js的微信小程序商城
- NideShop商城api服务:https://github.com/tumobi/nideshop
- NideShop微信小程序商城: https://github.com/tumobi/nideshop-mini-program
- NideShop后台管理系统: https://github.com/tumobi/nideshop-admin
更新系统和安装 git、vim、curl
yum update -y
yum install curl git -y
通过 nvm 安装 Node.js
- 安装 nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
验证安装是否成功
source ~/.bashrc
nvm --version
看到输出版本信息 0.33.5 表示安装成功
- 查看最新 8.x 版本 Node.js 版本并安装
nvm ls-remote
nvm install v8.9.3
node -v
看到输出版本信息 v8.2.1 表示安装成功
必须安装 Node.js 8.x 以上版本
安装 MySQL 5.7 修改密码失败,按照“CentOS下MySQL忘记root密码解决方法”成功修改密码
yum install https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm -y
yum install mysql-community-server -y
# 启动 mysql
systemctl start mysqld
systemctl enable mysqld
# 查找 root 的初始密码
cat /var/log/mysqld.log | grep password
# 更改密码
mysql_secure_installation
回车后输入查找到的密码,然后按照料提示更改密码
注意新密码必须包含特殊字符、数字、和大小写字母且不得少于8位,否则更改失败。
验证 mysql 是否安装成功
mysql -uroot -p
开始运行 NideShop
- 下载 NideShop 的源码
mkdir /var/www
cd /var/www
git clone https://github.com/tumobi/nideshop
- 全局安装 ThinkJS 命令
npm install -g think-cli
thinkjs -v
- 安装依赖
cd /var/www/nideshop
npm install
- 创建数据库并导入数据
mysql -uroot -p -e "create database nideshop character set utf8mb4"
mysql -uroot -p nideshop < /var/www/nideshop/nideshop.sql
- 修改 Nideshop 的数据库配置
vim src/common/config/adapter.js
- 修改后
24 /**
25 * model adapter config
26 * @type {Object}
27 */
28 exports.model = {
29 type: 'mysql',
30 common: {
31 logConnect: isDev,
32 logSql: isDev,
33 logger: msg => think.logger.info(msg)
34 },
35 mysql: {
36 handle: mysql,
37 database: 'nideshop',
38 prefix: 'nideshop_',
39 encoding: 'utf8mb4',
40 host: '127.0.0.1',
41 port: '3306',
42 user: 'root',
43 password: '你的密码',
44 dateStrings: true
45 }
46 };
注意 encoding,prefix 的值
编译项目
npm run compile
以生产模式启动
node production.js
打开另一个终端验证是否启动成功
curl -I http://127.0.0.1:8360/
# 输出 HTTP/1.1 200 OK,则表示成功
**Ctrl + C 停止运行**
为防止后面操作出现[Error] Error: Address already in use, port:8360. 的错误,一定要记得Ctrl + C停止运行,并确保curl -I http://127.0.0.1:8360/不能访问
使用 PM2 管理服务
- 安装配置 pm2
npm install -g pm2
- 修改项目根目录下的 pm2.json 为:
vim pm2.json
- 修改后的内容如下 :
{
"apps": [{
"name": "nideshop",
"script": "production.js",
"cwd": "/var/www/nideshop",
"exec_mode": "fork",
"max_memory_restart": "256M",
"autorestart": true,
"node_args": [],
"args": [],
"env": {
}
}]
}
如果服务器配置较高,可适当调整 max_memory_restart 和instances的值
- 启动pm2
pm2 start pm2.json
成功启动
使用 nginx 做反向代理
yum install nginx -y
systemctl start nginx.service
systemctl enable nginx.service
测试本地是否可以正常访问
curl -I localhost
修改nginx配置
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
vim /etc/nginx/nginx.conf
内容如下(只需更改 server 里面的内容)
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name swims.top www.swims.top;#申请的域名
root /var/www/nideshop/www;
set $node_port 8360;
index index.js index.html index.htm;
if ( -f $request_filename/index.html ){
rewrite (.*) $1/index.html break;
}
if ( !-f $request_filename ){
rewrite (.*) /index.js;
}
location = /index.js {
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:$node_port$request_uri;
proxy_redirect off;
}
location ~ /static/ {
etag on;
expires max;
}
}
}
- 重新启动nginx并验证nginx是否还可以正常访问
nginx -t
systemctl restart nginx.service
curl http://127.0.0.1/
- 如果返回的是下图的json数据则表示nginx反向代理配置成功
注:阿里云默认外网不能访问80/443端口,请更改实例的安全组配置,配置教程:https://help.aliyun.com/document_detail/25475.html?spm=5176.doc25475.3.3.ZAx4Uo
配置https访问
- 安装certbot
yum install epel-release -y
yum install certbot-nginx -y
certbot --nginx
如果 certbot -nginx 这步出错,则执行
pip install --upgrade --force-reinstall 'requests==2.6.0' urllib3
重新执行 certbot --nginx
- 配置自动更新证书
certbot renew --dry-run
- 测试浏览器使用https形式访问是否成功
CentOS下MySQL忘记root密码解决方法【成功手动修改了密码password 都是泪】
-
首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库。 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录和修改MySQL的信息。可以采用将MySQL对 外的端口封闭,并且停止Apache以及所有的用户进程的方法实现服务器的准安全 状态。最安全的状态是到服务器的Console上面操作,并且拔掉网线。
-
修改MySQL的登录设置:
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存并且退出vi
- 重新启动mysqld
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
- 登录并修改MySQL的root密码
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> USE mysql ;
Database changed
mysql> update user set authentication_string=password(‘new-password’) where User='root’;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
4.将MySQL的登录设置修改回来
# vim /etc/my.cnf
将刚才在[mysqld]的段中加上的skip-grant-tables删除
保存并且退出vim
5.重新启动mysqld
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
centos下彻底删除MYSQL 和重新安装MYSQL
发现密码无法设置
- 删除Mysql
yum remove mysql mysql-server mysql-libs mysql-server;
find / -name mysql// 将找到的相关东西delete掉;
rpm -qa|grep mysql//(查询出来的东东yum remove掉)
- 安装Mysql
yum install mysql mysql-server mysql-libs mysql-server;
linux下mysql开启远程访问权限及防火墙开放3306端口
开启mysql的远程访问权限
默认mysql的用户是没有远程访问的权限的,因此当程序跟数据库不在同一台服务器上时,我们需要开启mysql的远程访问权限。
主流的有两种方法,改表法和授权法。
相对而言,改表法比较容易一点,个人也是比较倾向于使用这种方法,因此,这里只贴出改表法
1、登陆mysql
mysql -u root -p
2、修改mysql库的user表,将host项,从localhost改为%。%这里表示的是允许任意host访问,如果只允许某一个ip访问,则可改为相应的ip,比如可以将localhost改为192.168.1.123,这表示只允许局域网的192.168.1.123这个ip远程访问mysql。
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> select host, user from user;
mysql> flush privileges;
防火墙开放3306端口
- 1、打开防火墙配置文件
vi /etc/sysconfig/iptables
- 2、增加下面一行
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
- 3、重启防火墙
service iptables restart
==注意:增加的开放3306端口的语句一定要在icmp-host-prohibited之前==
附:个人配置
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -i lo -j ACCEPT
-A FORWARD -i eth0 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT