| | |
| | | drop table if exists sys_ctrl_log; |
| | | create table sys_ctrl_log ( |
| | | log_id bigint(20) not null auto_increment comment 'æ¥å¿ID', |
| | | title varchar(100) not null comment 'æ é¢', |
| | | type char(1) default '0' comment 'ç±»å', |
| | | tab_id bigint(20) comment '表ID', |
| | | title varchar(200) not null comment 'æ é¢', |
| | | type char(1) comment 'ç±»åï¼n-æ£å¸¸ï¼e-é误ï¼', |
| | | ip varchar(50) comment 'IP', |
| | | url varchar(4000) comment 'URL', |
| | | method varchar(20) comment 'æ¹æ³', |
| | | method varchar(50) comment 'æ¹æ³', |
| | | args varchar(4000) comment 'åæ°', |
| | | msg varchar(2000) comment 'æ¶æ¯', |
| | | oper varchar(50) comment 'æä½å', |
| | | msg varchar(4000) comment 'æ¶æ¯', |
| | | oper varchar(100) comment 'æä½å', |
| | | time datetime default now() comment 'æä½æ¶é´', |
| | | remark varchar(500) default '' comment '夿³¨', |
| | | remark varchar(500) comment '夿³¨', |
| | | primary key (log_id) |
| | | ) engine=innodb auto_increment=1 comment = 'æ§å¶æ¥å¿è¡¨'; |
| | | select * from sys_ctrl_log order by log_id; |
| | |
| | | insert into sys_status_ctrl (sys_name,ip,url,method,order_num) values ('ç¨æ·åæé管ç','127.0.0.1','http://localhost:8080/system/health', 'GET',1); |
| | | insert into sys_status_ctrl (sys_name,ip,url,method,order_num) values ('æ°æ®ç®¡çåç³»ç»','127.0.0.1','http://localhost:8080/gateway/health','GET',2); |
| | | -- ---------------------------- |
| | | |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.common.core.domain; |
| | | |
| | | @SuppressWarnings("ALL") |
| | | public class DockerContainer { |
| | | private String id; |
| | | |
| | | private String name; |
| | | |
| | | /** |
| | | * running,created,exited,paused,restarting,dead,error |
| | | */ |
| | | private String state; |
| | | |
| | | /** |
| | | * redis:latest |
| | | */ |
| | | private String image; |
| | | |
| | | public DockerContainer() { |
| | | } |
| | | |
| | | public DockerContainer(String id, String name, String state, String image) { |
| | | this.id = id; |
| | | this.name = name; |
| | | this.state = state; |
| | | this.image = image; |
| | | } |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getState() { |
| | | return state; |
| | | } |
| | | |
| | | public void setState(String state) { |
| | | this.state = state; |
| | | } |
| | | |
| | | public String getImage() { |
| | | return image; |
| | | } |
| | | |
| | | public void setImage(String image) { |
| | | this.image = image; |
| | | } |
| | | } |
| | |
| | | return R.ok(str); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | return R.fail(); |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | import com.github.dockerjava.api.DockerClient; |
| | | import com.github.dockerjava.api.command.*; |
| | | import com.github.dockerjava.api.model.Container; |
| | | import com.github.dockerjava.api.model.PullResponseItem; |
| | | import com.github.dockerjava.core.DockerClientBuilder; |
| | | import com.se.common.core.domain.DockerContainer; |
| | | import com.se.docker.utils.DockerUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | | public class SysDockerService { |
| | | //@Value("${docker.prefix}") |
| | | public String localFilePrefix; |
| | | @Value("${docker.host}") |
| | | private String host; |
| | | |
| | | @Value("${docker.apiVersion}") |
| | | private String apiVersion; |
| | | |
| | | private static DockerUtils dockerUtils; |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(SysDockerService.class); |
| | | |
| | | public DockerUtils getDockerUtils() { |
| | | if (null == dockerUtils) { |
| | | dockerUtils = new DockerUtils(host, apiVersion); |
| | | } |
| | | |
| | | return dockerUtils; |
| | | } |
| | | |
| | | public String test() throws Exception { |
| | | List<String> names = new ArrayList<>(Arrays.asList("se-redis", "se-mysql", "se-system", "se-wgcloud")); |
| | | List<DockerContainer> list = getContainers(names); |
| | | |
| | | String id = list.get(0).getId(); |
| | | start(id); |
| | | pause(id); |
| | | unpause(id); |
| | | stop(id); |
| | | restart(id); |
| | | |
| | | return "docker: " + System.currentTimeMillis(); |
| | | } |
| | | |
| | | public List<DockerContainer> getContainers(List<String> names) { |
| | | DockerUtils util = getDockerUtils(); |
| | | List<Container> containers = util.listContainers(); |
| | | |
| | | List<DockerContainer> list = new ArrayList<>(); |
| | | for (Container container : containers) { |
| | | if (null == container.getNames() || 0 == container.getNames().length) continue; |
| | | |
| | | String containerName = container.getNames()[0]; |
| | | for (String name : names) { |
| | | if (containerName.contains(name)) { |
| | | list.add(new DockerContainer(container.getId(), containerName, container.getState(), container.getImage())); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public void start(String id) { |
| | | getDockerUtils().start(id); |
| | | } |
| | | |
| | | public void restart(String id) { |
| | | getDockerUtils().restart(id); |
| | | } |
| | | |
| | | public void stop(String id) { |
| | | getDockerUtils().stop(id); |
| | | } |
| | | |
| | | public void pause(String id) { |
| | | getDockerUtils().pause(id); |
| | | } |
| | | |
| | | public void unpause(String id) { |
| | | getDockerUtils().unpause(id); |
| | | } |
| | | |
| | | /** |
| | | * java DockerClientæä½ |
| | | * https://blog.csdn.net/weixin_45198228/article/details/130060333 |
| | |
| | | private DockerUtils() { |
| | | } |
| | | |
| | | private DockerUtils(String dockerHost, String dockerApiVersion, String dockerCertPath) { |
| | | public DockerUtils(String dockerHost, String dockerApiVersion) { |
| | | Objects.requireNonNull(dockerHost, "Docker 主æºå°åä¸è½ä¸ºç©º."); |
| | | Objects.requireNonNull(dockerApiVersion, "Docker API çæ¬ä¸è½ä¸ºç©º."); |
| | | |
| | | // 使ç¨åéæ ¡éªéå®ç° Docker 客æ·ç«¯åä¾ |
| | | if (dockerClient == null) { |
| | | if (null == dockerClient) { |
| | | synchronized (DockerUtils.class) { |
| | | if (dockerClient == null) { |
| | | if (null == dockerClient) { |
| | | dockerClient = createDockerClient(dockerHost, dockerApiVersion); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private DockerClient createDockerClient(String dockerHost, String dockerApiVersion) { |
| | | DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder() |
| | | .withApiVersion(dockerApiVersion) |
| | | .withDockerHost(dockerHost) |
| | | .build(); |
| | | |
| | | DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder() |
| | | .dockerHost(config.getDockerHost()) |
| | | .sslConfig(config.getSSLConfig()) |
| | | .maxConnections(1000) |
| | | .connectionTimeout(Duration.ofSeconds(60)) |
| | | .responseTimeout(Duration.ofMinutes(30)) |
| | | .build(); |
| | | |
| | | return DockerClientImpl.getInstance(config, httpClient); |
| | | } |
| | | |
| | | public DockerUtils(String dockerHost, String dockerApiVersion, String dockerCertPath) { |
| | | Objects.requireNonNull(dockerHost, "Docker 主æºå°åä¸è½ä¸ºç©º."); |
| | | Objects.requireNonNull(dockerApiVersion, "Docker API çæ¬ä¸è½ä¸ºç©º."); |
| | | |
| | | // 使ç¨åéæ ¡éªéå®ç° Docker 客æ·ç«¯åä¾ |
| | | if (null == dockerClient) { |
| | | synchronized (DockerUtils.class) { |
| | | if (null == dockerClient) { |
| | | dockerClient = createDockerClient(dockerHost, dockerApiVersion, dockerCertPath); |
| | | } |
| | | } |
| | |
| | | DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder() |
| | | .withApiVersion(dockerApiVersion) |
| | | .withDockerHost(dockerHost) |
| | | //妿å¼å¯å®å
¨è¿æ¥ï¼éè¦é
ç½®è¿è¡ |
| | | // 妿å¼å¯å®å
¨è¿æ¥ï¼éè¦é
ç½®è¿è¡ |
| | | .withDockerTlsVerify(true).withDockerCertPath(dockerCertPath) |
| | | .build(); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * æ¨ééå |
| | | * |
| | | * @param authConfig |
| | | * @param tag |
| | | */ |
| | | public static void pushImage(AuthConfig authConfig, String tag) { |
| | | Objects.requireNonNull(authConfig, "认è¯ä¿¡æ¯ä¸è½ä¸ºç©º."); |
| | | Objects.requireNonNull(tag, "éåä¿¡æ¯ä¸è½ä¸ºç©º."); |
| | | log.info("å¼å§æ¨é Docker éå: {}", tag); |
| | | try { |
| | | PushImageCmd pushImageCmd = dockerClient.pushImageCmd(tag); |
| | | pushImageCmd.withAuthConfig(authConfig) |
| | | .start() |
| | | .awaitCompletion(30, TimeUnit.SECONDS); |
| | | log.info("éåpushæå:{}", tag); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("éåpush失败ï¼{}" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åææ Docker 容å¨çä¿¡æ¯ |
| | | * |
| | | * @return ææ Docker 容å¨çä¿¡æ¯å表 |
| | |
| | | log.info("å¼å§è·åææ Docker 容å¨ä¿¡æ¯."); |
| | | try { |
| | | ListContainersCmd listContainersCmd = dockerClient.listContainersCmd(); |
| | | listContainersCmd.withShowAll(true); |
| | | return listContainersCmd.exec(); |
| | | } catch (Exception e) { |
| | | log.error("è·åææ Docker 容å¨ä¿¡æ¯å¤±è´¥: {}", e.getMessage()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * æ¨ééå |
| | | * |
| | | * @param authConfig |
| | | * @param tag |
| | | */ |
| | | public static void pushImage(AuthConfig authConfig, String tag) { |
| | | Objects.requireNonNull(authConfig, "认è¯ä¿¡æ¯ä¸è½ä¸ºç©º."); |
| | | Objects.requireNonNull(tag, "éåä¿¡æ¯ä¸è½ä¸ºç©º."); |
| | | log.info("å¼å§æ¨é Docker éå: {}", tag); |
| | | try { |
| | | PushImageCmd pushImageCmd = dockerClient.pushImageCmd(tag); |
| | | pushImageCmd.withAuthConfig(authConfig) |
| | | .start() |
| | | .awaitCompletion(30, TimeUnit.SECONDS); |
| | | log.info("éåpushæå:{}", tag); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("éåpush失败ï¼{}" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åéåId |
| | | * |
| | | * @param tag |
| | |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("æ æ³è·åéåä¿¡æ¯ï¼" + e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | // ä½¿ç¨ Builder æ¨¡å¼æå»º DockerUtil 对象 |
| | | public static class Builder { |
| | | public void start(String id) { |
| | | try { |
| | | InspectContainerResponse resp = dockerClient.inspectContainerCmd(id).exec(); |
| | | if (null == resp) return; |
| | | |
| | | private String dockerHost; |
| | | private String dockerApiVersion; |
| | | private String dockerCertPath; |
| | | |
| | | public Builder withDockerHost(String dockerHost) { |
| | | this.dockerHost = dockerHost; |
| | | return this; |
| | | dockerClient.startContainerCmd(id).exec(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | public Builder withDockerApiVersion(String dockerApiVersion) { |
| | | this.dockerApiVersion = dockerApiVersion; |
| | | return this; |
| | | public void restart(String id) { |
| | | try { |
| | | InspectContainerResponse resp = dockerClient.inspectContainerCmd(id).exec(); |
| | | if (null == resp) return; |
| | | |
| | | dockerClient.restartContainerCmd(id).exec(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | public Builder withDockerCertPath(String dockerCertPath) { |
| | | this.dockerCertPath = dockerCertPath; |
| | | return this; |
| | | public void stop(String id) { |
| | | try { |
| | | InspectContainerResponse resp = dockerClient.inspectContainerCmd(id).exec(); |
| | | if (null == resp) return; |
| | | |
| | | dockerClient.stopContainerCmd(id).exec(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | public DockerUtils build() { |
| | | return new DockerUtils(dockerHost, dockerApiVersion, dockerCertPath); |
| | | public void pause(String id) { |
| | | try { |
| | | InspectContainerResponse resp = dockerClient.inspectContainerCmd(id).exec(); |
| | | if (null == resp) return; |
| | | |
| | | if (null != resp.getState().getRunning() && resp.getState().getRunning()) { |
| | | dockerClient.pauseContainerCmd(id).exec(); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | public void unpause(String id) { |
| | | try { |
| | | InspectContainerResponse resp = dockerClient.inspectContainerCmd(id).exec(); |
| | | if (null == resp) return; |
| | | |
| | | if (null != resp.getState().getPaused() && resp.getState().getPaused()) { |
| | | dockerClient.unpauseContainerCmd(id).exec(); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | |
| | | .withUsername("admin") |
| | | .withPassword("admin123"); |
| | | |
| | | DockerUtils dockerUtil = new DockerUtils.Builder() |
| | | //æå¡å¨ip |
| | | .withDockerHost("tcp://10.50.80.165:2375") |
| | | //APIçæ¬ å¯éè¿å¨æå¡å¨ docker version å½ä»¤æ¥ç |
| | | .withDockerApiVersion("1.41") |
| | | //å®å
¨è¿æ¥å¯é¥æä»¶åæ¾è·¯å¾ |
| | | .withDockerCertPath("/home/user/certs/") |
| | | .build(); |
| | | DockerUtils dockerUtil = new DockerUtils( |
| | | "tcp://192.168.11.203:2375", |
| | | "1.45", |
| | | "/home/user/certs/"); |
| | | |
| | | //ç»å½ |
| | | dockerUtil.login(authConfig); |
| | | |
| | |
| | | </description> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- SpringCloud Alibaba Nacos --> |
| | | <dependency> |
| | | <groupId>com.alibaba.cloud</groupId> |
| | |
| | | <artifactId>caffeine</artifactId> |
| | | <version>2.9.3</version> |
| | | </dependency> |
| | | |
| | | <!--websocket--> |
| | | <dependency> |
| | | <groupId>javax.websocket</groupId> |
| | | <artifactId>javax.websocket-api</artifactId> |
| | | <version>1.0</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-websocket</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | @SuppressWarnings("ALL") |
| | | @Configuration |
| | | @SuppressWarnings("ALL") |
| | | public class RestTemplateConfig { |
| | | @Bean |
| | | public RestTemplate restTemplate() { |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.config; |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.socket.server.standard.ServerEndpointExporter; |
| | | |
| | | @Component |
| | | @SuppressWarnings("ALL") |
| | | public class WebSocketConfig { |
| | | @Bean |
| | | public ServerEndpointExporter serverEndpointExporter() { |
| | | return new ServerEndpointExporter(); |
| | | } |
| | | } |
| | |
| | | import com.se.common.core.utils.poi.ExcelUtil; |
| | | import com.se.common.core.web.page.TableDataInfo; |
| | | |
| | | |
| | | /** |
| | | * æ§å¶æ¥å¿Controller |
| | | * |
| | | * |
| | | * @author se |
| | | * @date 2024-11-22 |
| | | * @date 2024-12-13 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/ctrlLog") |
| | | public class SysCtrlLogController extends BaseController |
| | | { |
| | | public class SysCtrlLogController extends BaseController { |
| | | @Autowired |
| | | private ISysCtrlLogService sysCtrlLogService; |
| | | |
| | |
| | | */ |
| | | @RequiresPermissions("system:ctrlLog:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysCtrlLog sysCtrlLog) |
| | | { |
| | | public TableDataInfo list(SysCtrlLog sysCtrlLog) { |
| | | startPage(); |
| | | List<SysCtrlLog> list = sysCtrlLogService.selectSysCtrlLogList(sysCtrlLog); |
| | | return getDataTable(list); |
| | |
| | | @RequiresPermissions("system:ctrlLog:export") |
| | | @Log(title = "æ§å¶æ¥å¿", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysCtrlLog sysCtrlLog) |
| | | { |
| | | public void export(HttpServletResponse response, SysCtrlLog sysCtrlLog) { |
| | | List<SysCtrlLog> list = sysCtrlLogService.selectSysCtrlLogList(sysCtrlLog); |
| | | ExcelUtil<SysCtrlLog> util = new ExcelUtil<SysCtrlLog>(SysCtrlLog.class); |
| | | util.exportExcel(response, list, "æ§å¶æ¥å¿æ°æ®"); |
| | |
| | | */ |
| | | @RequiresPermissions("system:ctrlLog:query") |
| | | @GetMapping(value = "/{logId}") |
| | | public AjaxResult getInfo(@PathVariable("logId") Long logId) |
| | | { |
| | | public AjaxResult getInfo(@PathVariable("logId") Long logId) { |
| | | return success(sysCtrlLogService.selectSysCtrlLogByLogId(logId)); |
| | | } |
| | | |
| | |
| | | @RequiresPermissions("system:ctrlLog:add") |
| | | @Log(title = "æ§å¶æ¥å¿", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody SysCtrlLog sysCtrlLog) |
| | | { |
| | | public AjaxResult add(@RequestBody SysCtrlLog sysCtrlLog) { |
| | | return toAjax(sysCtrlLogService.insertSysCtrlLog(sysCtrlLog)); |
| | | } |
| | | |
| | |
| | | @RequiresPermissions("system:ctrlLog:edit") |
| | | @Log(title = "æ§å¶æ¥å¿", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@RequestBody SysCtrlLog sysCtrlLog) |
| | | { |
| | | public AjaxResult edit(@RequestBody SysCtrlLog sysCtrlLog) { |
| | | return toAjax(sysCtrlLogService.updateSysCtrlLog(sysCtrlLog)); |
| | | } |
| | | |
| | |
| | | */ |
| | | @RequiresPermissions("system:ctrlLog:remove") |
| | | @Log(title = "æ§å¶æ¥å¿", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{logIds}") |
| | | public AjaxResult remove(@PathVariable Long[] logIds) |
| | | { |
| | | @DeleteMapping("/{logIds}") |
| | | public AjaxResult remove(@PathVariable Long[] logIds) { |
| | | return toAjax(sysCtrlLogService.deleteSysCtrlLogByLogIds(logIds)); |
| | | } |
| | | } |
| | |
| | | import java.util.Date; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.se.common.core.annotation.Excel; |
| | | import com.se.common.core.web.domain.BaseEntity; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | |
| | | /** |
| | | * æ§å¶æ¥å¿å¯¹è±¡ sys_ctrl_log |
| | | * |
| | | * |
| | | * @author se |
| | | * @date 2024-11-22 |
| | | * @date 2024-12-13 |
| | | */ |
| | | public class SysCtrlLog { |
| | | private static final long serialVersionUID = 1L; |
| | |
| | | private Long logId; |
| | | |
| | | /** |
| | | * 表ID |
| | | */ |
| | | @Excel(name = "表ID") |
| | | private Long tabId; |
| | | |
| | | /** |
| | | * æ é¢ |
| | | */ |
| | | @Excel(name = "æ é¢") |
| | | private String title; |
| | | |
| | | /** |
| | | * ç±»å |
| | | * ç±»åï¼n-æ£å¸¸ï¼e-éè¯¯ï¼ |
| | | */ |
| | | @Excel(name = "ç±»å") |
| | | @Excel(name = "ç±»å", readConverterExp = "n=-æ£å¸¸ï¼e-é误") |
| | | private String type; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 夿³¨ |
| | | */ |
| | | @Excel(name = "夿³¨") |
| | | private String remark; |
| | | |
| | | public void setLogId(Long logId) { |
| | |
| | | |
| | | public Long getLogId() { |
| | | return logId; |
| | | } |
| | | |
| | | public void setTabId(Long tabId) { |
| | | this.tabId = tabId; |
| | | } |
| | | |
| | | public Long getTabId() { |
| | | return tabId; |
| | | } |
| | | |
| | | public void setTitle(String title) { |
| | |
| | | public String toString() { |
| | | return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("logId", getLogId()) |
| | | .append("tabId", getTabId()) |
| | | .append("title", getTitle()) |
| | | .append("type", getType()) |
| | | .append("ip", getIp()) |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.system.service; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.io.IOException; |
| | | import java.util.concurrent.CopyOnWriteArraySet; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | @Component |
| | | @SuppressWarnings("ALL") |
| | | @ServerEndpoint(value = "/ws/query") |
| | | public class WebSocketService { |
| | | @PostConstruct |
| | | public void init() { |
| | | System.out.println("websocket å è½½å®æ"); |
| | | } |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(WebSocketService.class); |
| | | |
| | | private static final AtomicInteger ONLINE_COUNT = new AtomicInteger(0); |
| | | |
| | | private final static CopyOnWriteArraySet<Session> SESSION_SET = new CopyOnWriteArraySet<Session>(); |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session) { |
| | | SESSION_SET.add(session); |
| | | |
| | | int cnt = ONLINE_COUNT.incrementAndGet(); |
| | | log.info("æè¿æ¥å å
¥ï¼å½åè¿æ¥æ°ä¸ºï¼{}", cnt); |
| | | sendMessage(session, "è¿æ¥æå"); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(Session session) { |
| | | SESSION_SET.remove(session); |
| | | |
| | | int cnt = ONLINE_COUNT.decrementAndGet(); |
| | | log.info("æè¿æ¥å
³éï¼å½åè¿æ¥æ°ä¸ºï¼{}", cnt); |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(String message, Session session) { |
| | | log.info("æ¥èªå®¢æ·ç«¯çæ¶æ¯ï¼{}", message); |
| | | sendMessage(session, "æ¶å°æ¶æ¯ï¼æ¶æ¯å
容ï¼" + message); |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Session session, Throwable error) { |
| | | log.error("åçé误ï¼{}ï¼Session IDï¼ {}", error.getMessage(), session.getId()); |
| | | } |
| | | |
| | | public static void sendMessage(Session session, String message) { |
| | | try { |
| | | session.getBasicRemote().sendText(String.format("%s", message)); |
| | | } catch (Exception ex) { |
| | | log.error("åéæ¶æ¯åºéï¼{}", ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | public static void broadCastInfo(String message) throws IOException { |
| | | for (Session session : SESSION_SET) { |
| | | if (session.isOpen()) { |
| | | sendMessage(session, message); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static void sendMessage(String message, String sessionId) throws IOException { |
| | | Session session = null; |
| | | for (Session s : SESSION_SET) { |
| | | if (s.getId().equals(sessionId)) { |
| | | session = s; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (session != null) { |
| | | sendMessage(session, message); |
| | | } else { |
| | | log.info("æ²¡ææ¾å°ä½ æå®IDçä¼è¯ï¼{}", sessionId); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | import java.util.List; |
| | | import com.se.common.core.utils.DateUtils; |
| | | import com.se.system.service.WebSocketService; |
| | | import com.se.system.utils.CaffeineUtils; |
| | | import com.se.system.utils.ConnectUtils; |
| | | import com.se.system.utils.StringUtils; |
| | |
| | | |
| | | sysStatusCtrlMapper.updates(list); |
| | | } |
| | | |
| | | private void sendMsg(String json) throws Exception { |
| | | //String json = JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue); |
| | | WebSocketService.broadCastInfo(json); |
| | | } |
| | | } |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.se.system.mapper.SysCtrlLogMapper"> |
| | | |
| | | |
| | | <resultMap type="SysCtrlLog" id="SysCtrlLogResult"> |
| | | <result property="logId" column="log_id" /> |
| | | <result property="tabId" column="tab_id" /> |
| | | <result property="title" column="title" /> |
| | | <result property="type" column="type" /> |
| | | <result property="ip" column="ip" /> |
| | |
| | | </resultMap> |
| | | |
| | | <sql id="selectSysCtrlLogVo"> |
| | | select log_id, title, type, ip, url, method, args, msg, oper, time, remark from sys_ctrl_log |
| | | select log_id, tab_id, title, type, ip, url, method, args, msg, oper, time, remark from sys_ctrl_log |
| | | </sql> |
| | | |
| | | <select id="selectSysCtrlLogList" parameterType="SysCtrlLog" resultMap="SysCtrlLogResult"> |
| | | <include refid="selectSysCtrlLogVo"/> |
| | | <where> |
| | | <where> |
| | | <if test="tabId != null "> and tab_id = #{tabId}</if> |
| | | <if test="title != null and title != ''"> and title = #{title}</if> |
| | | <if test="type != null and type != ''"> and type = #{type}</if> |
| | | <if test="ip != null and ip != ''"> and ip = #{ip}</if> |
| | |
| | | <if test="time != null "> and time = #{time}</if> |
| | | </where> |
| | | </select> |
| | | |
| | | |
| | | <select id="selectSysCtrlLogByLogId" parameterType="Long" resultMap="SysCtrlLogResult"> |
| | | <include refid="selectSysCtrlLogVo"/> |
| | | where log_id = #{logId} |
| | |
| | | <insert id="insertSysCtrlLog" parameterType="SysCtrlLog" useGeneratedKeys="true" keyProperty="logId"> |
| | | insert into sys_ctrl_log |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="tabId != null">tab_id,</if> |
| | | <if test="title != null and title != ''">title,</if> |
| | | <if test="type != null">type,</if> |
| | | <if test="ip != null">ip,</if> |
| | |
| | | <if test="oper != null">oper,</if> |
| | | <if test="time != null">time,</if> |
| | | <if test="remark != null">remark,</if> |
| | | </trim> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="tabId != null">#{tabId},</if> |
| | | <if test="title != null and title != ''">#{title},</if> |
| | | <if test="type != null">#{type},</if> |
| | | <if test="ip != null">#{ip},</if> |
| | |
| | | <if test="oper != null">#{oper},</if> |
| | | <if test="time != null">#{time},</if> |
| | | <if test="remark != null">#{remark},</if> |
| | | </trim> |
| | | </trim> |
| | | </insert> |
| | | |
| | | <update id="updateSysCtrlLog" parameterType="SysCtrlLog"> |
| | | update sys_ctrl_log |
| | | <trim prefix="SET" suffixOverrides=","> |
| | | <if test="tabId != null">tab_id = #{tabId},</if> |
| | | <if test="title != null and title != ''">title = #{title},</if> |
| | | <if test="type != null">type = #{type},</if> |
| | | <if test="ip != null">ip = #{ip},</if> |
| | |
| | | </delete> |
| | | |
| | | <delete id="deleteSysCtrlLogByLogIds" parameterType="String"> |
| | | delete from sys_ctrl_log where log_id in |
| | | delete from sys_ctrl_log where log_id in |
| | | <foreach item="logId" collection="array" open="(" separator="," close=")"> |
| | | #{logId} |
| | | </foreach> |
| | |
| | | kill -9 10086 |
| | | |
| | | url: jdbc:mysql://localhost:3306/se-cloud?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 |
| | | -------------------------------------------------------- |
| | | vi /etc/docker/daemon.json |
| | | |
| | | vim /lib/systemd/system/docker.service |
| | | # é
ç½®æ®é模å¼ï¼-Håæ°æå®dockeråºç¨ç¨åºç嬿¹å¼ï¼æè
éç¨ä¸é¢çå®å
¨è¿æ¥æ¹å¼2é1 |
| | | ExecStart=/usr/bin/dockerd -H unix://var/run/docker.sock -H tcp://0.0.0.0:2375 |
| | | |
| | | #é
ç½®å®å
¨è¿æ¥ï¼æ³¨æè¿éç/home/user/certs/ æ ¹æ®èªå·±æ
嵿¿æ¢ä¸ºå®é
ççå¯é¥åæ¾è·¯å¾ |
| | | ExecStart=/usr/bin/dockerd -D --tlsverify=true --tlscert=/home/user/certs/server-cert.pem --tlskey=/home/user/certs/server-key.pem --tlscacert=/home/user/certs/ca.pem -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock |
| | | |
| | | #éè½½é
ç½®ï¼éå¯æå¡ |
| | | systemctl daemon-reload |
| | | systemctl restart docker |
| | | |
| | | #æ¥ç端å£çå¬ |
| | | netstat -nlp |grep 2375 |
| | | |
| | | firewall-cmd --permanent --zone=public --add-port=2375/tcp |
| | | firewall-cmd --reload |
| | | firewall-cmd --list-ports |
| | | |
| | | /se-cloud-se-redis-1 |
| | | |
| | | # se-docker-dev.yml |
| | | docker: |
| | | host: tcp://192.168.11.203:2375 |
| | | apiVersion: 1.45 |
| | | |
| | | docker pause 7c5b33491640 |
| | | docker unpause 7c5b33491640 |
| | | -------------------------------------------------------- |