mirror of https://github.com/1Panel-dev/1Panel
fix: redis 配置更新方式修改
parent
e13bb924d6
commit
94ebe4952a
|
@ -1,3 +1,12 @@
|
||||||
|
# Redis configuration rewrite by 1Panel
|
||||||
|
timeout 0
|
||||||
|
# maxclients 10000
|
||||||
|
# maxmemory <bytes>
|
||||||
|
save 3600 1 300 100 60 10000
|
||||||
|
appendonly no
|
||||||
|
appendfsync everysec
|
||||||
|
# End Redis configuration rewrite by 1Panel
|
||||||
|
|
||||||
# Redis configuration file example.
|
# Redis configuration file example.
|
||||||
#
|
#
|
||||||
# Note that in order to read the configuration file, Redis must be
|
# Note that in order to read the configuration file, Redis must be
|
||||||
|
@ -156,7 +165,7 @@ tcp-backlog 511
|
||||||
# unixsocketperm 700
|
# unixsocketperm 700
|
||||||
|
|
||||||
# Close the connection after a client is idle for N seconds (0 to disable)
|
# Close the connection after a client is idle for N seconds (0 to disable)
|
||||||
timeout 0
|
# timeout 0
|
||||||
|
|
||||||
# TCP keepalive.
|
# TCP keepalive.
|
||||||
#
|
#
|
||||||
|
@ -1375,7 +1384,7 @@ disable-thp yes
|
||||||
#
|
#
|
||||||
# Please check https://redis.io/topics/persistence for more information.
|
# Please check https://redis.io/topics/persistence for more information.
|
||||||
|
|
||||||
appendonly no
|
# appendonly no
|
||||||
|
|
||||||
# The base name of the append only file.
|
# The base name of the append only file.
|
||||||
#
|
#
|
||||||
|
@ -1434,7 +1443,7 @@ appenddirname "appendonlydir"
|
||||||
# If unsure, use "everysec".
|
# If unsure, use "everysec".
|
||||||
|
|
||||||
# appendfsync always
|
# appendfsync always
|
||||||
appendfsync everysec
|
# appendfsync everysec
|
||||||
# appendfsync no
|
# appendfsync no
|
||||||
|
|
||||||
# When the AOF fsync policy is set to always or everysec, and a background
|
# When the AOF fsync policy is set to always or everysec, and a background
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
# Redis configuration rewrite by 1Panel
|
||||||
|
timeout 0
|
||||||
|
# maxclients 10000
|
||||||
|
# maxmemory <bytes>
|
||||||
|
save 3600 1 300 100 60 10000
|
||||||
|
appendonly no
|
||||||
|
appendfsync everysec
|
||||||
|
# End Redis configuration rewrite by 1Panel
|
||||||
|
|
||||||
# Redis configuration file example.
|
# Redis configuration file example.
|
||||||
#
|
#
|
||||||
# Note that in order to read the configuration file, Redis must be
|
# Note that in order to read the configuration file, Redis must be
|
||||||
|
@ -156,7 +165,7 @@ tcp-backlog 511
|
||||||
# unixsocketperm 700
|
# unixsocketperm 700
|
||||||
|
|
||||||
# Close the connection after a client is idle for N seconds (0 to disable)
|
# Close the connection after a client is idle for N seconds (0 to disable)
|
||||||
timeout 0
|
# timeout 0
|
||||||
|
|
||||||
# TCP keepalive.
|
# TCP keepalive.
|
||||||
#
|
#
|
||||||
|
@ -430,7 +439,7 @@ proc-title-template "{title} {listen-addr} {server-mode}"
|
||||||
#
|
#
|
||||||
# You can set these explicitly by uncommenting the following line.
|
# You can set these explicitly by uncommenting the following line.
|
||||||
#
|
#
|
||||||
save 3600 1 300 100 60 10000
|
# save 3600 1 300 100 60 10000
|
||||||
|
|
||||||
# By default Redis will stop accepting writes if RDB snapshots are enabled
|
# By default Redis will stop accepting writes if RDB snapshots are enabled
|
||||||
# (at least one save point) and the latest background save failed.
|
# (at least one save point) and the latest background save failed.
|
||||||
|
@ -1376,7 +1385,7 @@ disable-thp yes
|
||||||
#
|
#
|
||||||
# Please check https://redis.io/topics/persistence for more information.
|
# Please check https://redis.io/topics/persistence for more information.
|
||||||
|
|
||||||
appendonly no
|
# appendonly no
|
||||||
|
|
||||||
# The base name of the append only file.
|
# The base name of the append only file.
|
||||||
#
|
#
|
||||||
|
@ -1435,7 +1444,7 @@ appenddirname "appendonlydir"
|
||||||
# If unsure, use "everysec".
|
# If unsure, use "everysec".
|
||||||
|
|
||||||
# appendfsync always
|
# appendfsync always
|
||||||
appendfsync everysec
|
# appendfsync everysec
|
||||||
# appendfsync no
|
# appendfsync no
|
||||||
|
|
||||||
# When the AOF fsync policy is set to always or everysec, and a background
|
# When the AOF fsync policy is set to always or everysec, and a background
|
||||||
|
|
|
@ -436,9 +436,9 @@ func (u *MysqlService) UpdateVariables(updatas []dto.MysqlVariablesUpdate) error
|
||||||
lineBytes, err := ioutil.ReadFile(path)
|
lineBytes, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
files = strings.Split(string(lineBytes), "\n")
|
|
||||||
}
|
}
|
||||||
|
files = strings.Split(string(lineBytes), "\n")
|
||||||
|
|
||||||
group := "[mysqld]"
|
group := "[mysqld]"
|
||||||
for _, info := range updatas {
|
for _, info := range updatas {
|
||||||
if app.Version != "5.7.39" {
|
if app.Version != "5.7.39" {
|
||||||
|
|
|
@ -42,23 +42,18 @@ func (u *RedisService) UpdateConf(req dto.RedisConfUpdate) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := configSetStr(redisInfo.ContainerName, redisInfo.Password, "timeout", req.Timeout); err != nil {
|
|
||||||
|
var confs []redisConfig
|
||||||
|
confs = append(confs, redisConfig{key: "timeout", value: req.Timeout})
|
||||||
|
confs = append(confs, redisConfig{key: "maxclients", value: req.Maxclients})
|
||||||
|
confs = append(confs, redisConfig{key: "maxmemory", value: req.Maxmemory})
|
||||||
|
if err := confSet(redisInfo.Name, confs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := configSetStr(redisInfo.ContainerName, redisInfo.Password, "maxclients", req.Maxclients); err != nil {
|
if _, err := compose.Restart(fmt.Sprintf("%s/redis/%s/docker-compose.yml", constant.AppInstallDir, redisInfo.Name)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := configSetStr(redisInfo.ContainerName, redisInfo.Password, "maxmemory", req.Maxmemory); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
commands := append(redisExec(redisInfo.ContainerName, redisInfo.Password), []string{"config", "rewrite"}...)
|
|
||||||
cmd := exec.Command("docker", commands...)
|
|
||||||
stdout, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
return errors.New(string(stdout))
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,24 +74,20 @@ func (u *RedisService) UpdatePersistenceConf(req dto.RedisConfPersistenceUpdate)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var confs []redisConfig
|
||||||
if req.Type == "rbd" {
|
if req.Type == "rbd" {
|
||||||
if err := configSetStr(redisInfo.ContainerName, redisInfo.Password, "save", req.Save); err != nil {
|
confs = append(confs, redisConfig{key: "save", value: req.Save})
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if err := configSetStr(redisInfo.ContainerName, redisInfo.Password, "appendonly", req.Appendonly); err != nil {
|
confs = append(confs, redisConfig{key: "appendonly", value: req.Appendonly})
|
||||||
return err
|
confs = append(confs, redisConfig{key: "appendfsync", value: req.Appendfsync})
|
||||||
}
|
|
||||||
if err := configSetStr(redisInfo.ContainerName, redisInfo.Password, "appendfsync", req.Appendfsync); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
commands := append(redisExec(redisInfo.ContainerName, redisInfo.Password), []string{"config", "rewrite"}...)
|
if err := confSet(redisInfo.Name, confs); err != nil {
|
||||||
cmd := exec.Command("docker", commands...)
|
return err
|
||||||
stdout, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
return errors.New(string(stdout))
|
|
||||||
}
|
}
|
||||||
|
if _, err := compose.Restart(fmt.Sprintf("%s/redis/%s/docker-compose.yml", constant.AppInstallDir, redisInfo.Name)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +141,6 @@ func (u *RedisService) LoadPersistenceConf() (*dto.RedisPersistence, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var item dto.RedisPersistence
|
var item dto.RedisPersistence
|
||||||
if item.Appendonly, err = configGetStr(redisInfo.ContainerName, redisInfo.Password, "appendonly"); err != nil {
|
if item.Appendonly, err = configGetStr(redisInfo.ContainerName, redisInfo.Password, "appendonly"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -301,12 +291,63 @@ func configGetStr(containerName, password, param string) (string, error) {
|
||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
func configSetStr(containerName, password, param, value string) error {
|
|
||||||
commands := append(redisExec(containerName, password), []string{"config", "set", param, value}...)
|
type redisConfig struct {
|
||||||
cmd := exec.Command("docker", commands...)
|
key string
|
||||||
stdout, err := cmd.CombinedOutput()
|
value string
|
||||||
|
}
|
||||||
|
|
||||||
|
func confSet(redisName string, changeConf []redisConfig) error {
|
||||||
|
path := fmt.Sprintf("%s/redis/%s/conf/redis.conf", constant.AppInstallDir, redisName)
|
||||||
|
lineBytes, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(string(stdout))
|
return err
|
||||||
|
}
|
||||||
|
files := strings.Split(string(lineBytes), "\n")
|
||||||
|
|
||||||
|
isStartRange := false
|
||||||
|
isEndRange := false
|
||||||
|
var newFiles []string
|
||||||
|
for _, line := range files {
|
||||||
|
if !isStartRange {
|
||||||
|
if line == "# Redis configuration rewrite by 1Panel" {
|
||||||
|
isStartRange = true
|
||||||
|
}
|
||||||
|
newFiles = append(newFiles, line)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !isEndRange {
|
||||||
|
isExist := false
|
||||||
|
for _, item := range changeConf {
|
||||||
|
if strings.HasPrefix(line, item.key) || strings.HasPrefix(line, "# "+item.key) {
|
||||||
|
if item.value == "0" || len(item.value) == 0 {
|
||||||
|
newFiles = append(newFiles, fmt.Sprintf("# %s %s", item.key, item.value))
|
||||||
|
} else {
|
||||||
|
newFiles = append(newFiles, fmt.Sprintf("%s %s", item.key, item.value))
|
||||||
|
}
|
||||||
|
isExist = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isExist {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newFiles = append(newFiles, line)
|
||||||
|
if line == "# End Redis configuration rewrite by 1Panel" {
|
||||||
|
isEndRange = true
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newFiles = append(newFiles, line)
|
||||||
|
}
|
||||||
|
file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0666)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
_, err = file.WriteString(strings.Join(newFiles, "\n"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,11 @@ type daemonJsonItem struct {
|
||||||
|
|
||||||
func (u *DockerService) LoadDockerStatus() string {
|
func (u *DockerService) LoadDockerStatus() string {
|
||||||
status := constant.StatusRunning
|
status := constant.StatusRunning
|
||||||
// cmd := exec.Command("systemctl", "is-active", "docker")
|
cmd := exec.Command("systemctl", "is-active", "docker")
|
||||||
// stdout, err := cmd.CombinedOutput()
|
stdout, err := cmd.CombinedOutput()
|
||||||
// if string(stdout) != "active\n" || err != nil {
|
if string(stdout) != "active\n" || err != nil {
|
||||||
// status = constant.Stopped
|
status = constant.Stopped
|
||||||
// }
|
}
|
||||||
|
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
<span class="input-help">{{ $t('database.maxmemoryHelper') }}</span>
|
<span class="input-help">{{ $t('database.maxmemoryHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" @click="submtiForm(formRef)">
|
<el-button type="primary" @click="onSubmtiForm(formRef)">
|
||||||
{{ $t('commons.button.save') }}
|
{{ $t('commons.button.save') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
@ -150,6 +150,7 @@ const acceptParams = (prop: DialogProps): void => {
|
||||||
if (redisStatus.value === 'Running') {
|
if (redisStatus.value === 'Running') {
|
||||||
statusRef.value!.acceptParams({ status: prop.status });
|
statusRef.value!.acceptParams({ status: prop.status });
|
||||||
persistenceRef.value!.acceptParams({ status: prop.status });
|
persistenceRef.value!.acceptParams({ status: prop.status });
|
||||||
|
loadform();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const onClose = (): void => {
|
const onClose = (): void => {
|
||||||
|
@ -201,43 +202,36 @@ const onChangePort = async (formEl: FormInstance | undefined) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// const onChangePassword = async () => {
|
const confirmFormRef = ref();
|
||||||
// loading.value = true;
|
const onSubmtiForm = async (formEl: FormInstance | undefined) => {
|
||||||
// let param = {
|
|
||||||
// id: 0,
|
|
||||||
// value: form.requirepass,
|
|
||||||
// };
|
|
||||||
// changeRedisPassword(param)
|
|
||||||
// .then(() => {
|
|
||||||
// loading.value = false;
|
|
||||||
// ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
|
||||||
// })
|
|
||||||
// .finally(() => {
|
|
||||||
// loading.value = false;
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
|
|
||||||
const submtiForm = async (formEl: FormInstance | undefined) => {
|
|
||||||
if (!formEl) return;
|
if (!formEl) return;
|
||||||
formEl.validate(async (valid) => {
|
formEl.validate(async (valid) => {
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
let param = {
|
let params = {
|
||||||
timeout: form.timeout + '',
|
header: i18n.global.t('database.confChange'),
|
||||||
maxclients: form.maxclients + '',
|
operationInfo: i18n.global.t('database.restartNowHelper'),
|
||||||
maxmemory: form.maxmemory + '',
|
submitInputInfo: i18n.global.t('database.restartNow'),
|
||||||
};
|
};
|
||||||
loading.value = true;
|
confirmFormRef.value!.acceptParams(params);
|
||||||
await updateRedisConf(param)
|
|
||||||
.then(() => {
|
|
||||||
loadform();
|
|
||||||
loading.value = false;
|
|
||||||
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
loading.value = false;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const submtiForm = async () => {
|
||||||
|
let param = {
|
||||||
|
timeout: form.timeout + '',
|
||||||
|
maxclients: form.maxclients + '',
|
||||||
|
maxmemory: form.maxmemory + '',
|
||||||
|
};
|
||||||
|
loading.value = true;
|
||||||
|
await updateRedisConf(param)
|
||||||
|
.then(() => {
|
||||||
|
loadform();
|
||||||
|
loading.value = false;
|
||||||
|
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const onSaveFile = async () => {
|
const onSaveFile = async () => {
|
||||||
let params = {
|
let params = {
|
||||||
|
@ -264,19 +258,12 @@ const submtiFile = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadform = async () => {
|
const loadform = async () => {
|
||||||
loading.value = true;
|
const res = await loadRedisConf();
|
||||||
await loadRedisConf()
|
form.name = res.data?.name;
|
||||||
.then((res) => {
|
form.timeout = Number(res.data?.timeout);
|
||||||
loading.value = false;
|
form.maxclients = Number(res.data?.maxclients);
|
||||||
form.name = res.data?.name;
|
form.maxmemory = Number(res.data?.maxmemory);
|
||||||
form.timeout = Number(res.data?.timeout);
|
form.port = Number(res.data?.port);
|
||||||
form.maxclients = Number(res.data?.maxclients);
|
|
||||||
form.maxmemory = Number(res.data?.maxmemory);
|
|
||||||
form.port = Number(res.data?.port);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
loading.value = false;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadConfFile = async () => {
|
const loadConfFile = async () => {
|
||||||
|
|
Loading…
Reference in New Issue