在一个云主机centos 7上布署线上环境和开发开发两套审核平台。
git clone https://github.com/cookieY/Yearning.git
yum install docker docker-compose -y
目录说明:
db_data:存放mysql数据文件;
docker:存放配置文件
init-sql:存放初始化SQL
#tree
├── db_data /#存放数据文件
├── docker
│ ├── etc
│ │ └── mysql /#存放数据库配置文件
│ │ └── my.cnf
│ ├── logs
│ └── src /#存放程序配置文件
│ ├── app_dev.js
│ ├── app_prod.js
│ ├── gunicorn_dev.conf
│ ├── gunicorn_prod.conf
│ └── start_yearning.sh
├── docker-compose.yml
└── init-sql /#存放初始化sql脚本
└── install.sql
docker-compose文件配置:
#cat docker-compose
version: '2'
services:
db:
image: mysql:5.7
volumes:
- ./docker/etc/mysql/:/etc/mysql/conf.d/
- ./db_data/:/var/lib/mysql/
- ./init-sql/:/docker-entrypoint-initdb.d/
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: F4rtC7gR
注意事项:
Starting yearningdockercompose_db_1 ... done
Recreating yearningdockercompose_yearning_dev_1 ...
Recreating yearningdockercompose_yearning_dev_1 ... done
Attaching to yearningdockercompose_db_1, yearningdockercompose_yearning_prod_1, yearningdockercompose_yearning_dev_1
db_1 | 2018-10-23T14:03:54.283527Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2018-10-23T14:03:54.286060Z 0 [Note] mysqld (mysqld 5.7.23) starting as process 1 ...
db_1 | 2018-10-23T14:03:54.290775Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1 | 2018-10-23T14:03:54.290817Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2018-10-23T14:03:54.290825Z 0 [Note] InnoDB: Uses event mutexes
db_1 | 2018-10-23T14:03:54.290833Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1 | 2018-10-23T14:03:54.290840Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
db_1 | 2018-10-23T14:03:54.290847Z 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2018-10-23T14:03:54.291209Z 0 [Note] InnoDB: Number of pools: 1
db_1 | 2018-10-23T14:03:54.291365Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1 | 2018-10-23T14:03:54.293645Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1 | 2018-10-23T14:03:54.305775Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2018-10-23T14:03:54.308258Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1 | 2018-10-23T14:03:54.320987Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1 | 2018-10-23T14:03:54.339834Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2018-10-23T14:03:54.339911Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1 | 2018-10-23T14:03:54.417815Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1 | 2018-10-23T14:03:54.418814Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1 | 2018-10-23T14:03:54.418834Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1 | 2018-10-23T14:03:54.419989Z 0 [Note] InnoDB: Waiting for purge to start
db_1 | 2018-10-23T14:03:54.470171Z 0 [Note] InnoDB: 5.7.23 started; log sequence number 13026725
db_1 | 2018-10-23T14:03:54.470406Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2018-10-23T14:03:54.470659Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1 | 2018-10-23T14:03:54.474343Z 0 [Note] InnoDB: Buffer pool(s) load completed at 181023 14:03:54
db_1 | 2018-10-23T14:03:54.479744Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1 | 2018-10-23T14:03:54.480011Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2018-10-23T14:03:54.482673Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1 | 2018-10-23T14:03:54.482737Z 0 [Note] IPv6 is available.
db_1 | 2018-10-23T14:03:54.482750Z 0 [Note] - '::' resolves to '::';
db_1 | 2018-10-23T14:03:54.482789Z 0 [Note] Server socket created on IP: '::'.
db_1 | 2018-10-23T14:03:54.486406Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2018-10-23T14:03:54.496680Z 0 [Note] Event Scheduler: Loaded 0 events
db_1 | 2018-10-23T14:03:54.496960Z 0 [Note] mysqld: ready for connections.
db_1 | Version: '5.7.23' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
yearning_prod_1 | [2018-10-23 22:03:54 +0800] [18] [INFO] Starting gunicorn 19.8.1
yearning_prod_1 | [2018-10-23 22:03:54 +0800] [18] [INFO] Listening at: http://0.0.0.0:8000 (18)
yearning_prod_1 | [2018-10-23 22:03:54 +0800] [18] [INFO] Using worker: sync
yearning_prod_1 | [2018-10-23 22:03:54 +0800] [20] [INFO] Booting worker with pid: 20
yearning_dev_1 | [2018-10-23 22:03:54 +0800] [18] [INFO] Starting gunicorn 19.8.1
yearning_dev_1 | [2018-10-23 22:03:54 +0800] [18] [INFO] Listening at: http://0.0.0.0:8000 (18)
yearning_dev_1 | [2018-10-23 22:03:54 +0800] [18] [INFO] Using worker: sync
yearning_dev_1 | [2018-10-23 22:03:54 +0800] [20] [INFO] Booting worker with pid: 20
yearning_dev_1 | [2018-10-23 22:03:54 +0800] [21] [INFO] Booting worker with pid: 21
yearning_prod_1 | [2018-10-23 22:03:55 +0800] [21] [INFO] Booting worker with pid: 21
(线上)http://x.x.x.x:9080(开发)http://x.x.x.x:8080
在install/inception.tar解压,配置bin目录下的inc.cnf文件,分别修改inc_dev.cnf,inc_prod.cnf的配置文件。
[root@izbp18o219vg69uwg7d2dnz inception]# tree
.
├── bin
│ ├── inc.cnf
│ ├── inc_dev.cnf
│ ├── Inception
│ ├── inc_prod.cnf
│ └── mysql
.....
[root@izbp18o219vg69uwg7d2dnz bin]# cat inc_dev.cnf
[inception]
general_log=1
general_log_file=inception_dev.log
port=7669
socket=/tmp/inc_dev.socket
character-set-client-handshake=0
character-set-server=utf8
inception_support_charset=utf8mb4
inception_enable_nullable=0
inception_check_primary_key=1
inception_check_column_comment=1
inception_check_table_comment=1
inception_enable_blob_type=1
inception_check_column_default_value=1
inception_support_charset=utf8
inception_osc_on=OFF
inception_check_column_default_value=OFF
inception_check_column_comment=OFF
inception_check_table_comment=OFF
inception_enable_identifer_keyword=ON
inception_remote_backup_host = 127.0.0.1
inception_remote_backup_port = 3306
inception_remote_system_user = root
inception_remote_system_password = F4rtC7gR
启动inception:
sh Yearning.sh 按1
cat Yearning.sh
# Network
ping -c 1 -W 3 www.baidu.com &> /dev/null
if [ ! $? = 0 ];then
echo "Cannot be networked"
exit 1
fi
echo "
-------------------------------------------
|
1: Restart all Inception services |
|
-------------------------------------------
"
# Set PATH Variables
export PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/root/bin
BASE_DIR=$(cd "$(dirname "$0")";pwd)
# Set output color
COLUMENS=80
SPACE_COL=$[ $COLUMENS-21 ]
VERSION=`uname -r | awk -F'.' '{print $1}'`
RED='\033[1;5;31m'
GREEN='\033[1;32m'
NORMAL='\033[0m'
success() {
REAL_SPACE=$[ $SPACE_COL - ${#1} ]
for i in `seq 1 $REAL_SPACE`; do
echo -n " "
done
echo -e "[ ${GREEN}SUCCESS${NORMAL} ]"
}
failure() {
REAL_SPACE=$[ $SPACE_COL - ${#1} ]
for i in `seq 1 $REAL_SPACE`; do
echo -n " "
done
echo -e "[ ${RED}FAILURE${NORMAL} ]"
exit 1
}
help() {
echo "Please enter a valid serial number"
}
restart() {
Data="01) Restart Inception"
echo -n $Data
netstat -nltp | grep ":6669"|awk '{print $7}'|awk -F "/" '{print $1}' | xargs kill -9 &> /dev/null
netstat -nltp | grep ":7669"|awk '{print $7}'|awk -F "/" '{print $1}' | xargs kill -9 &> /dev/null
#ps aux | grep Inception | grep -v grep | awk '{print $2}' | xargs kill -9 &> /dev/null
nohup $BASE_DIR/install/inception/bin/Inception --defaults-file=$BASE_DIR/install/inception/bin/inc_dev.cnf > $BASE_DIR/logs/inception_dev.log 2>&1 &
nohup $BASE_DIR/install/inception/bin/Inception --defaults-file=$BASE_DIR/install/inception/bin/inc_prod.cnf > $BASE_DIR/logs/inception_prod.log 2>&1 &
if [ $? = 0 ];then
success "$Data"
else
failure "$Data"
fi
sleep 1
}
read -p "Please select enter a valid sequence number: " NUMBER
echo
case "$NUMBER" in
1)
restart
;;
*)
help
exit 1
esac
1)docker-compose stop 关容器服务
2)docker-compose restart 重启容器服务
3)docker-compose ps 查看容器服务
4)docker ps docker exec docker exec 查看某一个容器运行时情况
在/etc/nginx/conf.d/添加devsql.conf,prodsql.conf两个文件:
#cat /etc/nginx/conf.d/devsql.conf
# A virtual host using mix of IP-, name-, and port-based configuration
#
server {
#add_header 'Access-Control-Allow-Origin' '*';
#add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept';
#add_header 'Access-Control-Allow-Methods' "GET,POST,PUT,DELETE,OPTIONS";
listen 80;
server_name a1.abc.com;
location / {
proxy_pass http://172.16.0.49:9080;
}
location ~ ^/api {
proxy_pass http://172.16.0.49:9000;
}
}
#cat /etc/nginx/conf.d/prodsql.conf
# A virtual host using mix of IP-, name-, and port-based configuration
#
server {
#add_header 'Access-Control-Allow-Origin' '*';
#add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept';
#add_header 'Access-Control-Allow-Methods' "GET,POST,PUT,DELETE,OPTIONS";
listen 80;
server_name a1.abc.com;
location / {
proxy_pass http://172.16.0.49:8080;
}
location ~ ^/api {
proxy_pass http://172.16.0.49:8000;
}
}
#systemctl start nginx
backup_dbname:这个列表示的是当前语句产生的备份信息,存储在备份服务器的哪个数据库中,这是一个字符串类型的值,只针对需要备份的语句,数据库名由IP地址、端口、源数据库名组成,由下划线连接,而如果是不需要备份的语句,则返回字符串None。
mysql 数据库名称长度不能超过64字符!!!!!!