Docker环境下的前后端分离项目部署与运维(九)后端项目部署与负载均衡
数据库准备
建立数据库 renren_fast ,然后运行renrenfast项目中的db文件夹内的脚本
-- 菜单 CREATE TABLE `sys_menu` ( `menu_id` bigint NOT NULL AUTO_INCREMENT, `parent_id` bigint COMMENT '父菜单ID,一级菜单为0', `name` varchar(50) COMMENT '菜单名称', `url` varchar(200) COMMENT '菜单URL', `perms` varchar(500) COMMENT '授权(多个用逗号分隔,如:user:list,user:create)', `type` int COMMENT '类型 0:目录 1:菜单 2:按钮', `icon` varchar(50) COMMENT '菜单图标', `order_num` int COMMENT '排序', PRIMARY KEY (`menu_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='菜单管理'; -- 系统用户 CREATE TABLE `sys_user` ( `user_id` bigint NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL COMMENT '用户名', `password` varchar(100) COMMENT '密码', `salt` varchar(20) COMMENT '盐', `email` varchar(100) COMMENT '邮箱', `mobile` varchar(100) COMMENT '手机号', `status` tinyint COMMENT '状态 0:禁用 1:正常', `create_user_id` bigint(20) COMMENT '创建者ID', `create_time` datetime COMMENT '创建时间', PRIMARY KEY (`user_id`), UNIQUE INDEX (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统用户'; -- 系统用户Token CREATE TABLE `sys_user_token` ( `user_id` bigint(20) NOT NULL, `token` varchar(100) NOT NULL COMMENT 'token', `expire_time` datetime DEFAULT NULL COMMENT '过期时间', `update_time` datetime DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`user_id`), UNIQUE KEY `token` (`token`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统用户Token'; -- 系统验证码 CREATE TABLE `sys_captcha` ( `uuid` char(36) NOT NULL COMMENT 'uuid', `code` varchar(6) NOT NULL COMMENT '验证码', `expire_time` datetime DEFAULT NULL COMMENT '过期时间', PRIMARY KEY (`uuid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统验证码'; -- 角色 CREATE TABLE `sys_role` ( `role_id` bigint NOT NULL AUTO_INCREMENT, `role_name` varchar(100) COMMENT '角色名称', `remark` varchar(100) COMMENT '备注', `create_user_id` bigint(20) COMMENT '创建者ID', `create_time` datetime COMMENT '创建时间', PRIMARY KEY (`role_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色'; -- 用户与角色对应关系 CREATE TABLE `sys_user_role` ( `id` bigint NOT NULL AUTO_INCREMENT, `user_id` bigint COMMENT '用户ID', `role_id` bigint COMMENT '角色ID', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户与角色对应关系'; -- 角色与菜单对应关系 CREATE TABLE `sys_role_menu` ( `id` bigint NOT NULL AUTO_INCREMENT, `role_id` bigint COMMENT '角色ID', `menu_id` bigint COMMENT '菜单ID', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色与菜单对应关系'; -- 系统配置信息 CREATE TABLE `sys_config` ( `id` bigint NOT NULL AUTO_INCREMENT, `key` varchar(50) COMMENT 'key', `value` varchar(2000) COMMENT 'value', `status` tinyint DEFAULT 1 COMMENT '状态 0:隐藏 1:显示', `remark` varchar(500) COMMENT '备注', PRIMARY KEY (`id`), UNIQUE INDEX (`key`) ) ENGINE=`InnoDB` DEFAULT CHARACTER SET utf8 COMMENT='系统配置信息表'; -- 系统日志 CREATE TABLE `sys_log` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `username` varchar(50) COMMENT '用户名', `operation` varchar(50) COMMENT '用户操作', `method` varchar(200) COMMENT '请求方法', `params` varchar(5000) COMMENT '请求参数', `time` bigint NOT NULL COMMENT '执行时长(毫秒)', `ip` varchar(64) COMMENT 'IP地址', `create_date` datetime COMMENT '创建时间', PRIMARY KEY (`id`) ) ENGINE=`InnoDB` DEFAULT CHARACTER SET utf8 COMMENT='系统日志'; -- 初始数据 INSERT INTO `sys_user` (`user_id`, `username`, `password`, `salt`, `email`, `mobile`, `status`, `create_user_id`, `create_time`) VALUES ('1', 'admin', '9ec9750e709431dad22365cabc5c625482e574c74adaebba7dd02f1129e4ce1d', 'YzcmCZNvbXocrsz9dm8e', 'root@renren.io', '13612345678', '1', '1', '2016-11-11 11:11:11'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('1', '0', '系统管理', NULL, NULL, '0', 'fa fa-cog', '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('2', '1', '管理员列表', 'modules/sys/user.html', NULL, '1', 'fa fa-user', '1'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('3', '1', '角色管理', 'modules/sys/role.html', NULL, '1', 'fa fa-user-secret', '2'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('4', '1', '菜单管理', 'modules/sys/menu.html', NULL, '1', 'fa fa-th-list', '3'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('5', '1', 'SQL监控', 'druid/sql.html', NULL, '1', 'fa fa-bug', '4'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('15', '2', '查看', NULL, 'sys:user:list,sys:user:info', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('16', '2', '新增', NULL, 'sys:user:save,sys:role:select', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('17', '2', '修改', NULL, 'sys:user:update,sys:role:select', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('18', '2', '删除', NULL, 'sys:user:delete', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('19', '3', '查看', NULL, 'sys:role:list,sys:role:info', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('20', '3', '新增', NULL, 'sys:role:save,sys:menu:list', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('21', '3', '修改', NULL, 'sys:role:update,sys:menu:list', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('22', '3', '删除', NULL, 'sys:role:delete', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('23', '4', '查看', NULL, 'sys:menu:list,sys:menu:info', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('24', '4', '新增', NULL, 'sys:menu:save,sys:menu:select', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('25', '4', '修改', NULL, 'sys:menu:update,sys:menu:select', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('26', '4', '删除', NULL, 'sys:menu:delete', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('27', '1', '参数管理', 'modules/sys/config.html', 'sys:config:list,sys:config:info,sys:config:save,sys:config:update,sys:config:delete', '1', 'fa fa-sun-o', '6'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('29', '1', '系统日志', 'modules/sys/log.html', 'sys:log:list', '1', 'fa fa-file-text-o', '7'); -- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- 云存储服务相关SQL,如果不使用该功能,则不用执行下面SQL ------------------------------------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- 文件上传 CREATE TABLE `sys_oss` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `url` varchar(200) COMMENT 'URL地址', `create_date` datetime COMMENT '创建时间', PRIMARY KEY (`id`) ) ENGINE=`InnoDB` DEFAULT CHARACTER SET utf8 COMMENT='文件上传'; INSERT INTO `sys_config` (`key`, `value`, `status`, `remark`) VALUES ('CLOUD_STORAGE_CONFIG_KEY', '{\"aliyunAccessKeyId\":\"\",\"aliyunAccessKeySecret\":\"\",\"aliyunBucketName\":\"\",\"aliyunDomain\":\"\",\"aliyunEndPoint\":\"\",\"aliyunPrefix\":\"\",\"qcloudBucketName\":\"\",\"qcloudDomain\":\"\",\"qcloudPrefix\":\"\",\"qcloudSecretId\":\"\",\"qcloudSecretKey\":\"\",\"qiniuAccessKey\":\"NrgMfABZxWLo5B-YYSjoE8-AZ1EISdi1Z3ubLOeZ\",\"qiniuBucketName\":\"ios-app\",\"qiniuDomain\":\"http://7xqbwh.dl1.z0.glb.clouddn.com\",\"qiniuPrefix\":\"upload\",\"qiniuSecretKey\":\"uIwJHevMRWU0VLxFvgy0tAcOdGqasdtVlJkdy6vV\",\"type\":1}', '0', '云存储配置信息'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('30', '1', '文件上传', 'modules/oss/oss.html', 'sys:oss:all', '1', 'fa fa-file-image-o', '6'); -- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- APP接口相关SQL,如果不使用该功能,则不用执行下面SQL ------------------------------------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- 用户表 CREATE TABLE `tb_user` ( `user_id` bigint NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL COMMENT '用户名', `mobile` varchar(20) NOT NULL COMMENT '手机号', `password` varchar(64) COMMENT '密码', `create_time` datetime COMMENT '创建时间', PRIMARY KEY (`user_id`), UNIQUE INDEX (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户'; -- 账号:13612345678 密码:admin INSERT INTO `tb_user` (`username`, `mobile`, `password`, `create_time`) VALUES ('mark', '13612345678', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', '2017-03-23 22:37:41'); -- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- 定时任务相关表结构,如果不使用该功能,则不用执行下面SQL ------------------------------------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- 初始化菜单数据 INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('6', '1', '定时任务', 'modules/job/schedule.html', NULL, '1', 'fa fa-tasks', '5'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('7', '6', '查看', NULL, 'sys:schedule:list,sys:schedule:info', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('8', '6', '新增', NULL, 'sys:schedule:save', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('9', '6', '修改', NULL, 'sys:schedule:update', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('10', '6', '删除', NULL, 'sys:schedule:delete', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('11', '6', '暂停', NULL, 'sys:schedule:pause', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('12', '6', '恢复', NULL, 'sys:schedule:resume', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('13', '6', '立即执行', NULL, 'sys:schedule:run', '2', NULL, '0'); INSERT INTO `sys_menu` (`menu_id`, `parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) VALUES ('14', '6', '日志列表', NULL, 'sys:schedule:log', '2', NULL, '0'); -- 定时任务 CREATE TABLE `schedule_job` ( `job_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '任务id', `bean_name` varchar(200) DEFAULT NULL COMMENT 'spring bean名称', `method_name` varchar(100) DEFAULT NULL COMMENT '方法名', `params` varchar(2000) DEFAULT NULL COMMENT '参数', `cron_expression` varchar(100) DEFAULT NULL COMMENT 'cron表达式', `status` tinyint(4) DEFAULT NULL COMMENT '任务状态 0:正常 1:暂停', `remark` varchar(255) DEFAULT NULL COMMENT '备注', `create_time` datetime DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`job_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='定时任务'; -- 定时任务日志 CREATE TABLE `schedule_job_log` ( `log_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '任务日志id', `job_id` bigint(20) NOT NULL COMMENT '任务id', `bean_name` varchar(200) DEFAULT NULL COMMENT 'spring bean名称', `method_name` varchar(100) DEFAULT NULL COMMENT '方法名', `params` varchar(2000) DEFAULT NULL COMMENT '参数', `status` tinyint(4) NOT NULL COMMENT '任务状态 0:成功 1:失败', `error` varchar(2000) DEFAULT NULL COMMENT '失败信息', `times` int(11) NOT NULL COMMENT '耗时(单位:毫秒)', `create_time` datetime DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`log_id`), KEY `job_id` (`job_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='定时任务日志'; INSERT INTO `schedule_job` (`bean_name`, `method_name`, `params`, `cron_expression`, `status`, `remark`, `create_time`) VALUES ('testTask', 'test', 'renren', '0 0/30 * * * ?', '0', '有参数测试', '2016-12-01 23:16:46'); INSERT INTO `schedule_job` (`bean_name`, `method_name`, `params`, `cron_expression`, `status`, `remark`, `create_time`) VALUES ('testTask', 'test2', NULL, '0 0/30 * * * ?', '1', '无参数测试', '2016-12-03 14:55:56'); -- quartz自带表结构 CREATE TABLE QRTZ_JOB_DETAILS( SCHED_NAME VARCHAR(120) NOT NULL, JOB_NAME VARCHAR(200) NOT NULL, JOB_GROUP VARCHAR(200) NOT NULL, DESCRIPTION VARCHAR(250) NULL, JOB_CLASS_NAME VARCHAR(250) NOT NULL, IS_DURABLE VARCHAR(1) NOT NULL, IS_NONCONCURRENT VARCHAR(1) NOT NULL, IS_UPDATE_DATA VARCHAR(1) NOT NULL, REQUESTS_RECOVERY VARCHAR(1) NOT NULL, JOB_DATA BLOB NULL, PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_TRIGGERS ( SCHED_NAME VARCHAR(120) NOT NULL, TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, JOB_NAME VARCHAR(200) NOT NULL, JOB_GROUP VARCHAR(200) NOT NULL, DESCRIPTION VARCHAR(250) NULL, NEXT_FIRE_TIME BIGINT(13) NULL, PREV_FIRE_TIME BIGINT(13) NULL, PRIORITY INTEGER NULL, TRIGGER_STATE VARCHAR(16) NOT NULL, TRIGGER_TYPE VARCHAR(8) NOT NULL, START_TIME BIGINT(13) NOT NULL, END_TIME BIGINT(13) NULL, CALENDAR_NAME VARCHAR(200) NULL, MISFIRE_INSTR SMALLINT(2) NULL, JOB_DATA BLOB NULL, PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP) REFERENCES QRTZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_SIMPLE_TRIGGERS ( SCHED_NAME VARCHAR(120) NOT NULL, TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, REPEAT_COUNT BIGINT(7) NOT NULL, REPEAT_INTERVAL BIGINT(12) NOT NULL, TIMES_TRIGGERED BIGINT(10) NOT NULL, PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_CRON_TRIGGERS ( SCHED_NAME VARCHAR(120) NOT NULL, TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, CRON_EXPRESSION VARCHAR(120) NOT NULL, TIME_ZONE_ID VARCHAR(80), PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_SIMPROP_TRIGGERS ( SCHED_NAME VARCHAR(120) NOT NULL, TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, STR_PROP_1 VARCHAR(512) NULL, STR_PROP_2 VARCHAR(512) NULL, STR_PROP_3 VARCHAR(512) NULL, INT_PROP_1 INT NULL, INT_PROP_2 INT NULL, LONG_PROP_1 BIGINT NULL, LONG_PROP_2 BIGINT NULL, DEC_PROP_1 NUMERIC(13,4) NULL, DEC_PROP_2 NUMERIC(13,4) NULL, BOOL_PROP_1 VARCHAR(1) NULL, BOOL_PROP_2 VARCHAR(1) NULL, PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_BLOB_TRIGGERS ( SCHED_NAME VARCHAR(120) NOT NULL, TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, BLOB_DATA BLOB NULL, PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), INDEX (SCHED_NAME,TRIGGER_NAME, TRIGGER_GROUP), FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_CALENDARS ( SCHED_NAME VARCHAR(120) NOT NULL, CALENDAR_NAME VARCHAR(200) NOT NULL, CALENDAR BLOB NOT NULL, PRIMARY KEY (SCHED_NAME,CALENDAR_NAME)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS ( SCHED_NAME VARCHAR(120) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_FIRED_TRIGGERS ( SCHED_NAME VARCHAR(120) NOT NULL, ENTRY_ID VARCHAR(95) NOT NULL, TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, INSTANCE_NAME VARCHAR(200) NOT NULL, FIRED_TIME BIGINT(13) NOT NULL, SCHED_TIME BIGINT(13) NOT NULL, PRIORITY INTEGER NOT NULL, STATE VARCHAR(16) NOT NULL, JOB_NAME VARCHAR(200) NULL, JOB_GROUP VARCHAR(200) NULL, IS_NONCONCURRENT VARCHAR(1) NULL, REQUESTS_RECOVERY VARCHAR(1) NULL, PRIMARY KEY (SCHED_NAME,ENTRY_ID)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_SCHEDULER_STATE ( SCHED_NAME VARCHAR(120) NOT NULL, INSTANCE_NAME VARCHAR(200) NOT NULL, LAST_CHECKIN_TIME BIGINT(13) NOT NULL, CHECKIN_INTERVAL BIGINT(13) NOT NULL, PRIMARY KEY (SCHED_NAME,INSTANCE_NAME)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE QRTZ_LOCKS ( SCHED_NAME VARCHAR(120) NOT NULL, LOCK_NAME VARCHAR(40) NOT NULL, PRIMARY KEY (SCHED_NAME,LOCK_NAME)) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE INDEX IDX_QRTZ_J_REQ_RECOVERY ON QRTZ_JOB_DETAILS(SCHED_NAME,REQUESTS_RECOVERY); CREATE INDEX IDX_QRTZ_J_GRP ON QRTZ_JOB_DETAILS(SCHED_NAME,JOB_GROUP); CREATE INDEX IDX_QRTZ_T_J ON QRTZ_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP); CREATE INDEX IDX_QRTZ_T_JG ON QRTZ_TRIGGERS(SCHED_NAME,JOB_GROUP); CREATE INDEX IDX_QRTZ_T_C ON QRTZ_TRIGGERS(SCHED_NAME,CALENDAR_NAME); CREATE INDEX IDX_QRTZ_T_G ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP); CREATE INDEX IDX_QRTZ_T_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE); CREATE INDEX IDX_QRTZ_T_N_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE); CREATE INDEX IDX_QRTZ_T_N_G_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE); CREATE INDEX IDX_QRTZ_T_NEXT_FIRE_TIME ON QRTZ_TRIGGERS(SCHED_NAME,NEXT_FIRE_TIME); CREATE INDEX IDX_QRTZ_T_NFT_ST ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME); CREATE INDEX IDX_QRTZ_T_NFT_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME); CREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE); CREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE_GRP ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE); CREATE INDEX IDX_QRTZ_FT_TRIG_INST_NAME ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME); CREATE INDEX IDX_QRTZ_FT_INST_JOB_REQ_RCVRY ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY); CREATE INDEX IDX_QRTZ_FT_J_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP); CREATE INDEX IDX_QRTZ_FT_JG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_GROUP); CREATE INDEX IDX_QRTZ_FT_T_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP); CREATE INDEX IDX_QRTZ_FT_TG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);
后端项目
后端项目为开源项目renren-fast
使用到的技术有:SpringBoot,Shiro,Redis,SSM,Swagger,JWT
单点登录:只需登录微服务的任一节点,访问其它微服务节点时便无需再重复登录。
JWT:不在session里面保存认证与授权信息,而是保存在客户端浏览器上,访问某个节点时发送认证信息,后端认证令牌信息成功后就认为登录成功了。
后端项目部署
- 从后端项目网址下载项目,并导入到Eclipse当中,具体流程参加官方文档
注意后端项目是SpringBoot项目,需要在Eclipse中安装Spring Tools插件
-
修改 application-dev.yml 的数据库配置,连接之前配好的数据库集群的虚拟IP:
first: #数据源1 url: jdbc:mysql://192.168.63.160:3306/renren_fast?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 username: root password: abc123456 second: #数据源2 url: jdbc:mysql://192.168.63.160:3306/renren_fast?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 username: root password: abc123456
-
修改 application.yml 文件中的redis配置,连接之前配好的Redis集群:
redis: open: false # 是否开启redis缓存 true开启 false关闭 database: 0 # host: localhost # port: 6379 # password: Nannan2017JK # 密码(默认为空) timeout: 6000 # 连接超时时长(毫秒) cluster: nodes: - 192.168.63.144:5001 - 192.168.63.144:5002 - 192.168.63.144:5003 - 192.168.63.144:5004 - 192.168.63.144:5005 - 192.168.63.144:5006
-
修改 application.yml 中的项目端口号为6001:
将来项目要部署到Docker容器中,而Docker内部的网络是不允许跨网段访问的,所以后端项目容器要连接到Docker的host网络,使用宿主机IP。为了避免端口冲突,需要修改端口号。
# Tomcat server: tomcat: uri-encoding: UTF-8 max-threads: 1000 min-spare-threads: 30 port: 6001 connection-timeout: 5000 servlet: context-path: /renren-fast
- 后端项目使用Maven管理项目,在项目根目录使用如下命令打包:
renren-fast包含了tomcat.jar文件,所以工程打包成JAR文件就能独立运行
进入renren-fast目录,执行mvn命令
mvn clean install -Dmaven.test.skep=true # 跳过测试代码 # clean :表示清除之前的JAR文件; # install :意味着打包到本地; # -Dmaven.test.skip=true :代表跳过测试代码
打包成功后,会在项目根目录的 target 文件夹下生成 renren-fast.jar
- 创建Docker卷 j1 ,并将 renren-fast.jar 复制到该目录下,用来在容器中启动该Jar包
docker volume create j1 ls /var/lib/docker/volumes/j1/_data renren-fast.jar
-
后端Jar包运行需要Java环境,从Docker仓库拉下
java
镜像,然后执行如下指令创建容器:docker run -it -d -v j1:/home/soft --net=host --name j1 java
-
进入
j1
容器Jar包所在目录,执行如下命令使后端项目在关闭终端时不挂断(nohup)并且在后台运行(&):docker exec -it j1 bash cd /home/soft nohup java -jar renren-fast.jar &
项目启动成功后便可以通过 http://192.168.63.144:6001/renren-fast/swagger/index.html 来测试后端接口
我的Jar包启动时报如下错误:Couldn't get host name! [See nested exception: java.net.UnknownHostException: wayne: wayne:] 解决办法是进入容器,在/etc/hosts文件中添加一行127.0.0.1 wayne
-
创建负载站点
按照上述方法再在Docker中部署j2(端口6002),j3(端口6003)两个后台项目容器
注意:要修改tomcat配置端口,打包
docker volume create j2 ls /var/lib/docker/volumes/j2/_data renren-fast.jar docker run -it -d -v j2:/home/soft --net=host --name j2 java docker exec -it j2 bash cd /home/soft nohup java -jar renren-fast.jar & docker volume create j3 ls /var/lib/docker/volumes/j3/_data renren-fast.jar docker run -it -d -v j3:/home/soft --net=host --name j3 java docker exec -it j3 bash cd /home/soft nohup java -jar renren-fast.jar &
Nginx负载均衡
Nginx是性能非常出色的反向代理服务器,最大可以支持8万/秒的并发访问
- 拉取Nginx镜像
docker pull nginx
-
创建n1目录
mkdir /home/n1
上传Nginx配置文件 nginx.conf 相关参数
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; 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; keepalive_timeout 65; #gzip on; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 5s; proxy_send_timeout 5s; proxy_read_timeout 5s; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; upstream tomcat { server 192.168.63.144:6001; server 192.168.63.144:6002; server 192.168.63.144:6003; } server { listen 6101; server_name 192.168.63.144; location / { proxy_pass http://tomcat; index index.html index.htm; } } }
-
启动Nginx容器:
# 需要加上--privileged参数,使keepalived能在宿主机网卡注册虚拟IP docker run -it -d -v /home/n1/nginx.conf:/etc/nginx/nginx.conf --net=host --name n1 --privileged nginx
- 按照上述操作再创建一个nginx节点6102端口
mkdir /home/n2 # 拷贝配置文件 # 需要加上--privileged参数,使keepalived能在宿主机网卡注册虚拟IP docker run -it -d -v /home/n2/nginx.conf:/etc/nginx/nginx.conf --net=host --name n2 --privileged nginx
Nginx双机热备
参考之前Haproxy双机热备的方案,仍然采用Keepalived和虚拟IP技术。建立两个Nginx容器并各自安装Keepalived,映射到同一宿主机虚拟IP上
下面是keepalived配置文件示例:
docker exec -it n1 bash apt-get update apt-get install keepalived apt-get install vim vim /etc/keepalived/keepalived.conf # 配置keepalived.conf文件 service keepalived start exit ping 192.168.63.151 docker exec -it n2 bash apt-get update apt-get install keepalived apt-get install vim vim /etc/keepalived/keepalived.conf # 配置keepalived.conf文件 service keepalived start exit ping 192.168.63.151
n1的keepalived.conf文件:
vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.63.151 } } virtual_server 192.168.63.151 6201 { delay_loop 3 lb_algo rr lb_kind NAT persistence_timeout 50 protocol TCP real_server 192.168.63.144 6101 { weight 1 } }
n2的keepalived.conf文件:
vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.63.151 } } virtual_server 192.168.63.151 6201 { delay_loop 3 lb_algo rr lb_kind NAT persistence_timeout 50 protocol TCP real_server 192.168.63.144 6102 { weight 1 } }
然后能成功访问http://192.168.63.151:6201/renren-fast/swagger/index.html即代表成功
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!