創建數據庫 renren_fast ,而後運行renrenfast項目中的db文件夾內的腳本html
-- 菜單 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,JWTjava
單點登陸:只需登陸微服務的任一節點,訪問其它微服務節點時便無需再重複登陸。
JWT:不在session裏面保存認證與受權信息,而是保存在客戶端瀏覽器上,訪問某個節點時發送認證信息,後端認證令牌信息成功後就認爲登陸成功了。
注意後端項目是SpringBoot項目,須要在Eclipse中安裝Spring Tools插件
修改 application-dev.yml 的數據庫配置,鏈接以前配好的數據庫集羣的虛擬IP:node
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集羣:mysql
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:ios
未來項目要部署到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
進入renren-fast目錄,執行mvn命令nginx
mvn clean install -Dmaven.test.skep=true # 跳過測試代碼 # clean :表示清除以前的JAR文件; # install :意味着打包到本地; # -Dmaven.test.skip=true :表明跳過測試代碼
打包成功後,會在項目根目錄的 target 文件夾下生成 renren-fast.jar git
docker volume create j1 ls /var/lib/docker/volumes/j1/_data renren-fast.jar
後端Jar包運行須要Java環境,從Docker倉庫拉下java
鏡像,而後執行以下指令建立容器:redis
docker run -it -d -v j1:/home/soft --net=host --name j1 java
進入j1
容器Jar包所在目錄,執行以下命令使後端項目在關閉終端時不掛斷(nohup)而且在後臺運行(&):spring
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 來測試後端接口sql
個人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是性能很是出色的反向代理服務器,最大能夠支持8萬/秒的併發訪問
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
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
參考以前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即表明成功