Category: Programming

12 Posts

MyBatisPlus
custom page sql xml <select id="selectPages" resultType="com.example.domain.vo.UserVo"> select u.user_name, u.real_real from user u ${ew.customSqlSegment} order by u.sort_num desc </select> mapper public interface UserMapper extends BaseMapper<User> { IPage<UserVo> selectPages(IPage<UserVo> page,@Param(Constants.WRAPPER) Wrapper<User> ex); } service @Service public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService { @Override public IPage<UserVo> pages(UserPageDto dto){ QueryWrapper<User> query = new QueryWrapper<>(); query.eq(StringUtils.hasText(dto.getUserName()), "u.user_name",dto.getUserName()); query.like(StringUtils.hasText(dto.getRealName()), "u.real_name",dto.getRealName()); Page<User> page = new Page(1,10); IPage<UserVo> result = this.getBaseMapper().selectPages(page, query); return result; } }
Redis
linux docker-compose.yml services: redis: container_name: redis image: redis:7.4.1-alpine restart: always ports: - "16379:6379" volumes: - ./conf/redis.conf:/etc/redis/redis.conf:rw - ./data:/data:rw command: "redis-server /etc/redis/redis.conf" redis.conf [execute permission] bind 0.0.0.0 protected-mode no port 6379 timeout 60 save 900 1 save 300 10 save 60 10000 rdbcompression yes dbfilename dump.rdb dir /data appendonly yes appendfsync everysec requirepass 123456 rename-command FLUSHALL "" rename-command FLUSHDB "" rename-command CONFIG "" rename-command KEYS "" rename-command SHUTDOWN "" rename-command EVAL "" windows redis.windows-service.conf port requirepass install # windows service .\redis-server.exe --service-install .\redis.windows-service.conf --loglevel verbose --service-name redis3.0 net start redis3.0 # connect .\redis-cli.exe -h 127.0.0.1 -p 6379 -a 123456
MySQL Install
Windows my.ini [mysqld] port = 3000 basedir = D:\Program Files\mysql-8.0.31 datadir = D:\Program Files\mysql-8.0.31\data secure-file-priv = NULL # user-defined skip-name-resolve character-set-server = utf8mb4 default-time-zone = '+8:00' innodb_rollback_on_timeout = 'ON' max_connections = 1000 innodb_lock_wait_timeout = 500 shared-memory default-authentication-plugin = mysql_native_password general_log = 1 slow_query_log = 1 log-error = D:\Program Files\mysql-8.0.31\logs\error.log log-bin = mysql-bin # log_replica_updates user = mysql sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' # cert # ssl-ca = "D:\Program Files\mysql-8.0.19\data\mysql-server.crt" # ssl-cert = "D:\Program Files\mysql-8.0.19\data\mysql-server.crt" # ssl-key = "D:\Program Files\mysql-8.0.19\data\mysql-server.key" connect_timeout = 10 interactive_timeout = 28800 wait_timeout = 28800 # validate_password.length = 10 # validate_password.number_count = 2 # plugin-load-add = # connection_control.dll # connection-control = FORCE # connection-control-failed-login-attempts = FORCE # connection_control_min_connection_delay = 1000 # connection_control_max_connection_delay = 86400 # connection_control_failed_connections_threshold = 3 # innodb_buffer_pool_size = 4G # innodb_log_buffer_size = 256M # innodb_log_file_size = 1G # innodb_write_io_threads = 16 # innodb_flush_log_at_trx_commit = 0 # innodb_doublewrite = 0 # Row size too large # innodb_strict_mode=0 [mysql] local_infile = 0 [client] port=3000 default-character-set=utf8mb4 install create my.ini create logs create app # init bin\mysqld.exe --initialize --console # install service bin\mysqld.exe install mysql8…
Nginx
commands # start start nginx # reload nginx -s reload # stop/quit nginx -s stop/quit # test config nginx -t conf server { listen 80; server_name 127.0.0.1; gzip on; gzip_static on; gzip_buffers 4 16k; gzip_http_version 1.1; # 1-10 gzip_comp_level 5; gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_vary on; server_tokens off; location / { root /usr/share/nginx/html; index index.html; try_files $uri $uri/ /index.html; } location /admin/ { alias E:/Work/www/dist/; index index.html try_files $uri $uri/ /admin/index.html; } location /uploads/ { alias /attachment/; } location /api/ { proxy_pass http://api:8080/; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 20m; } error_page 302 /error.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } docker-compose.yml services: web: container_name: invent-web image: nginx:1.24.0 restart: always ports: - "80:80" volumes: - ./dist:/usr/share/nginx/html - ./uploads:/attachment - ./nginx/conf.d:/etc/nginx/conf.d/ logging: driver: "json-file" options: max-size: "100m" SSL HTTP redirect HTTPS server { listen 80; listen [::]:80; server_name oluck.top; return 301 https://$server_name$request_uri; } server { listen 443 ssl; listen [::]:443 ssl; http2 on; ssl_certificate /ssl/oluck.top.crt; ssl_certificate_key /ssl/oluck.top.key;…
Docker
doc install # docker apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y systemctl start docker systemctl enable docker docker --version docker info # docker-compose curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose docker-compose --version docker commands # list docker ps [-a] # search by name docker ps [-a] | grep "redis" # logs docker logs -f --tail <container-name> # start/stop/rm docker start/stop/rm <container-name> # container info docker inspect <container-name> # disk usage docker system df network # create docker network create --subnet 10.10.10.0/24 net-stmp # delete docker network prune docker-compose commands # up docker-compose up -d [--build] [<service-name>] # down docker-compose down # logs docker-compose logs -f --tail=0 <service-name> # list docker-compose ps images # images docker images | grep nginx # save docker save -o nginx.1.24.0.tar redis:1.24.0 # load docker load -i nginx.1.24.0.tar # delete the image with the tag none docker images | grep none | awk '{print $3}' | xargs docker rmi
MySQL
Database -- create CREATE DATABASE `dbname` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci'; User -- create user CREATE USER 'test' @'10.10.10.1' IDENTIFIED WITH mysql_native_password BY '123456' REQUIRE SSL PASSWORD EXPIRE INTERVAL 90 DAY; -- grant privileges GRANT ALL PRIVILEGES ON `dbname`.* TO 'test' @'10.10.10.1'; -- grant SELECT -- select, insert, update, delete GRANT SELECT ON`invent`.* TO 'test' @'10.10.10.1'; -- flush FLUSH PRIVILEGES; -- select user SELECT `host`, `user`, `plugin`, `authentication_string` FROM `user`; -- show user grants SHOW GRANTS FOR 'test' @'10.10.10.1'; -- revoke privileges REVOKE ALL PRIVILEGES ON `invent`.* FROM 'test' @'10.10.10.1'; -- delete user DROP USER 'test' @'10.10.10.1'; -- flush privileges FLUSH PRIVILEGES; -- modify password ALTER USER 'test' @'10.10.10.1' IDENTIFIED WITH mysql_native_password BY '123456'; -- select user SELECT `USER`, `HOST`, password_last_changed, password_lifetime, password_expired FROM mysql.USER; Config -- select all columns SELECT * FROM information_schema.`COLUMNS` WHERE table_name = 'sys_user'; -- version SELECT version(); -- is suport ssl SHOW VARIABLES LIKE '%ssl%'; -- port SHOW VARIABLES LIKE 'port'; -- datadir SHOW VARIABLES LIKE 'datadir'; -- update table name to upper SELECT concat( "alter table ", TABLE_NAME, '…
SSH
commands # generate ssh-keygen # copy to server type ~/.ssh/id_rsa.pub | ssh [email protected] "cat >> .ssh/authorized_keys" # clearn known_hosts ssh-keygen -f ~/.ssh/known_hosts -R 10.10.10.67
SSL
Root Certificate # Root Key openssl genrsa -des3 -out ca.key 2048 # ROOT CA Certificate openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 \ -subj "/C=CN/ST=SH/L=SH/O=ON" \ -out ca.crt Server Certificate # Server Key openssl genrsa -out server.key 2048 # Server CSR openssl req -new -key server.key \ -subj "/C=CN/ST=SH/L=SH/O=ON" \ -out server.csr # Server Certificate,3650 days openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 3650 -out server.crt # p12 openssl pkcs12 -export -in server.crt -inkey server.key -out server.p12 -name "server" # pem openssl x509 -in ca.crt -out ca.pem -outform PEM Client Certificate # Client Key openssl genrsa -out client.key 2048 # Client CSR,Common Name: client Name requried openssl req -new -key client.key \ -subj "/C=CN/ST=SH/L=SH/O=ON/CN=Env1" \ -out client.csr # Client Certificate openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 3650 -sha256 -out client.crt # p12 openssl pkcs12 -export -out client.p12 -inkey client.key -in client.crt -certfile ca.crt # pem openssl x509 -in client.crt -out client.pem -outform PEM verify # verify chain openssl verify -CAfile ca.crt client.crt #…
Java
commands # Java java -jar "-Dloader.path=./lib" ./ROOT.jar --spring.profiles.active=test -Duser.timezone=GMT+8 -Djava.security.egd=file:/dev/./urandom # Maven mvn clean package -DskipTests Docker docker-compose.yml ``` - Dockerfile base image FROM openjdk:8-alpine FROM openjdk:17-jdk-alpine font RUN apk update && apk add --no-cache ttf-dejavu fontconfig author LABEL author="katzhen" port EXPOSE 9082 aa jar ADD ROOT.jar ROOT.jar add lib ADD lib lib add yml ADD application-prod.yml application-prod.yml set variables -Xmx ENV JAVA_OPTS="-Xmx512m -Dspring.profiles.active=prod" exec Support graceful shutdown -Duser.timezone -Djava.security.egd Improving random number generation efficiency ENTRYPOINT ["sh","-c","exec java $JAVA_OPTS -Duser.timezone=GMT+8 -Djava.security.egd=file:/dev/./urandom -jar '-Dloader.path=./lib' ROOT.jar" ] ### winsw.xml ```xml user-service User Service User Service java -jar "-Dloader.path=./lib" ./ROOT.jar --spring.profiles.active=prod -Duser.timezone=GMT+8 -Djava.security.egd=file:/dev/./urandom Automatic reset
Windows
commands # port netstat -ano | findstr :22 # process tasklist | findstr "java" # force stop process tasklist /PID <PID> -t -f # force stop multiple process tasklist /PID <PID> /PID <PID> /F # tail gc -tail 10 -wait -encoding UTF8 ./info.log # search process Get-Process | Where-Object {$_.Name -like '*chrome*'} | Select-Object Id,Name,Path winsw.exe config <service> <id>service-id</id> <name>service-name</name> <description>service-description</description> <executable><executable> <arguments></arguments> <startmode>Automatic</startmode> <logmode>reset</logmode> </service> .\winsw.exe install .\winsw.exe start .\winsw.exe stop .\winsw.exe uninstall