Swift Perfect 服务器配置(Ubuntu16.0.4 主机、虚拟机)

Mac 开发环境

brew install mysql@5.7 && brew link mysql@5.7 --force
mysql.server start
mysql_secure_installation mysql
-uroot -p (默认密码为空,直接回车) alter user 'root'@'localhost' identified by '新密码';(MySQL 5.7.6 and later)

Ubuntu 16.0.4 Swift环境配置 (下载对应环境 https://swift.org/download/ Toolchain)

#.bashrc

export SWIFT_HOME=/opt/swift
export PATH=$SWIFT_HOME/usr/bin:$PATH

# source .bashrc
sudo apt-get install mysql-server mysql-client libmysqlclient-dev clang libcurl3 openssl libssl-dev uuid-dev libpython2.7-dev supervisor pkg-config libcurl4-openssl-dev

Ubuntu 16.0.4 MySQL数据库配置

基础命令:service mysql restart | service mysql start | service mysql stop

sudo mysql_secure_installation

配置项较多,如下所示:

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)

#2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)

#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)

#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)

#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)

#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项) 

检查mysql服务状态:

systemctl status mysql.service

显示如下结果说明mysql服务是正常的:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Tue 2019-05-07 14:14:23 CST; 13min ago
 Main PID: 18542 (mysqld)
    Tasks: 29 (limit: 2319)
   CGroup: /system.slice/mysql.service
           └─18542 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pi

May 07 14:14:23 fileplay-ecs-3445 systemd[1]: Starting MySQL Community Server...
May 07 14:14:23 fileplay-ecs-3445 systemd[1]: Started MySQL Community Server.

新增用户并开启远程连接

 1 1、首先用root用户登录mysql
 2 sudo mysql -u root -p
 3 
 4 2、新建用户
 5 use mysql;
 6 select host,user from user;(查看现有用户)
 7 CREATE USER 'king'@'localhost' IDENTIFIED BY '123456';(新建用户)
 8 flush privileges;
 9 select host,user from user;(再次查看用户)
10   
11 3、赋权限
12 CREATE USER 'king'@'localhost' IDENTIFIED BY 'mypass';
13 CREATE USER 'king'@'%' IDENTIFIED BY 'mypass';
14 
15 GRANT ALL ON *.* TO 'king'@'localhost';
16 GRANT ALL ON *.* TO 'king'@'%';
17 
18 flush privileges;

$sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

这里我们注释掉这一行 #bind-address = 127.0.0.1

重启mysql
service mysql restart

mysql增大超时时间(24小时,需重启)

interactive_timeout=86400
wait_timeout=86400

mysql插入数据支持中文

#
[client]
default-character-set=utf8

[mysql]
no-auto-rehash
default-character-set=utf8

[mysqld]
character-set-server=utf8
init_connect='SET NAMES utf8'

Mysql频繁出现 Mysql mysql lost connection to server during query(同时解决设置utf8后,异端无法用utf8查看数据库【中文乱码】)

[mysqld]
skip-name-resolve

Supervisor让服务器项目后台运行

apt-get install supervisor

#没有
/etc/supervisor/supervisord.conf文件,可按此方法生成

echo_supervisord_conf > /etc/supervisor/supervisord.conf
#修改supervisor配置文件 /etc/supervisor/supervisord.conf #移至文件内容结尾 去掉 [include] 前面;
files = /etc/supervisor/conf.d/*.conf
1 # script.sh 执行脚本,进入代码路径,执行命令
2 
3 cd /root/Code/PerfectTemplate
4 .build/debug/PerfectTemplate 
# cd /etc/supervisor/conf.d, 创建并编辑 vim swiftServer.conf, swiftServer是我的文件名和program名
# ; 一定一定不能少

[program:swiftServer] ; //  program name
file=/tmp/supervisor.sock ; 
command=sh script.sh ; // script name
process_name=%(program_name)s ; 
directory=/opt ; // script path
autorestart=unexpected ; //当进程意外被kill或出现异常时,Supervisor会自动重启该进程。
user=root ; // user name
[supervisord]
[supervisorctl]

输入supervisord -c /etc/supervisord.conf让你刚刚的配置生效.

输入supervisorctl start swiftServer启动并后台运行

输入supervisorctl status查询状态

supervisor 自启动

创建/usr/lib/systemd/system/supervisord.service文件;
写入:

# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

systemctl enable supervisord

验证一下是否为开机启动:systemctl is-enabled supervisord

supervisor 定期启动应用

 

posted @ 2019-05-07 11:57  doubletcjs  阅读(349)  评论(0编辑  收藏  举报