默认基于centos系统进行安装
很多内容和写的另外一篇博客nginx+keepalived+pgsql+mysql+redis+tomcat离线部署过程有部分重合
因为一些在线安装, 无非是
rpm
/tar.gz
压缩包: 与离线差不多有一些服务器会自带java8
rpm -qa|grep jdk
查看copy-jdk-configs-4.0-1.hce2.noarch
java-1.8.0-openjdk-headless-1.8.0.342.b07-0.hce2.x86_64
java-1.8.0-openjdk-1.8.0.342.b07-0.hce2.x86_64
java-1.8.0-openjdk-devel-1.8.0.342.b07-0.hce2.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.342.b07-0.hce2.x86_64
(如果有网可通过wget下载安装包)
rpm -ivh jdk-8u371-linux-x64.rpm
java
/ javac
/ java -version
yum install -y java-1.8.0-openjdk-devel.x86_64
tomcat学习整理, 会一直更新.
下载: 官网下载tar.gz压缩包, apache-tomcat-8.5.81.tar.gz
为例
上传: 将压缩包上传到服务器的一个目录上
解压: tar -zxvf apache-tomcat-8.5.81.tar.gz
重命名: mv apache-tomcat-8.5.81.tar.gz tomcat
移动到安装目录(位置随意): mv tomcat /usr/local/tomcat
创建tomcat.service, vi /etc/systemd/system/tomcat.service
, 并输入(注意java路径和tomcat路径):
[Unit]
Description=Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/
Environment=CATALINA_PID=/usr/local/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/usr/local/tomcat/
Environment=CATALINA_BASE=/usr/local/tomcat/
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
User=root
Group=root
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
常用指令
验证: curl localhost:8080
修改默认端口8080为80, vi /usr/local/tomcat/conf/service.xml
, 差不多69行(或者通过/ + 输入8080寻找)
<Connector port="80" protocol="HTTP/1.1"...
将8080
修改成80即可
重启tomcat: systemctl restart tomcat
端口放行
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --list-port
firewall-cmd --reload
curl ip:80
参考:
yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
yum install mysql-community-server
systemctl start mysqld
systemctl enable mysqld
grep 'temporary password' /var/log/mysqld.log
mysql -p t&ki3u&+ib7X
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=1;
mysql> update mysql.user set host='%' where user="root";
mysql> flush privileges;
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --list-port
firewall-cmd --reload
mysql-8.0.32-el7-x86_64.tar.gz
/usr/local下
tar -zxvf mysql-8.0.32-el7-x86_64.tar.gz
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql mysql/
vim /etc/my.cnf
, 其中local_case_table_names=1
是忽略大小写[mysql]
default-character-set=utf8mb4
[client]
#port=3306
socket=/var/lib/mysql/mysql.sock
[mysqld]
user=mysql
general_log = 1
general_log_file= /var/log/mysql/mysql.log
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data
log-bin=/usr/local/mysql/data/mysql-bin
innodb_data_home_dir=/usr/local/mysql/data
innodb_log_group_home_dir=/usr/local/mysql/data/
character-set-server=utf8mb4
lower_case_table_names=1
autocommit=1
default_authentication_plugin=mysql_native_password
symbolic-links=0
# Disabling symbolic-links is recommended to prevent assorted security risks
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
#
# include all files from the config directory
chown 777 /etc/my.cnf
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
source /etc/profile
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize
, 会输出日志如下(最后一行是默认密码):2023-04-18T06:52:34.464698Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-04-18T06:52:34.464786Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2023-04-18T06:52:34.464809Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.32) initializing of server in progress as process 11924
2023-04-18T06:52:34.480151Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-04-18T06:52:34.946560Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-04-18T06:52:36.589592Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fGzmjdZXj0<p
cp -a ./support-files/mysql.server /etc/init.d/mysql
cp -a ./support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysql
chmod +x /etc/init.d/mysqld
mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
service mysql start
service mysql restart
service mysql stop
/usr/local/mysql/bin/mysql -p
, 回车输入密码(初始化数据库那个默认密码)ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '5h%jqTlsjfgm0UjHksklP3vL';
flush privileges;
vim /etc/systemd/system/mysql.service
[Unit]
Description=MySQL Server
After=network.target
[Service]
Type=forking
User=mysql
ExecStart=/etc/init.d/mysql start
ExecStop=/etc/init.d/mysql stop
[Install]
WantedBy=multi-user.target
service mysql stop
systemctl daemon-reload
systemctl enable mysql
syatemctl start mysql
会自动生成service, 目录在/usr/lib/systemd/system/
下, 自己创建的service在这里和/etc/systemd/system/
下都是可以生效, 区别是/usr/
下的一般是软件安装时候自动生成的, /etc/
下是用户自己定义的.
Linux
-> Red Hat/Rocky/CentOS
-> 1.软件版本最新就行
-> 2.系统版本根据自己的选择对应版本
-> 3.位数 x86_64就行
下方会出现安装需要执行的指令, 逐条执行即可.sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql15-server
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15
sudo -u postgres psql
\password postgres
, 回车等待输入密码alter user postgres with password 'your_new_password';
也行\q
postgresql.conf
:
vim /var/lib/pgsql/14/data/postgresql.conf
, 修改成listen_addresses="*"
pg_hab.conf
: vim /var/lib/pgsql/14/data/pg_hba.conf
在IPV4
下添加host all all 0.0.0.0/0 md5
systemctl status firewalld
查看防火墙状态)
firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload
/var/lib/pgsql/15/data/postgresql.conf
logging_collector
: 日志收集功能, 默认开(on
)log_directory
: 日志的路径, 默认log
, 可配置绝对路径/home/pgsql/log
(需要手动创建目录, 且给postgresql
用户权限)log_filename
: 日志文件名, 默认postgresql-%a.log
, 意思周为单位, 最多七个, 可更改为postgresql-%Y-%m-%d.log
, 每天一个log_statement
: 要记录哪些sql语句, none-不记录, ddl-create/alter/drop等, mod-insert/update/delete等, all-dll+mod, 建议配置mode即可log_duration
: 是否记录sql执行的时间, 默认off
, 可以修改为on
log_min_duration_statement
: sql语句执行时间的最小阈值, 超过这个值时候才会如日志, 默认-1(不开启), 可以修改为0(记录所有)log_statement_stats
: 确定是否记录每种 SQL 语句的执行统计信息,如执行次数、平均执行时间等。默认值为 off,表示不记录统计信息。你可以将其设置为 on,以记录统计信息。不建议开启文件会很大log_connections
: 客户端连接事件, 默认off
, 可修改on
开启log_disconnections
: 客户端断开事件, 默认off
, 可修改on
开启log_hostname
: 记录客户端主机名, 默认off
(只记录ip), 可修改on
systemctl restart postgresql-15
rpm -ivh postgresql15-libs-15.3-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql15-15.3-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql15-server-15.3-1PGDG.rhel7.x86_64.rpm
/usr/pgsql-15/bin/postgresql-15-setup initdb
systemctl enable postgresql-15
systemctl start postgresql-15
需要编译安装, 提前安装gcc pcre-devel openssl-devel zlib-devel
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel
rpm -ivh *.rpm --nodeps --force
批量安装redis-7.0.11.tar.gz
, 上传服务器tar -zxvf redis-7.0.11.tar.gz
cd redis-7.0.11
make
make install PREFIX=/usr/local/redis
, 不指定目录, 默认/usr/local/bin
, 指定了会在目录下生成bin
目录cp redis.conf /usr/local/redis/bin/
vim /usr/local/redis/bin/redis.conf
daemonize yes
# bind 127.0.0.1
或者改成 0.0.0.0
protected-mode no
port 6379
requirepass 123456
logfile "/usr/local/redis/bin/redis.log"
// 需要手动创建出vim /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable redis
systemctl start redis
firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --reload
学习使用过程整理了ngix安装与使用
也需要先提前安装5.1中的内容
下载: https://nginx.org/en/download.html, 中的Stable version
, 以nginx-1.24.0.tar.gz
为例
上传服务器
解压: tar -zxvf nginx-1.24.0.tar.gz
切换目录: cd nginx-1.24.0
配置: ./configure
配置(选, 如果需要https, 安装ssl证书的话): ./configure --with-http_ssl_module
编译: make
安装: make install
, 默认安装目录/usr/local/nginx
, 也可想redis一样指定安装目录
修改配置文件(简单配置)
http
下与server
同级的地方upstream myservers {
# 可多个
# 输入ip端口和权重
server 127.0.0.1:8080 weight=1;
}
server
节点下location
中修改server {
listen 80;
server_name: localhost;
location / {
proxy_pass http://myservers;
proxy_redirect default;
#root html;
#index index.html index.htm;
}
}
注册nginx.service, vim /etc/systemd/system/nginx.service
[Unit]
Description=Nginx HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重载: systemctl daemon-reload
开机自启: systemctl enable nginx
启动: systemctl start nginx
重载配置(修改配置后需要): systemctl reload nginx
测试能否实现转发, 访问机器上的80
端口, 看能否转发到8080端口上
复制到/opt
下
解压: tar -zxvf keepalived-2.2.7.tar.gz
进入目录: cd keepalived-2.2.7/
配置: ./configure --prefix=/usr/local/keepalived
, 指定安装目录
编译: make
安装: make install
进入安装目录: cd /usr/local/keepalived/
会自动生成:
drwxr-xr-x. 2 root root 21 May 5 03:19 bin
drwxr-xr-x. 4 root root 41 May 5 03:19 etc
drwxr-xr-x. 2 root root 24 May 5 03:19 sbin
drwxr-xr-x. 5 root root 40 May 5 03:19 share
新建配置文件(同目录下有配置文件的demo可参考): vim ./etc/keepalived/keepalived.conf
备用服务器上的state 填入BACK_UP, 优先级小一点. 其他一样
! Configuration File for keepalived
# 定义虚拟路由, 必须叫VI_1
vrrp_instance VI_1 {
state MASTER #设置为主服务器, 备份服务器设置为BACKUP
interface eth0 #监控的网络接口(ifconfig或者ip addr指令找出网卡)
priority 100 #(优先级, 主机大一点, 备份机小一点)
virtual_router_id 99 #同一个vrrp_instance下routerId必须是一致的
authentication {
auth_type PASS #vrrp认证方式主备必须一致
auth_pass 12345 #密码
}
virtual_ipaddress {
127.0.0.88 #虚拟ip, 主从一致, 可配置多个
}
}
修改service
使用离线方式安装keepalived后会自动生成keepalived.service文件位置在: /usr/lib/systemd/system/keepalived.service
注: 一般系统的或者安装程序自动生成的service文件会在/usr/lib/systemd/system
下
用户自己配置的service一般会放在/etc/systemd/system/下, 两个目录下都可以用systemctl命令操作到.
默认的keepalived.service文件
[Unit]
Description=LVS and VRRP High Availability Monitor
After=network-online.target syslog.target
Wants=network-online.target
Documentation=man:keepalived(8)
Documentation=man:keepalived.conf(5)
Documentation=man:genhash(1)
Documentation=https://keepalived.org
[Service]
Type=forking
PIDFile=/run/keepalived.pid
KillMode=process
EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived
ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
修改后的keepalived.service文件
需要修改ExecStart命令后指向配置文件位置. -f /path/to/keepalived.conf
(因为默认的配置文件都在/usr/local/keepalived/etc/内, 就没有往/etc/keepalived/内复制)
[Unit]
Description=LVS and VRRP High Availability Monitor
After=network-online.target syslog.target
Wants=network-online.target
Documentation=man:keepalived(8)
Documentation=man:keepalived.conf(5)
Documentation=man:genhash(1)
Documentation=https://keepalived.org
[Service]
Type=forking
PIDFile=/run/keepalived.pid
KillMode=process
EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived
ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS -f /usr/local/keepalived/etc/keepalived/keepalived.conf
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
使用systemctl控制
systemctl daemon-reload
systemctl enable keepalived
systemctl start keepalived
systemctl restart keepalived
systemctl stop keepalived
systemctl status keepalived
keepalived的默认日志在/var/log/messages下, 修改日志方法参考这个
防火墙放行vrrp通信: firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept' --permanent
防火墙重载: firewall-cmd --reload
检查通信是否正常: tcpdump -i eth0-nn host 224.0.0.18
, 只有一个等级高为正常
通过访问虚拟ip查看是否由正在工作的主或备来处理ip内的请求.
学习整理: springboot整合nacos和dubbo
nacos-server-2.2.3.tar.gz
, win下就下载zip后缀的解压运行就可以.tar -zxvf nacos-server-2.2.3.tar.gz
mv nacos /usr/local/
nacos.service
, vim /etc/systemd/system/nacos.service
[Unit]
Description=Nacos Server
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/local/soft/jdk/jdk8
ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
ExecStop=/usr/local/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable nacos
systemctl start nacos
firewall-cmd --add-port=8848/tcp --permanent
firewall-cmd --reload
记录常用指令, 以nexus(部署maven私库的工具)为例
docker version
: 查看docker客户端和服务器的版本信息docker info
: 查看有关docker系统的详细信息, 如容器数、镜像数等docker earch <image_name>
: 从docker hub上搜索指定名称的镜像docker pull <image_name>
: 从docker hub上下载指定名称的镜像docker images
: 列出本地已下载的镜像docker run <image_name>
: 基于指定的镜像, 运行一个容器. 如果本地不存在镜像会去hub上面尝试拉取.docker run -tid -p <host_port>:<container_port> --name <container_name> -v <host_path>:<container_path> --restart=always <image_name>
docker run -tid -p 8081:8081 --name nexus -v /usr/local/nexus/nexus-data:/nexus-data --restart=always sonatype/nexus3
-d
: 以后台(守护进程)模式运行容器-t
: 分配一个伪终端(pseudo-TTY),使容器内的应用程序可以与终端进行交互,例如输出日志和接收输入-i
: 保持标准输入打开,使得可以通过标准输入向容器内的应用程序发送数据, 习惯-tid
搭配使用-p <host-port>:<container-port>
: 将主机的端口映射到容器的端口, 前面是主机接口, 后面是容器端口-v <host-path>:<container-path>
: 将主机的目录火文件挂载到容器中, 实现主机和容器之间的文件共享, 前面是主机目录, 后面是容器目录. 这样当容器删除时候挂在在外面的运行数据会保留. 例子中是共享的文件夹, 容器中的文件夹, 也即容器中配置的或内置的文件夹, 比如nexus就在/nexus-data
中, MySQL一般在/var/lib/mysql
; 可配置多个-v hp1/cp1 -v hp2/cp2
即可. 需要记得在docker官网查询该容器所使用的用户id-e <variable-name>=<value>
: 设置环境变量--name <container-name>
: 指定容器名称, 如果不配置将随机生成名称--restart=<restart-policy>
: 设置容器的重启策略
no
: 不自动重启, 容器退出或崩溃时不会自动重启它on-failure[:max-retries]
: 在非正常退出时重启, max-retries
是可选参数, 默认3. docker run --restart=on-failure:5 <image_name>
always
: 无论容器正常退出还是意外退出, docker引擎都会自动重启容器. 当docker服务器启动时, 容器也会自启. 想要自动启动的话, 建议配置这个unless-stopped
: 除非显式停止容器, 否则容器会自动重启.--network=<network-name>
: 连接容器到指定网络--link=<container-name>:<alias>
: 连接到另外一个容器, 并设置别名, 使容器可以与其他容器通信--rm
: 在容器退出后立即自动删除容器. 也即配置--restart=always
会不生效--entrypoint <command>
: 覆盖容器的默认入口点(执行的指令), 比如: tomcat默认使bin下的start.sh可以通过此种方式使用catalina.sh当成启动的指令--user <username>
: 指定运行用户名或用户id(uid)--privileged
: 拥有访问主机设备和文件系统的能力docker ps
: 列出正在运行的容器, 指令后跟-a
可查看所有的容器(包括未启动的)docker stop <container_id / container_name>
停止运行指定id/name的容器docker rm <container_id / container_name>
: 删除指定id的容器(如果未将主机目录挂载到容器中会将容器对应的配置文件/日志等运行数据一同删除掉), 删除之前需要先停止容器, 指令后添加-f
代表强制执行docker rmi <image_name>
: 删除指定名称的镜像, 指令后添加-f
代表强制执行docker build <path_to_dockerfile>
: 在指定路径下的dockerfile文件中构建镜像docker exec -it <container_id / container_name> <command>
: 在正在运行的容器中执行指定命令docker logs <container_id / container_name>
: 查看指定容器的日志输出
-f / --follow
: 同tail -f
, 可实现实时日志跟踪效果-n
: 最后的几行, 默认all-t
: 最近多少分钟的, 具体docker logs --help
查看docker-compose up
: 使用docker compose启动多个容器的应用程序, docker compose
工具, 具体百度了解docker-compose down
: 使用docker compose停止多个容器的应用程序, docker compose
工具, 具体百度了解yum -y install yum-utils
, 失败的话需要换国内源.yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce
[root@hecs-26265 yum.repos.d]# sudo yum install docker-ce
Docker CE Stable - x86_64 320 B/s | 385 B 00:01
Errors during downloading metadata for repository 'docker-ce-stable':
- Status code: 404 for https://download.docker.com/linux/centos/2.0/x86_64/stable/repodata/repomd.xml (IP: 99.86.199.59)
Error: Failed to download metadata for repo 'docker-ce-stable': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
很明显说去找https://download.docker.com/linux/centos/2.0/x86_64/stable/repodata/repomd.xml
结果404了, 也就是没找到, 我们看这个地址中的2.0的位置, 很明显这里应该是centos的系统的版本, 所有改成7.9
或者改成8
(根据自己系统版本)就可以访问了, 那么我们如何去修改才可以让他执行时候用我们修改的而不是2.0
呢:
vim /etc/yum.repos.d/docker-ce.repo
$releasever
改成7.9
: :%s/$releasever/7.9/g
x86_64
-ce
): yum install -y docker
systemctl status docker
systemctl enable docker
systemctl start docker
https://download.docker.com/linux/static/stable/x86_64/docker-24.0.5.tgz
, 可以去https://download.docker.com/linux/static/stable/x86_64/ 挑选合适的安装包, 如果架构不是x64, 可以退上一级选合适的结构tar -zxvf docker-24.0.5.tgz
/usr/bin/
下: cp -p docker/* /usr/bin/
vim /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
Delegate=yes
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start docker
systemctl status docker
systemctl enable docker
由于未深究, 内容很少, 就没有单分出来一个文章.
代码: 点击跳转gitee库
整合springboot+mybatis plus的使用过程与mysql/pgsql类似, 配置分页插件, 自动填充createTime/updateTime等是一样的使用
数据库部分的sql语法与常用的sql语法类似
--drop table example_table;
CREATE TABLE example_table (
-- id UUID DEFAULT generateUUIDv4(),
id String,
equipment_num String,
equipment_type String,
log_type String,
log_content String,
create_time DateTime64(3)
) ENGINE = MergeTree()
ORDER BY (create_time)
PRIMARY KEY (create_time);
因为大多使用clickhouse来做日志存储, 一般都是来降序获取数据, 所以使用create_time
来排序, 查找时候会快一点
MergeTree
: 存储引擎PRIMARY KEY
: 主键, clickhouse中主键没有单一约束, 也即可重复ORDER BY
: 指明排序字段id String
: clickhouse不可以实现12345这样的递增id, 所以采用字符串存储, 在mp中使用@TableId(type = IdType.ASSIGN_UUID)
配合生成com.clickhouse.jdbc.ClickHouseDriver
jdbc:clickhouse://localhost:8123/default?useTimeZone=true&useServerTimeZone=false&serverTimeZone=UTC
PaginationInnerInterceptor innerInterceptor = new PaginationInnerInterceptor(DbType.CLICK_HOUSE);
***ById
发现是可以用的, 如果有需要时候, 在额外测试其他的情况能否适配, 建议参考官网yum -y install yum-utils
, 失败的话需要换国内源.yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/stable/x86_64
yum -y install clickhouse-server clickhouse-client
sudo yum list installed 'clickhouse*'
Error: GPG check FAILED
--nogpgcheck
代表不进行检查rpm --import https://repo.yandex.ru/clickhouse/CLICKHOUSE-KEY.GPG
, 然后执行安装即可systemctl start clickhouse-server
systemctl status clickhouse-server
systemctl enable clickhouse-server
curl localhost:8123
, 返回Ok.
算作成功chmod +w /etc/clickhouse-server/config.xml
chmod +w /etc/clickhouse-server/users.xml
vim /etc/clickhouse-server/config.xml
<listen_host>0.0.0.0</listen_host>
注释放开, 代表允许其他ipv4除ipv6的连接.http
: 8123
tcp
: 9000
mysql
: 9004
pgsql
: 9005
vim /etc/clickhouse-server/users.xml
clickhouse.users.default.password
内写密码users
下新增一对用户名标签以及密码(如下), 配置密码其他方式和其他属性可以参考文件内说明或官方文档<users>
<test>
<password>123456</password>
</test>
</users>
systemctl restart clickhouse-server
config.xml
内用到的端口允许通过防火墙
firewall-cmd --add-port=8123/tcp --permanent
firewall-cmd --reload
dbeaver.ini
文件内的-vmargs前面, -vm后面要有回车:-vm
C:\Program\Java\jdk-17.0.6\bin
将在线安装的前三步使用以下三步代替
clickhouse-common-static
: ClickHouse编译的二进制文件。clickhouse-server
: 创建clickhouse-server软连接,并安装默认配置服务clickhouse-client
: 创建clickhouse-client客户端工具软连接,并安装客户端配置文件。clickhouse-common-static-dbg
: 带有调试信息的ClickHouse二进制文件。rpm -ivh *.rpm
docker的安装可以参考上面9. docker
在win上可使用docker安装, 如果网络不好可以给给docker配置国内的源
数据目录和日志目录在下面连接中也有
/var/lib/clickhouse/
- main folder where ClickHouse stores the data/var/log/clickhouse-server/
- logsdocker run -d \
-v $(realpath ./ch_data):/var/lib/clickhouse/ \
-v $(realpath ./ch_logs):/var/log/clickhouse-server/ \
--name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
要求安装java运行环境
只简单涉及上传和拉取, 只是涉及到releases
类型的配置和使用, 如果需要使用快照或者public等对应配置即可.
Repository
-> Repositories
-> maven-releases
-> Hosted
-> Deployment policy
修改成Allow redeploy
(可重新部署同版本号的版本)maven-releases
和nuget-hosted
供上传, 我们以maven-releases
为例.
File
: 选文件上传, 以jar包为例Extension
: jarGroup ID
: com.test.apiArtiface ID
: test-apiVersion
: 1.0Generate a POM file with these coordinates.
<groupId>com.maven.private1</groupId>
<artifactId>maven-private1</artifactId>
<version>2.23</version>
<packaging>jar</packaging>
<!-- 与dependencies同级 -->
<distributionManagement>
<!-- 快照使用snapshotRepository -->
<repository>
<!-- 与settings.xml中<server>的id相同 -->
<id>my-server</id>
<name>Release repository</name>
<url>http://127.0.0.1:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
mvn deplay
: 进行部署(或者在idea中双击deplay
也行)settings.xml
中配置(一般在自己用户下.m2
目录下)servers
内添加用户名密码<server>
<id>my-server</id>
<username>admin</username>
<password>admin123</password>
</server>
mirrors
中添加镜像<mirror>
<id>my mirror</id>
<name>my mirror</name>
<url>http://127.0.0.1:8081/repository/maven-releases/</url>
<mirrorOf>*</mirrorOf>
</mirror>
profiles
添加配置文件<profile>
<id>my-nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>my nexus releases</name>
<url>http://127.0.0.1:8081/repository/maven-releases/</url>
</repository>
</repositories>
</profile>
activeProfiles
激活配置文件: <activeProfile>my-nexus</activeProfile>
<dependency>
<groupId>test-api</groupId>
<artifactId>com.test.api</artifactId>
<version>1.0</version>
</dependency>
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
下载tar -zxvf nexus-3.60.0-02-unix.tar.gz
mv nexus-3.60.0-02 /usr/local/nexus/
/usr/local/nexus/bin/nexus.rc
可指定执行人/usr/local/nexus/bin/nexus.vmoptions
是配置java执行参数(有日志和数据位置)/usr/local/nexus/etc/nexus-default.properties
中可修改默认端口8081
/usr/local/nexus/bin/nexus
, 后面跟
start
: 启动status
: 查看状态stop
: 停止restart
: 重启ip:8081
, 进入页面
Your admin user password is located in/usr/local/sonatype-work/nexus3/admin.password on the server.
, sonatype-work是运行数据目录, 包括日志和数据等admin123
vim /etc/systemd/system/nexus.service
echo $JAVA_HOME
看到确实有这个变量, 而且命令行直接输入java也可以显示出来, 但是通过systemctl start nexus
的报错信息Please define INSTALL4J_JAVA_HOME to point to a suitable JVM.
在nexus.service
中配置上JAVA_HOME之后就可以了)[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/local/soft/jdk/jdk8
ExecStart=/usr/local/nexus/bin/nexus start
ExecStop=/usr/local/nexus/bin/nexus stop
User=root
Group=root
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
systemctl deamon-reload
systemctl start nexus
systemctl enable nexus
systemctl stop nexus
systemctl restart nexus
firewall-cmd --add-port=8081 --permanent
firewall-cmd --reload
ip:8081
docker run -d -p 8081:8081 --name nexus -v /usr/local/nexus/nexus-data:/nexus-data --restart=always sonatype/nexus3
docker run
: 运行一个容器, 如果没有镜像(docker images
查看)会自动下载最新的并运行-d
: 后台运行-p 8081:8081
: 端口影响, 将主机的8081映射到容器的8081上, 前面是主机的--name
: 指明容器的名称, 不填默认随机单词-v host_path:container_path
: 将主机路径挂接到容器内路径, 这样日志和数据会保存在主机上, 不会随着容器删除而删除--restart=always
: 重启策略, always是当意外停止或者正常停止时候(包括重启机器或者docker)会自动运行该容器docker ps -a
, 其中-a
是显示所有容器(包括停止的, 不加的话是显示正在运行的)status
中看到nexus看到是Restarting
, 证明没有启动成功, 在重启中. 通过查找日志docker logs nexus
的最上面会发现mkdir: cannot create directory '../sonatype-work/nexus3/log': Permission denied
, 说是权限不足, 创建sonatype-work目录时候被拒绝了, 因为sonatype-work是运行数据目录, 包括日志和数据等, 所以可以判断是-v
挂接的主机路径权限问题, 通过chown -R 200 /usr/local/nexus/nexus-data/
给目录赋予用户id为200的即可, 因为nexus docker镜像使用的用户id是200, 因为在官网https://hub.docker.com/r/sonatype/nexus3/有提到A persistent directory, /nexus-data, is used for configuration, logs, and storage. This directory needs to be writable by the Nexus process, which runs as UID 200.
, 设置完再次通过docker start nexus
运行ip:80801
admin
, 密码在-v
前面的主机目录内的admin.password
, 使用cat
/vim
查看, 直接复制出来登录上然后按照提醒重置密码.本软件的安装是基于Kylin Linux Advanced Server V10 (Lance)
, 系统镜像: 麒麟官网镜像下载中的海光版, 点进去是x86_64后缀.
mybatis-plus连接opengauss(与连接pgsql的代码一样)测试代码: 代码
openGauss 5.0.0 (LTS)
x86_64
, 根据自己系统使用uname -a
或者lscpu
找到自己的Architecture
.openEuler 20.03. LTS
, 如果是centos选择centos即可. 我的系统是是麒麟v10Kylin Linux Advanced Server V10 (Lance)
(通过 cat /etc/os-release
获取), 我这里选择的系统版本是openEuler 20.0.3 LTS
(没有找到麒麟和euler的版本对应)极简
, 部署方式是单点服务器安装
. 其他的类型的方式按照官网文档就行wget
下载或者下载之后上传到服务器都可, 假如服务器目录是: /opt/openGauss/
tar -jxvf openGauss-5.0.0-openEuler-64bit.tar.bz2
oom
/用户组dbgrp
groupadd <group_name>
useradd -G <group_name> <username>
usermod -G <group_name> <username>
usermod -a -G <group_name> <username>
: 添加-a
之后是将用户添加到组中, 而不是替换其所在组.chown -R oom:dbgrp /opt/openGauss
su - oom
cd /opt/openGauss/simpleInstall
sh ./install.sh -w "221531,ww" &&source ~/.bashrc
, 其中-w
是指密码cd /opt/openGauss/bin
gs_ctl start -D /opt/openGauss/data/single_node -Z single_node
./gsql -d postgres
连接测试. 连接上之后使用\q
退出.sha256
方式的, 而navicat和dbeaver连接pgsql(openGauss是基于pgsql改的)时默认密码加密方式是md5,exit
退出oom用户, 切换到root用户cd /opt/openGauss/data/single_node
vim pg_hba.conf
, 在ipv4
下添加一行host all all 0.0.0.0/0 md5
vim postgresql.conf
:
listen_addresses
的注释放开, 值改成'*'
password_encryption_type
的值改成0
oom
)是不允许远程登录的, 所以需要创建一个可以远程登录的数据库管理员.
su - oom
cd /opt/openGauss/bin
gs_ctl restart -D /opt/openGauss/data/single_node -Z single_node
./gsql -d postgres
连接create user testuser password 'admin,123';
alter role testuser sysadmin;
SELECT rolpassword FROM pg_authid WHERE rolname = 'testuser';
, 看密码的开始是否是md5vim /etc/systemd/system/opengauss.service
, (使用root账户创建即可)[Unit]
Description=OpenGauss Simplified Database Server
After=network.target
[Service]
Type=forking
User=oom
Group=dbgrp
Environment=PGDATA=/opt/openGauss/data
Environment=GAUSSHOME=/opt/openGauss
Environment=LD_LIBRARY_PATH=/opt/openGauss/lib
ExecStart=/opt/openGauss/bin/gs_ctl start -D /opt/openGauss/data/single_node -Z single_node
ExecStop=/opt/openGauss/bin/gs_ctl stop -D /opt/openGauss/data/single_node -Z single_node
[Install]
WantedBy=multi-user.target
su - oom
/opt/openGauss/bin/gs_ctl stop -D /opt/openGauss/data/single_node -Z single_node
exit
systemctl daemon-reload
systemctl enable opengauss
systemctl start opengauss
systemctl status opengauss
systemctl restart opengauss
systemctl stop opengauss
firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload
docker容器的安装通过上面9.3离线安装docker即可(记得选择对应架构).