This commit is contained in:
zhiqiang feng
2025-12-29 13:38:39 +08:00
commit 1a4aa9a660
579 changed files with 388880 additions and 0 deletions
@@ -0,0 +1,583 @@
---
page-title: "Docker学习笔记_14 docker应用 - 部署ORACLE 11g单实例数据库.md | 一个DBA的工作学习笔记"
url: http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/
date: "2024-11-20 16:16:55"
---
> docker pull oraclelinux:6.10
---
## Docker学习笔记\_14 docker应用 - 部署ORACLE 11g单实例数据库.md
## [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#%E4%B8%8B%E8%BD%BD%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%9F%BA%E9%95%9C%E5%83%8F "下载操作系统基镜像")下载操作系统基镜像
docker pull oraclelinux:6.10
docker tag oraclelinux:6.10 10.240.4.159/os/oraclelinux:6.10
docker push 10.240.4.159/os/oraclelinux:6.10
docker pull oraclelinux:7.5
docker tag oraclelinux:7.5 10.240.4.159/os/oraclelinux:7.5
docker push 10.240.4.159/os/oraclelinux:7.5
## [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#BUILD%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BD%AF%E4%BB%B6%E9%95%9C%E5%83%8F "BUILD数据库软件镜像")BUILD数据库软件镜像
mkdir -p /docker\_build/oracle\_database/oel\-6.10/01\_database
cd /docker\_build/oracle\_database/oel\-6.10/01\_database
rz
rlwrap\-0.42.tar.gz
p13390677\_112040\_Linux-x86\-64\_1of7.zip
p13390677\_112040\_Linux-x86\-64\_2of7.zip
vi db\_install.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt\_dbinstall\_response\_schema\_v11\_2\_0
oracle.install.option=INSTALL\_DB\_SWONLY
ORACLE\_HOSTNAME=oradb
UNIX\_GROUP\_NAME=oinstall
INVENTORY\_LOCATION=/u01/app/oraInventory
SELECTED\_LANGUAGES=en,zh\_CN
ORACLE\_HOME=/u01/app/oracle/product/11.2.0/db\_1
ORACLE\_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=false
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0
oracle.install.db.DBA\_GROUP=dba
oracle.install.db.OPER\_GROUP=dba
oracle.install.db.CLUSTER\_NODES=
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=
oracle.install.db.config.starterdb.globalDBName=
oracle.install.db.config.starterdb.SID=
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=oracle
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB\_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
oracle.install.db.config.starterdb.storageType=
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
MYORACLESUPPORT\_USERNAME=
MYORACLESUPPORT\_PASSWORD=
SECURITY\_UPDATES\_VIA\_MYORACLESUPPORT=
DECLINE\_SECURITY\_UPDATES=true
PROXY\_HOST=
PROXY\_PORT=
PROXY\_USER=
PROXY\_PWD=
PROXY\_REALM=
COLLECTOR\_SUPPORTHUB\_URL=
oracle.installer.autoupdates.option=
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES\_MYORACLESUPPORT\_USERNAME=
AUTOUPDATES\_MYORACLESUPPORT\_PASSWORD=
vi Dockerfile
FROM 10.240.4.159/os/oralcelinux:6.10
ADD rlwrap\-0.42.tar.gz /tmp/
ADD p13390677\_112040\_Linux-x86\-64\_1of7.zip /tmp/
ADD p13390677\_112040\_Linux-x86\-64\_2of7.zip /tmp/
ADD db\_install.rsp /tmp/
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle && \\
yum -y install oracle-rdbms-server\-11gR2-preinstall unzip readline-devel.x86\_64 lrzsz && \\
cd /tmp/rlwrap\-0.42 && ./configure && make && make install && \\
echo "Create /u01/app dir..." && \\
mkdir -p -m 755 /u01/app/dumpdir && \\
mkdir -p -m 755 /u01/app/oradata && \\
mkdir -p -m 755 /u01/app/oraInventory && \\
mkdir -p -m 755 /u01/app/oracle && \\
mkdir -p -m 755 /u01/app/oracle/product/11.2.0/db\_1 && \\
chown -R oracle:oinstall /u01 && \\
unzip -oq /tmp/p13390677\_112040\_Linux-x86\-64\_1of7.zip -d /tmp/ && \\
unzip -oq /tmp/p13390677\_112040\_Linux-x86\-64\_2of7.zip -d /tmp/ && \\
chown -R oracle:oinstall /tmp/database && \\
printf "%s\\n" 'export ORACLE\_SID=orcl' \\
'export ORACLE\_BASE=/u01/app/oracle' \\
'export ORACLE\_HOME=$ORACLE\_BASE/product/11.2.0/db\_1' \\
'export LD\_LIBRARY\_PATH=$ORACLE\_HOME/lib:$ORACLE\_HOME/lib32' \\
'export PATH=$PATH:$ORACLE\_HOME/bin:$ORACLE\_HOME/OPatch' \\
'export NLS\_LANG=AMERICAN\_AMERICA.ZHS16GBK' \\
'export NLS\_DATE\_FORMAT="yyyy-mm-dd hh24:mi:ss"' \\
'alias sqlplus="rlwrap sqlplus"' \\
'alias rman="rlwrap rman"' \\
>>/home/oracle/.bash\_profile && \\
cat /etc/security/limits.conf | grep -v oracle | tee /etc/security/limits.conf && \\
su oracle -c "/tmp/database/runInstaller -ignorePrereq -ignoreSysPrereqs -waitforcompletion -silent -responseFile /tmp/db\_install.rsp 2>&1" && \\
/u01/app/oraInventory/orainstRoot.sh && \\
/u01/app/oracle/product/11.2.0/db\_1/root.sh && \\
yum clean all && \\
rm -rf /tmp/\* && rm -rf /var/log/\* && rm -rf /var/cache/\*
vi build.sh
imagetag="10.240.4.159/app/oracledatabase:11.2.0.4-software"
dockerfile="Dockerfile"
docker build --rm \\
--force-rm \\
--no-cache \\
--memory=4g \\
--shm-size=4g \\
-t ${imagetag} \\
-f ${dockerfile} .
chmod +x build.sh
./build.sh
## [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#PSU "PSU")PSU
mkdir -p /docker\_build/oracle\_database/oel\-6.10/02\_psu
cd /docker\_build/oracle\_database/oel\-6.10/02\_psu
rz
ocm.rsp
p6880880\_112000\_Linux-x86\-64.zip
p27967757\_112040\_Linux-x86\-64\_2of7.zip
p27923163\_112040\_Linux-x86\-64\_2of7.zip
vi Dockerfile
FROM 10.240.4.159/app/oracledatabase:11.2.0.4\-software
ADD ocm.rsp /tmp/ocm.rsp
ADD p6880880\_112000\_Linux-x86\-64.zip /tmp/
ADD p27967757\_112040\_Linux-x86\-64.zip /tmp/
ADD p27923163\_112040\_Linux-x86\-64.zip /tmp/
RUN printf "%s\\n" '\[GENERAL\]' \\
'RESPONSEFILE\_VERSION="11.2"' \\
'CREATE\_TYPE="CUSTOM"' \\
'\[oracle.net.ca\]' \\
'INSTALLED\_COMPONENTS={"server","net8","javavm"}' \\
'INSTALL\_TYPE=""typical""' \\
'LISTENER\_NUMBER=1' \\
'LISTENER\_NAMES={"LISTENER"}' \\
'LISTENER\_PROTOCOLS={"TCP;1521"}' \\
'LISTENER\_START=""LISTENER""' \\
'NAMING\_METHODS={"TNSNAMES","ONAMES","HOSTNAME"}' \\
'NSN\_NUMBER=1' \\
'NSN\_NAMES={"EXTPROC\_CONNECTION\_DATA"}' \\
'NSN\_SERVICE={"PLSExtProc"}' \\
'NSN\_PROTOCOLS={"TCP;HOSTNAME;1521"}' \\
>>/tmp/netca.rsp && \\
unzip -oq /tmp/p6880880\_112000\_Linux-x86\-64.zip -d /tmp/ && \\
rm -rf /u01/app/oracle/product/11.2.0/db\_1/OPatch && \\
chown -R oracle:oinstall /tmp/OPatch && \\
mv /tmp/OPatch /u01/app/oracle/product/11.2.0/db\_1/ && \\
unzip -qo /tmp/p27967757\_112040\_Linux-x86\-64.zip -d /tmp && \\
unzip -qo /tmp/p27923163\_112040\_Linux-x86\-64.zip -d /tmp && \\
su - oracle -c "opatch apply -silent -ocmrf /tmp/ocm.rsp -local /tmp/27967757/27734982" && \\
su - oracle -c "opatch apply -silent -ocmrf /tmp/ocm.rsp -local /tmp/27923163" && \\
su oracle -c "/u01/app/oracle/product/11.2.0/db\_1/bin/netca -silent -responseFile /tmp/netca.rsp" && \\
yum clean all && \\
rm -rf /tmp/\* && rm -rf /var/log/\* && rm -rf /var/cache/\*
vi build.sh
imagetag="10.240.4.159/app/oracledatabase:11.2.0.4-psu"
dockerfile="Dockerfile"
docker build --rm \\
--force-rm \\
--no-cache \\
--memory=4g \\
--shm-size=4g \\
-t ${imagetag} \\
-f ${dockerfile} .
chmod +x build.sh
./build.sh
## [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#%E5%AE%89%E8%A3%85%E6%95%B0%E6%8D%AE%E5%BA%93 "安装数据库")安装数据库
mkdir -p /docker\_build/oracle\_database/oel\-6.10/03\_db
cd /docker\_build/oracle\_database/oel\-6.10/03\_db
vi Dockerfile
FROM 10.240.4.159/app/oracledatabase:11.2.0.4\-psu
RUN printf "%s\\n" '\[GENERAL\]' \\
'RESPONSEFILE\_VERSION = "11.2.0"' \\
'OPERATION\_TYPE = "createDatabase"' \\
'\[CREATEDATABASE\]' \\
'GDBNAME = "orcl"' \\
'DATABASECONFTYPE = "SI"' \\
'SID = "orcl"' \\
'TEMPLATENAME = "General\_Purpose.dbc"' \\
'SYSPASSWORD = "Center08"' \\
'SYSTEMPASSWORD = "Center08"' \\
'DATAFILEDESTINATION=/u01/app/oradata' \\
'RECOVERYAREADESTINATION=/u01/app/oradata' \\
'STORAGETYPE=FS' \\
'CHARACTERSET="ZHS16GBK"' \\
'INITPARAMS="java\_jit\_enabled=false,memory\_target=0,sga\_target=2048,pga\_aggregate\_target=300,processes=300,open\_cursors=300"' \\
'AUTOMATICMEMORYMANAGEMENT="False"' \\
> /tmp/dbca.rsp && chown oracle:oinstall /tmp/dbca.rsp && chmod +x /tmp/dbca.rsp && \\
su oracle -c "/u01/app/oracle/product/11.2.0/db\_1/bin/dbca -silent -responseFile /tmp/dbca.rsp" && \\
yum clean all && \\
rm -rf /tmp/\* && rm -rf /var/log/\* && rm -rf /var/cache/\*
vi build.sh
imagetag="10.240.4.159/app/oracledatabase:11.2.0.4-db"
dockerfile="Dockerfile"
docker build --rm \\
--force-rm \\
--no-cache \\
--memory=4g \\
--shm-size=4g \\
-t ${imagetag} \\
-f ${dockerfile} .
chmod +x build.sh
./build.sh
docker push 10.240.4.159/app/oracledatabase:11.2.0.4
## [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#%E5%90%AF%E6%9C%BA%E5%90%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E8%87%AA%E8%A1%8C%E5%90%AF%E5%8A%A8 "启机后数据库自行启动")启机后数据库自行启动
mkdir -p /docker\_build/oracle\_database/oel\-6.10/04\_run
cd /docker\_build/oracle\_database/oel\-6.10/04\_run
cp /usr/share/zoneinfo/Asia/Shanghai .
vi entrypoint.sh
set -e
/etc/init.d/sshd start
chown -R oracle:oinstall /u01
su - oracle -c "/usr/sbin/entrypoint\_oracle.sh"
chmod +x entrypoint.sh
vi entrypoint\_oracle.sh
set -e
source ~/.bashrc
alert\_log="$ORACLE\_BASE/diag/rdbms/orcl/$ORACLE\_SID/trace/alert\_$ORACLE\_SID.log"
listener\_log="$ORACLE\_BASE/diag/tnslsnr/$HOSTNAME/listener/trace/listener.log"
pfile=$ORACLE\_HOME/dbs/init$ORACLE\_SID.ora
monitor() {
tail -F -n 0 $1 | while read line; do echo -e "$2: $line"; done
}
trap\_db() {
trap "echo 'Caught SIGTERM signal, shutting down...'; stop\_db" SIGTERM;
trap "echo 'Caught SIGINT signal, shutting down...'; stop\_db" SIGINT;
}
check\_shm() {
echo ""
echo "Checking shared memory..."
df -h | grep "Mounted on" && df -h | egrep --color "^.\*/dev/shm" || echo "Shared memory is not mounted."
}
reconfig\_lsnr() {
echo ""
echo "Reconfig listener for hostname : \[$HOSTNAME\]..."
sed -i "s/(HOST.\*)(/(HOST = $HOSTNAME)(/g" /u01/app/oracle/product/11.2.0/db\_1/network/admin/tnsnames.ora
sed -i "s/(HOST.\*)(/(HOST = $HOSTNAME)(/g" /u01/app/oracle/product/11.2.0/db\_1/network/admin/listener.ora
echo "Show tnsnames.ora..."
cat /u01/app/oracle/product/11.2.0/db\_1/network/admin/tnsnames.ora
echo "Show listener.ora..."
cat /u01/app/oracle/product/11.2.0/db\_1/network/admin/listener.ora
}
start\_lsnr() {
echo ""
echo "Starting listener..."
monitor $listener\_log listener &
lsnrctl start | while read line; do echo -e "lsnrctl: $line"; done
MON\_LSNR\_PID=$!
}
start\_db() {
echo ""
echo "Starting database..."
trap\_db
monitor $alert\_log alertlog &
MON\_ALERT\_PID=$!
sqlplus / as sysdba <<-EOF |
pro Starting with pfile='$pfile' ...
startup;
alter system register;
exit 0
EOF
while read line; do echo -e "sqlplus: $line"; done
change\_dpdump\_dir
change\_profile\_default\_limit
wait $MON\_ALERT\_PID
}
stop\_db() {
trap '' SIGINT SIGTERM
shut\_immediate
echo "Shutting down listener..."
lsnrctl stop | while read line; do echo -e "lsnrctl: $line"; done
kill $MON\_ALERT\_PID $MON\_LSNR\_PID
exit 0
}
shut\_immediate() {
ps -ef | grep ora\_pmon | grep -v grep > /dev/null && \\
echo "Shutting down the database..." && \\
sqlplus / as sysdba <<-EOF |
set echo on
shutdown immediate;
exit 0
EOF
while read line; do echo -e "sqlplus: $line"; done
}
change\_dpdump\_dir () {
echo ""
echo "Changing dpdump dir to /u01/app/dumpdir"
sqlplus / as sysdba <<-EOF |
create or replace directory data\_pump\_dir as '/u01/app/dumpdir';
commit;
exit 0
EOF
while read line; do echo -e "sqlplus: $line"; done
}
change\_profile\_default\_limit() {
echo ""
echo "Changing profile default limit : password\_life\_time/failed\_login\_attempts"
sqlplus / as sysdba <<-EOF |
alter profile default limit password\_life\_time unlimited;
alter profile default limit failed\_login\_attempts unlimited;
commit;
exit 0
EOF
while read line; do echo -e "sqlplus: $line"; done
}
check\_shm
reconfig\_lsnr
start\_lsnr
start\_db
chmod +x entrypoint\_oracle.sh
vi Dockerfile
FROM 10.240.4.159/app/oracledatabase:11.2.0.4\-db
ADD Shanghai /etc/localtime
ADD entrypoint.sh /usr/sbin/entrypoint.sh
ADD entrypoint\_oracle.sh /usr/sbin/entrypoint\_oracle.sh
RUN sed -i "s/#PermitRootLogin.\*/PermitRootLogin yes/g" /etc/ssh/sshd\_config && \\
echo "export LANG=en\_US.utf8" >> /etc/profile && \\
echo 'root:ydgw.cn' | chpasswd
ENTRYPOINT \["/usr/sbin/entrypoint.sh"\]
CMD \[""\]
vi build.sh
imagetag="10.240.4.159/app/oracledatabase:11.2.0.4-rundb"
dockerfile="Dockerfile"
docker build --rm \\
--force-rm \\
--no-cache \\
--memory=4g \\
--shm-size=4g \\
-t ${imagetag} \\
-f ${dockerfile} .
chmod +x build.sh
./build.sh
## [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#%E9%83%A8%E7%BD%B2ORACLE%E6%9C%8D%E5%8A%A1 "部署ORACLE服务")部署ORACLE服务
1. 登陆Rancher(1.6.21),编排工具用的是默认的Cattle
2. 应用 - 用户 - 添加应用 - 名称:\[ORACLE\] - 创建(已有服务此步忽略)
3. 添加服务 - 在添加服务页面添写配置如下信息 - 创建
名称: erptest2\-11g
描述: 日结后
选择镜像: 10.240.4.159/app/oracledatabase:11.2.0.4\-database
端口映射: 1521:1522/tcp 15620:22/tcp
网络 - 主机名: erptest2
安全/主机: 主机完全访问权限 内存限制 4096
调度 - 在指定主机上运行全部容器: docker156
4.启动应用(容器) - 检查检查并登录erptest2-11g服务,无问题后`shutdown immediate`数据库
5.登陆宿主机,执行以下命令
docker ps -a | grep oracle
ab409de14588 10.240.4.159/app/oracledatabase:11.2.0.4\-database "/.r/r /entrypoint.s…" 7 minutes ago Up 7 minutes r-Oracle-erptest1\-11g\-1\-c16a25ba
295f99a4f7d4 10.240.4.159/app/oracledatabase:11.2.0.4\-database "/.r/r /entrypoint.s…" 3 hours ago Up 3 hours r-Oracle-erptest2\-1\-efd39217
cd /docker\_mnt/oracledb/erptest2\-20180817
docker cp 295f99a4f7d4:/u01/app/oradata .
docker cp 295f99a4f7d4:/u01/app/dumpdir .
docker cp 295f99a4f7d4:/u01/app/oracle/fast\_recovery\_area .
docker cp 295f99a4f7d4:/u01/app/oracle/diag .
docker cp 295f99a4f7d4:/u01/app/oracle/product/11.2.0/db\_1/dbs .
6.升级erptest2-11g
卷 - 添加卷: /etc/localtime:/etc/localtime:ro
/docker\_mnt/oracledb/erptest2\-20180817/oradata:/u01/app/oradata
/docker\_mnt/oracledb/erptest2\-20180817/dpdump:/u01/app/dumpdir
/docker\_mnt/oracledb/erptest2\-20180817/fast\_recovery\_area:/u01/app/oracle/fast\_recovery\_area
/docker\_mnt/oracledb/erptest2\-20180817/diag:/u01/app/oracle/diag
/docker\_mnt/oracledb/erptest2\-20180817/dbs:/u01/app/oracle/product/11.2.0/db\_1/dbs
docker 限制内存, 报 not support swap limit capabilities
参考:[https://segmentfault.com/q/1010000002888521](https://segmentfault.com/q/1010000002888521)
Adjust memory and swap accounting
When users run Docker, they may see these messages when working with an image:
WARNING: Your kernel does not support cgroup swap limit. WARNING: Your
kernel does not support swap limit capabilities. Limitation discarded.
To prevent these messages, enable memory and swap accounting on your system. To enable these on system using GNU GRUB (GNU GRand Unified Bootloader), do the following.
Log into Ubuntu as a user with sudo privileges.
Edit the /etc/default/grub file.
Set the GRUB\_CMDLINE\_LINUX value as follows:
GRUB\_CMDLINE\_LINUX="cgroup\_enable=memory swapaccount=1"
Save and close the file.
Update GRUB.
$ sudo update-grub
Reboot your system.
## [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#%E5%8F%82%E8%80%83 "参考")参考
- [基于Oracle Linux 7.5实现了Oracle Database 11gR2 企业版容器化运行](https://gitee.com/rancococ-code/docker-oracle11g)
- [利用Docker建立Oracle 11g实验环境](https://zhangjoto.github.io/li-yong-dockerjian-li-oracle-11gshi-yan-huan-jing.html)
- docker 限制内存, 报`not support swap limit capabilities`,解决方法:
Edit the /etc/default/grub file.
Set the GRUB\_CMDLINE\_LINUX value as follows:
GRUB\_CMDLINE\_LINUX="cgroup\_enable=memory swapaccount=1"
Save and close the file.
Update GRUB.
$ sudo update-grub
Reboot your system.
## [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#expect%E7%9A%84%E7%94%A8%E6%B3%95%E7%A4%BA%E4%BE%8B "expect的用法示例")expect的用法示例
RUN yum -y install expect && \\
unzip -qo /tmp/p6880880\_112000\_Linux-x86\-64.zip -d /tmp && \\
unzip -qo /tmp/p27967757\_112040\_Linux-x86\-64.zip -d /tmp && \\
unzip -qo /tmp/p27923163\_112040\_Linux-x86\-64.zip -d /tmp && \\
rm -rf /u01/app/oracle/product/11.2.0/db\_1/OPatch && \\
chown -R oracle:oinstall /tmp/OPatch && \\
mv /tmp/OPatch /u01/app/oracle/product/11.2.0/db\_1/ && \\
printf "%s\\n" '#!/usr/bin/expect' \\
'spawn opatch apply -local /tmp/27967757/27734982/' \\
'expect "\*proceed\*" {send "y\\r"}' \\
'expect "\*Email\*" {send "\\r"}' \\
'expect "\*security\*" {send "y\\r"}' \\
'expect "\*patching" {send "y\\r"}' \\
'interact' \\
>> /tmp/27967757/27734982/psu\_apply.sh && \\
printf "%s\\n" '#!/usr/bin/expect' \\
'spawn opatch apply -local /tmp/27923163/' \\
'expect "\*proceed\*" {send "y\\r"}' \\
'expect "\*Email\*" {send "\\r"}' \\
'expect "\*security\*" {send "y\\r"}' \\
'expect "\*patching" {send "y\\r"}' \\
'interact' \\
>> /tmp/27923163/jvm\_apply.sh && \\
chmod +x /tmp/27967757/27734982/psu\_apply.sh && \\
chmod +x /tmp/27923163/jvm\_apply.sh && \\
su - oracle -c "/tmp/27967757/27734982/psu\_apply.sh" && \\
su - oracle -c "/tmp/27923163/jvm\_apply.sh"
## [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#%E6%95%B4%E5%90%88%E6%88%90%E4%B8%80%E4%B8%AAdockerfile "整合成一个dockerfile")整合成一个dockerfile
### [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#%E5%88%B6%E4%BD%9C%E9%95%9C%E5%83%8F "制作镜像")制作镜像
FROM 10.240.4.159/os/oraclelinux:6.10
ADD Shanghai /etc/localtime
ADD rlwrap\-0.42.tar.gz /tmp/
ADD p13390677\_112040\_Linux-x86\-64\_1of7.zip /tmp/
ADD p13390677\_112040\_Linux-x86\-64\_2of7.zip /tmp/
ADD p6880880\_112000\_Linux-x86\-64.zip /tmp/
ADD p27967757\_112040\_Linux-x86\-64.zip /tmp/
ADD p27923163\_112040\_Linux-x86\-64.zip /tmp/
ADD db\_install.rsp /tmp/
ADD ocm.rsp /tmp/ocm.rsp
ADD p6880880\_112000\_Linux-x86\-64.zip /tmp/
ADD p27967757\_112040\_Linux-x86\-64.zip /tmp/
ADD p27923163\_112040\_Linux-x86\-64.zip /tmp/
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle && \\
yum -y install oracle-rdbms-server\-11gR2-preinstall unzip readline-devel.x86\_64 lrzsz && \\
cd /tmp/rlwrap\-0.42 && ./configure && make && make install && \\
echo "Create /u01/app dir..." && \\
mkdir -p -m 755 /u01/app/dumpdir && \\
mkdir -p -m 755 /u01/app/oradata && \\
mkdir -p -m 755 /u01/app/oraInventory && \\
mkdir -p -m 755 /u01/app/oracle && \\
mkdir -p -m 755 /u01/app/oracle/product/11.2.0/db\_1 && \\
chown -R oracle:oinstall /u01 && \\
unzip -oq /tmp/p13390677\_112040\_Linux-x86\-64\_1of7.zip -d /tmp/ && \\
unzip -oq /tmp/p13390677\_112040\_Linux-x86\-64\_2of7.zip -d /tmp/ && \\
chown -R oracle:oinstall /tmp/database && \\
printf "%s\\n" 'export ORACLE\_SID=orcl' \\
'export ORACLE\_BASE=/u01/app/oracle' \\
'export ORACLE\_HOME=$ORACLE\_BASE/product/11.2.0/db\_1' \\
'export LD\_LIBRARY\_PATH=$ORACLE\_HOME/lib:$ORACLE\_HOME/lib32' \\
'export PATH=$PATH:$ORACLE\_HOME/bin:$ORACLE\_HOME/OPatch' \\
'export NLS\_LANG=AMERICAN\_AMERICA.ZHS16GBK' \\
'export NLS\_DATE\_FORMAT="yyyy-mm-dd hh24:mi:ss"' \\
'alias sqlplus="rlwrap sqlplus"' \\
'alias rman="rlwrap rman"' \\
>>/home/oracle/.bash\_profile && \\
cat /etc/security/limits.conf | grep -v oracle | tee /etc/security/limits.conf && \\
su oracle -c "/tmp/database/runInstaller -ignorePrereq -ignoreSysPrereqs -waitforcompletion -silent -responseFile /tmp/db\_install.rsp 2>&1" && \\
/u01/app/oraInventory/orainstRoot.sh && \\
/u01/app/oracle/product/11.2.0/db\_1/root.sh && \\
unzip -oq /tmp/p6880880\_112000\_Linux-x86\-64.zip -d /tmp/ && \\
rm -rf /u01/app/oracle/product/11.2.0/db\_1/OPatch && \\
chown -R oracle:oinstall /tmp/OPatch && \\
mv /tmp/OPatch /u01/app/oracle/product/11.2.0/db\_1/ && \\
unzip -qo /tmp/p27967757\_112040\_Linux-x86\-64.zip -d /tmp && \\
unzip -qo /tmp/p27923163\_112040\_Linux-x86\-64.zip -d /tmp && \\
su - oracle -c "opatch apply -silent -ocmrf /tmp/ocm.rsp -local /tmp/27967757/27734982" && \\
su - oracle -c "opatch apply -silent -ocmrf /tmp/ocm.rsp -local /tmp/27923163" && \\
printf "%s\\n" '\[GENERAL\]' \\
'RESPONSEFILE\_VERSION="11.2"' \\
'CREATE\_TYPE="CUSTOM"' \\
'\[oracle.net.ca\]' \\
'INSTALLED\_COMPONENTS={"server","net8","javavm"}' \\
'INSTALL\_TYPE=""typical""' \\
'LISTENER\_NUMBER=1' \\
'LISTENER\_NAMES={"LISTENER"}' \\
'LISTENER\_PROTOCOLS={"TCP;1521"}' \\
'LISTENER\_START=""LISTENER""' \\
'NAMING\_METHODS={"TNSNAMES","ONAMES","HOSTNAME"}' \\
'NSN\_NUMBER=1' \\
'NSN\_NAMES={"EXTPROC\_CONNECTION\_DATA"}' \\
'NSN\_SERVICE={"PLSExtProc"}' \\
'NSN\_PROTOCOLS={"TCP;HOSTNAME;1521"}' \\
>>/tmp/netca.rsp && \\
su oracle -c "/u01/app/oracle/product/11.2.0/db\_1/bin/netca -silent -responseFile /tmp/netca.rsp" && \\
printf "%s\\n" '\[GENERAL\]' \\
'RESPONSEFILE\_VERSION = "11.2.0"' \\
'OPERATION\_TYPE = "createDatabase"' \\
'\[CREATEDATABASE\]' \\
'GDBNAME = "orcl"' \\
'DATABASECONFTYPE = "SI"' \\
'SID = "orcl"' \\
'TEMPLATENAME = "General\_Purpose.dbc"' \\
'SYSPASSWORD = "Center08"' \\
'SYSTEMPASSWORD = "Center08"' \\
'DATAFILEDESTINATION=/u01/app/oradata' \\
'RECOVERYAREADESTINATION=/u01/app/oradata' \\
'STORAGETYPE=FS' \\
'CHARACTERSET="ZHS16GBK"' \\
'INITPARAMS="java\_jit\_enabled=false,memory\_target=0,sga\_target=2048,pga\_aggregate\_target=300,processes=300,open\_cursors=300"' \\
'AUTOMATICMEMORYMANAGEMENT="False"' \\
> /tmp/dbca.rsp && chown oracle:oinstall /tmp/dbca.rsp && chmod +x /tmp/dbca.rsp && \\
su oracle -c "/u01/app/oracle/product/11.2.0/db\_1/bin/dbca -silent -responseFile /tmp/dbca.rsp" && \\
sed -i "s/#PermitRootLogin.\*/PermitRootLogin yes/g" /etc/ssh/sshd\_config && \\
echo "export LANG=en\_US.utf8" >> /etc/profile && \\
yum clean all && \\
rm -rf /tmp/\* && rm -rf /var/log/\* && rm -rf /var/cache/\*
### [](http://dbase.cc/2018/09/19/docker/14_docker%E5%BA%94%E7%94%A8-%E9%83%A8%E7%BD%B2ORACLE-11g%E5%8D%95%E5%AE%9E%E4%BE%8B%E6%95%B0%E6%8D%AE%E5%BA%93/#%E6%B7%BB%E5%8A%A0%E5%88%B0rancher%E4%B8%AD "添加到rancher中")添加到rancher中
1. 登陆Rancher(1.6.21),编排工具用的是默认的Cattle
2. 应用 - 用户 - 添加应用 - 名称:\[ORACLE\] - 创建(已有服务此步忽略)
3. 添加服务 - 在添加服务页面添写配置如下信息 - 创建
名称: dev-erp
选择镜像: 10.240.4.159/app/oracledatabase:11.2.0.4\-run
端口映射: 1521:1521/tcp 16221:22/tcp
网络 - 主机名: dev-erp
安全/主机: 主机完全访问权限 内存限制 4096
调度 - 在指定主机上运行全部容器: docker162
4.启动应用(容器) - 检查检查并登录dev-erp服务,无问题后`shutdown immediate`数据库
5.登陆宿主机,执行以下命令
docker ps -a | grep erp
cdf49b075fb6 10.240.4.159/app/oracledatabase:11.2.0.4\-run "/.r/r /usr/sbin/ent…" 38 minutes ago Up 38 minutes r-Oracle-erp-dev\-1\-77fbbce2
mkdir -p /docker\_mnt/oracledb/dev-erp\-20180925
cd /docker\_mnt/oracledb/dev-erp\-20180925
docker cp cdf49b075fb6:/u01/app/oradata .
docker cp cdf49b075fb6:/u01/app/dumpdir .
docker cp cdf49b075fb6:/u01/app/oracle/fast\_recovery\_area .
docker cp cdf49b075fb6:/u01/app/oracle/diag .
docker cp cdf49b075fb6:/u01/app/oracle/product/11.2.0/db\_1/dbs .
6.升级
卷 - 添加卷:
/docker\_mnt/oracledb/dev-pos\-20180925/oradata:/u01/app/oradata
/docker\_mnt/oracledb/dev-pos\-20180925/dpdump:/u01/app/dumpdir
/docker\_mnt/oracledb/dev-pos\-20180925/fast\_recovery\_area:/u01/app/oracle/fast\_recovery\_area
/docker\_mnt/oracledb/dev-pos\-20180925/diag:/u01/app/oracle/diag
/docker\_mnt/oracledb/dev-pos\-20180925/dbs:/u01/app/oracle/product/11.2.0/db\_1/dbs
@@ -0,0 +1,119 @@
---
page-title: "MySQL Change a User Password Command Tutorial - nixCraft"
url: https://www.cyberciti.biz/faq/mysql-change-user-password/
date: "2024-11-01 14:51:07"
---
> ALTER USER 'user'@'hostname' IDENTIFIED BY 'newPass';
---
[![See all MySQL Database Server related FAQ](https://www.cyberciti.biz/media/new/category/old/mysqllogo.gif)](https://www.cyberciti.biz/faq/category/mysql/ "See all MySQL Database Server related FAQ")
I would like to change a password for a user called tom using UNIX / Linux command line option. How do I change a user password on MySQL server?
You need to use mysql (or mysql.exe on MS-Windows based system) command on a Linux or Unix like operating system. Open a terminal app or ssh session. Type the following command at the shell prompt to login as a root user. The syntax is as follows for Unix like operating system.
| Tutorial details |
| --- |
| Difficulty level | [Easy](https://www.cyberciti.biz/faq/tag/easy/ "See all Easy Linux / Unix System Administrator Tutorials") |
| Root privileges | No |
| Requirements | Linux or Unix terminal |
| Category | [Database Server](https://www.cyberciti.biz/faq/mysql-change-user-password/#Database_Server "See ALL other tutorials in 'Database Server' category") |
| OS compatibility | BSD • [Linux](https://www.cyberciti.biz/faq/category/linux/ "See all Linux distributions tutorials") • [macOS](https://www.cyberciti.biz/faq/category/mac-os-x/ "See all macOS (OS X) tutorials") • [Unix](https://www.cyberciti.biz/faq/category/unix/ "See all Unix tutorials") • [Windows](https://www.cyberciti.biz/faq/category/windows/ "See all MS Windows OS compatible tutorials") • WSL |
| Est. reading time | 3 minutes |
## How to change user password on mysql
Mysql change user password using the following method:
1. Open the bash shell and connect to the server as root user:
**mysql -u root -h localhost -p**
2. Run ALTER mysql command:
**ALTER USER 'userName'@'localhost' IDENTIFIED BY 'New-Password-Here';**
3. Finally type SQL command to reload the grant tables in the mysql database:
FLUSH PRIVILEGES;
Please note that use mysql.exe on MS-Windows host as follows (first change directory where mysql.exe is located \[example: “C:\\Program Files\\mysql\\mysql-5.0.77-win32\\bin“\]. Let us see examples and syntax in details.
## mysql command to change a user password
Login as root from the shell:
`$ mysql -u root -p`
Or admin user that can do DBA duties. For example:
`$ mysql -u admin -h 10.83.200.253 -p`
Where,
- \-u root OR \-u admin : MySQL server admin user name (root is default on most systems).
- \-h 10.83.200.253 : MySQL server IP address or hostname such as server1.cyberciti.biz.
- \-p : Prompt for the password.
Switch to mysql database (type command at mysql> prompt, do not include string “mysql>”):
`mysql> **use mysql;**`
The syntax is as follows for **mysql database server version 5.7.5** or older:
SET PASSWORD FOR 'user-name-here'@'hostname' \= PASSWORD('new-password');
For **mysql database server version 5.7.6 or newer** use the following syntax:
ALTER USER 'user'@'hostname' IDENTIFIED BY 'newPass';
You can also use the following sql syntax:
UPDATE mysql.user SET Password\=PASSWORD('new-password-here') WHERE USER\='user-name-here' AND Host\='host-name-here';
In this example, change a password for a user called tom:
SET PASSWORD FOR 'tom'@'localhost' \= PASSWORD('foobar');
OR
UPDATE mysql.user SET Password\=PASSWORD('foobar') WHERE USER\='tom' AND Host\='localhost';
Sample outputs:
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
Feel free to replace the values for “tom” (user), “localhost” (hostname), and “foobar” (password) as per your requirements. Finally, type the following command to reload privileges:
Sample outputs:
Query OK, 0 rows affected (0.00 sec)
To exit from mysql> prompt, enter:
## Changing the MySQL root or user password using the mysqladmin command
We can also use the mysqladmin CLI to alter the MySQL password. The syntax for the mysqladmin command is as follows:
`$ mysqladmin --user={USER_NAME} password "{NEW_PASSWORD_HERE}" $ mysqladmin --user=root password "5b350f65542fdb74e74ef7b815f86ad5" $ mysqladmin --user=root --host=192.168.2.200 --password password "5b350f65542fdb74e74ef7b815f86ad5"`
Where,
- \--user=root : User for login if not current user.
- \--password : Prompt for password to use when connecting to server.
- \--host=192.168.2.200 : Connect to MySQL server host by given IP address or hostname.
- password "5b350f65542fdb74e74ef7b815f86ad5" : Change old password to “5b350f65542fdb74e74ef7b815f86ad5” in current format.
### Verify the new password settings
User or you can test new password using the following shell syntax:
`$ mysql -u tom -p`
When promoted enter new password you set earlier for tom user.
## Sample session
[![Fig.01: Mysql Updating / Changing password (click to enlarge)](https://www.cyberciti.biz/media/new/faq/2007/07/mysql-update-password-300x232.png "HowTo: Mysql Update Password SQL Command")](https://www.cyberciti.biz/faq/mysql-change-user-password/mysql-update-password/)
Fig.01: Mysql Updating / Changing password (click to enlarge)
## Summing up
You learned how to change MySQL or MariaDB user password using the mysql command line on Linux, Unix, macOS, \*BSD and Windows operating systems. For more info please read the mysql manual page by typing the [man command](https://bash.cyberciti.biz/guide/Man_command "Man command - Linux Bash Shell Scripting Tutorial Wiki") or passing the [\--help option](https://bash.cyberciti.biz/guide/Help_command "help command - Linux Bash Shell Scripting Tutorial Wiki") under Unix-like systems. For instance:
`$ man mysql $ mysql --help`
🥺 Was this helpful? Please add [a comment to show your appreciation or feedback](https://www.cyberciti.biz/faq/mysql-change-user-password/#respond "Please add your comment below ↓ to show your appreciation or feedback to the author").
![nixCrat Tux Pixel Penguin](https://www.cyberciti.biz/media/new/cms/2024/04/tux_96.png)
Hi! 🤠
I'm Vivek Gite, and I write [about](https://www.cyberciti.biz/tips/about-us "About the author and nixCraft") Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my [RSS feed](https://www.cyberciti.com/atom/atom.xml "Get nixCraft updates using RSS feed") or [email newsletter](https://newsletter.cyberciti.com/subscription?f=1ojtmiv8892KQzyMsTF4YPr1pPSAhX2rq7Qfe5DiHMgXwKo892di4MTWyOdd976343rcNR6LhdG1f7k9H8929kMNMdWu3g "Get nixCraft updates using Email") for updates.
@@ -0,0 +1,531 @@
---
page-title: "Percona XtraDB setup - Jite.eu"
url: https://jite.eu/2023/12/7/percona-setup/
date: "2024-11-26 18:32:24"
---
I have been trying to write a post about Percona - and especially the operators - for a while. Its a tool which I first encountered a while back, while researching an alternative to KubeDB (another good project) after their licensing changes.
I never got too much into it back then, seeing I decided to go with managed databases at that point, but after visiting [Civo Navigate](https://jite.eu/2023/10/13/civo-navigate-eu/) back in september and a followup chat with percona I decided to dive a bit deeper into it.
I really like the ease of setting it up, and the fact that they support a wide array of database engines makes their operators very useful.
In this post, we will focus on XtraDB, which is their mysql version with backup and clustering capabilities.
We will go through the installation of the operator as well as what I find most important in the custom resource which will allow us to provision a full XtraDb cluster with backups and proxying.
This is what Ive been using the most, and Ill try to create a post at a later date with some benchmarks to show how it compares with other databases.
Running databases in kubernetes (or docker) have earlier been a big no-no, this is not as much of an issue now a days, especially when using good storage types.
In this writeup, Ill use my default storage class which on my k3s cluster is a mounted disk on Hetzner, they are decent in speed, but seeing its just a demo, the speed doesnt matter much!
## Prerequisites[Permalink](https://jite.eu/2023/12/7/percona-setup/#prerequisites "Permalink")
Percona xtradb makes use of cert-manager to generate TLS certificated, it will automatically create an issuer (namespaced) for your resources, but you do need to have cert-manager installed.
This post will *not* cover the installation, and I would recommend that you take a look at the official [cert-manager doucmentation](https://cert-manager.io/) for installation instructions.
## Helm installation[Permalink](https://jite.eu/2023/12/7/percona-setup/#helm-installation "Permalink")
The first thing we have to do is to install the helm charts and deploy them to a kubernetes cluster.
In this post, we will as I said earlier, use the Mysql version of percona, and we will use the operator that is supplied by percona.
If you want to dive deeper, you can find the [documentation here](https://docs.percona.com/percona-operator-for-mysql/pxc/index.html)!
Percona supplies their own helm charts for the operator via GitHub, so adding it to helm is easily done with
```
helm repo add percona https://percona.github.io/percona-helm-charts/
helm repo update
```
If you havent worked with helm before, the above snippet will add it to your local repository and allow you to install charts from the repo we add.
If you just want to install the operator right away, you can do this by invoking the `helm install` command, but we might want to look a bit at the values we can pass to the operator first, to customize it slightly.
The full chart can be found on [GitHub](https://github.com/percona/percona-helm-charts/tree/main/charts/pxc-operator), where you should be able to see all the customizable values in the `values.yml` file (the ones set are the default values).
In the case of this operator, the default values are quite sane, it will create a service account and set up the RBAC values required for it to monitor the CRD:s.
But, one thing that you might want to change is the value for `watchAllNamespaces`.
The default value here is `false`, which will only allow you to create new clusters in the same namespace as the operator. This might be a good idea if you have multiple tenants in the cluster, and you dont want all of them to have access to the operator, while for me, making it a cluster-wide operator is far more useful.
To tell the helm chart that we want it to change the said value, we can either pass it directly in the install command, or we can set up a `values` file for our specific installation.
When you change a lot of values, or you want to source-control your overrides, a file is for sure more useful.
To create an override file, you need to create a `values.yml` (you can actually name it whatever you want) where you set the values you want to change, the format is the same as in the above repository values.yml file, so if we only want to change the namespaces parameter it would look like this:
But any value in the default values file can be changed.
Installing the operator with the said values file is done by invoking the following command:
```
helm install percona-xtradb-operator percona/pxc-operator -f values.yml --namespace xtradb --create-namespace
```
The above command will install the chart as `percona-xtradb-operator` in the `xtradb` namespace.
You can change namespace as you wish, and it will create the namespace for you.
If you dont want the namespace to be created (using another one or default) skip the `--create-namespace` flag.
Without using the namespace flag, the operator will be installed in the `default` namespace.
The file we changed is passed via the `-f` flag, and will override any values already defined in the default values file.
When we set the `watchAllNamespaces` value, the helm installation will create cluster wide roles and bindings, this does not happen if its not set but is required for the operator to be able to look for and manage clusters in all namespaces.
If you dont want to use a custom values file, passing values to helm is done easily by the following flags:
```
helm install percona-xtradb-operator percona/pxc-operator --namespace xtradb --set watchAllNamespaces=true
```
### Multi Arch clusters[Permalink](https://jite.eu/2023/12/7/percona-setup/#multi-arch-clusters "Permalink")
Currently, the operator images (and other as well) are only available for the AMD64 architecture, so in cases where you use nodes which are based on another architecture (like me who use a lot of ARM64), you might want to set the `nodeSelector` value in your override to only use amd64 nodes:
```
nodeSelector:
kubernetes.io/arch: amd64
```
To update your installation, instead of using `install` (which will make helm yell about already having it installed) you use the upgrade command:
```
helm upgrade percona-xtradb-operator percona/pxc-operator -f values.yml --namespace xtradb
```
If you are lazy like me, you can actually use the above command with the `--install` flagg to install as well.
## Percona xtradb CRD:s[Permalink](https://jite.eu/2023/12/7/percona-setup/#percona-xtradb-crds "Permalink")
As with most operators, the xtradb operator comes with a few custom resource definitions to allow easy creation of new clusters.
We can install a new db cluster with helm as well, but I prefer to version control my resources and I really enjoy using the CRD:s supplied by operators I use, so we will go with that!
So, to install a new percona xtradb cluster, we will create a new kubernetes resource as a yaml manifest.
The cluster uses the api version `pxc/percona.com/v1` and the kind we are after is `PerconaXtraDBCluster`.
There are a lot of configuration that can be done, and a lot you really should look deeper into if you are intending to run the cluster in production (especially the TLS options and how to encrypt the data at rest).
But to keep this post under a million words, Ill focus on the things we need to just get a cluster up and running!
As with all kubernetes resources, we will need a bit of metadata to allow kubernetes to know where and what to create:
```
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBCluster
metadata:
name: cluster1-test
namespace: private
```
In the above manifest, Im telling kubernetes that we want a PerconaXtraDBCluster set up in the `private` namespace using the name `cluster1-test`.
There are a few extra finalizers we can add to the metadata to hint to the operator how we want it to handle removal of clusters, the ones that are available are the following:
- delete-pods-in-order
- delete-pxc-pvc
- delete-proxysql-pvc
- delete-ssl
These might be important to set up correctly, as they will allow for the operator to remove PVC:s and other configurations which we want it to remove on cluster deletion.
If you do want to save the claims and such, you should *not* include the finalizers in the metadata.
### Sepc[Permalink](https://jite.eu/2023/12/7/percona-setup/#sepc "Permalink")
After the metadata have been set, we want to start working on the specification of the resource.
There is a lot of customization tha can be done in the manifest, but the most important sections are the following:
- `tls` (which allows us to use cert-manager to configure mTLS for the cluster)
- `upgradeOptions` (which allows us to set up upgrades of the running mysql servers)
- `pxc` (the configuration for the actual percona xtradb cluster)
- `haproxy` (configuration for the HAProxy which runs in front of the cluster)
- `proxysql` (configuration for the ProxySQL instances in front of the cluster)
- `logcollector` (well, for logging of course!)
- `pmm` (Percona monitor and management, which allows us to monitor the instances)
- `backup` (this one you can probably guess the usage for!)
#### TLS[Permalink](https://jite.eu/2023/12/7/percona-setup/#tls "Permalink")
In this writeup I will leave this with the default values (and not even add it to the manifest), that way the cluster will create its own issuer and just issue tls certificates as it needs to, but if you want the certificate to be a bit more constrained, you can here set boh which issuer to use (or create) as well as the SANs to use.
#### UpgradeOptions[Permalink](https://jite.eu/2023/12/7/percona-setup/#upgradeoptions "Permalink")
Keeping your database instances up to date automatically is quite a sweet feature. Now, we dont always want to do this seeing we sometimes want to use the exact same version in the cluster as in another database (if we got multiple environments for example) or if we want to stay on a version we know is stable.
But, if we want to live on the edge and use the latest version, or stay inside a patch version of the current version we use this section is very good.
There are three values that can be set in the `upgradeOptions` section, and they handle the scheduling, where to look and the version constraints we want to sue.
```
upgradeOptions:
versionServiceEndpoint: ' https://check.percona.com'
apply: '8.0-latest'
schedule: '0 4 * * *'
```
The `versionServiceEndpoint` flag should probably always be `https://check.percona.com`, but if there are others you can probably switch. Im not sure about this though, so to be safe, I keep it at the default one!
`apply` can be used to set a constraint or disable the upgrade option all together.
If you dont want your installations to upgrade, just set it to `disabled`, then it will not run at all.
In the above example, Ive set the version constraint to use the `latest` version of the 8.0 mysql branch.
This can be set to a wide array of values, for more detailed info, I recommend checking the [percona docs](https://docs.percona.com/percona-operator-for-mysql/pxc/update.html#automated-upgrade).
The Schedule is a cron-formatted value, in this case, at 4am every day, to continuously check, set it to `* * * * *`!
#### pxc[Permalink](https://jite.eu/2023/12/7/percona-setup/#pxc "Permalink")
The pxc section of the manifest handles the actual cluster setup.
It got quite a few options, and Ill only cover the ones I deem most important to just run a cluster, while as said earlier, if you are intending to run this in production, make sure you check the documentation or read the CRD specification for all available options.
```
spec:
pxc:
nodeSelector:
kubernetes.io/arch: amd64
size: 3
image: percona/percona-xtradb-cluster:8.0.32-24.2
autoRecovery: true
expose:
enabled: false
resources:
requests:
memory: 256M
cpu: 100m
limits:
memory: 512M
cpu: 200m
volumeSpec:
persistentVolumeClaim:
storageClassName: 'hcloud-volumes'
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
```
The size variable will tell the operator how many individual mysql instances we want to run.
3 is a good one, seeing most clustered programs prefer 3 or more instances.
The image should presumably be one of the percona images in this case, to allow updates and everything to work as smoothly as possible.
I havent peeked enough into the images, but I do expect that there is some custom things in the images to make them run fine, which makes me want to stick to the default images rather than swapping to another!
`autoRecovery` should probably almost always be set to `true`, this will allow the Automatic Crash Recovery functionality to work, which I expect is something most people prefer to have.
I would expect that you know how `resources` works in kubernetes, but I included it in the example to make sure that its seen, as you usually want to be able to set those yourself. The values set above are probably quite a bit low when you want to be able to use the database for more than just testing, so set them accordingly, just remember that its for each container, not the whole cluster!
The `volumeSpec` is quite important. In the above example, I use my default volume type, which is a RWO type of disk the size is set to 10Gi. The size should probably either be larger or possible to expand on short notice.
There are two more keys which can be quite useful if you wish to customize your database a bit more, and especially if you want to finetune it.
Percona xtradb comes with quite sane defaults, but when working with databases, its not unusual that you need to enter some custom params to the `my.cnf` file.
##### Environment variables[Permalink](https://jite.eu/2023/12/7/percona-setup/#environment-variables "Permalink")
The percona pxc configuration does not currently allow bare environment variables (from what I can see), but this is not a huge issue, seeing the spec allows for a `envVarsSecret` to be set.
The secret must of course be in the same namespace as the resources, but any variables in it will be loaded as environment variables into the pod.
Im not certain what environment variables are available for the pxc section, but will try to update this part when I got more info on it.
##### Configuration[Permalink](https://jite.eu/2023/12/7/percona-setup/#configuration "Permalink")
The `configuration` property expects a string, the string is a mysql configuration file, i.e, the values that you usually put in the `my.cnf` file.
```
spec:
pxc:
configuration: |
[mysqld]
innodb_write_io_threads = 8
innodb_read_io_threads = 8
```
#### HAProxy and ProxySQL[Permalink](https://jite.eu/2023/12/7/percona-setup/#haproxy-and-proxysql "Permalink")
Percona allows you to choose between two proxies to use for loadbalancing, which is quite nice.
The available proxies are [HAProxy](https://www.haproxy.org/) and [ProxySQL](https://proxysql.com/), both valid choices which are well tried in the industry for loadbalancing and proxying.
The one you choose should have the property `enabled` set to true, and the other one set to false.
The most “default” configuration you can use would look like this:
```
# With haproxy
spec:
haproxy:
nodeSelector:
kubernetes.io/arch: amd64
enabled: true
size: 3
image: percona/percona-xtradb-cluster-operator:1.13.0-haproxy
resources:
requests:
memory: 256M
cpu: 100m
# With proxysql
spec:
proxysql:
nodeSelector:
kubernetes.io/arch: amd64
enabled: true
size: 3
image: percona/percona-xtradb-cluster-operator:1.13.0-proxysql
resources:
requests:
memory: 256M
cpu: 100m
volumeSpec:
emptyDir: {}
```
The size should be at the least 2 (can be set to 1 if you use `allowUnsafeConfigurations` but thats not recommended).
The image is just as with the pxc configuration most likely best to use the percona provided images (in this case 1.13.0, same version as the percona operator).
As always, the resources aught to be finetuned to fit your needs, the above is on the lower end, but could work okay for a smaller cluster which does not have huge traffic.
Both of the sections allow for (just as with pxc section) to supply both environment variables via the `envVarsSecret` as well as a `configuration` property. The configuration does of course differ and I would direct you to the proxy documentation for more information about those!
Now, something quite important to note here is that if you supply a configuration file, you need to supply the full file, it doesnt merge the default file but replaces it in full.
So if you want to finetune the configuration, include the default configuration as well (and change it), this applies to both haproxy and proxysql and will work the same if you use a configmap, secret or directly accessing the `configuration` key.
The choice of proxy might be important to decide on at creation of the resource, if you use proxysql, you can (with a restart of the pods) switch to haproxy, while if you choose haproxy, you cant change the cluster to use proxysql. So I would highly recommend that you decide which to use before creating the cluster.
There are a lot more variables you can set here, and all of them can be found at the [documentation page](https://docs.percona.com/percona-operator-for-mysql/pxc/operator.html#haproxy-section).
### LogCollector[Permalink](https://jite.eu/2023/12/7/percona-setup/#logcollector "Permalink")
Logs are nice, we love logs! Percona seems to as well, because they supply us with a section for configuring a [fluent bit](https://fluentbit.io/) log collector right in the manifest! No need for any sidecars, just turn it on and start collecting :)
If you already have some type of logging system which captures all pods logs and such, this might not be useful and you can set the `enabled` value to `false` and ignore this section.
The log collector specification is quite slim, and looks something like this:
```
spec:
logcollector:
enabled: true
image: percona/percona-xtradb-cluster-operator:1.13.0-logcollector
resources:
requests:
memory: 64M
cpu: 50m
configuration: ...
```
The default values might be enough, but the fluent bit [documentation](https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/yaml/configuration-file) got quite a bit of customization available if you really want to!
### PPM (Monitoring)[Permalink](https://jite.eu/2023/12/7/percona-setup/#ppm-monitoring "Permalink")
The xtradb server is able to push metrics and monitoring data to a PMM (percona monitoring & management) service, now, this is not installed with the cluster and needs to be set up separately, but if you want to make use of this (which I recommend, seeing how important monitoring is!) the documentation can be found [here](https://docs.percona.com/percona-monitoring-and-management/index.html).
I havent researched this too much yet, but personally I would have loved to be able to scrape the instances with prometheus and have my dashboards in my standard Grafana instance, which I will ask percona about if its possible. In either case, Ill update this part with more information when I figure it out!
### Backups[Permalink](https://jite.eu/2023/12/7/percona-setup/#backups "Permalink")
Backups, one of the most important parts of keeping a database up and running without angry customers questioning you about where their 5 years of data has gone after a database failure… Well, percona helps us with that too, thankfully!
The percona backup section allows us to define a bunch of different storage engines to use to store our backups, this is great, because we dont always want to store our backups on the same disks or systems as we run our cluster. The most useful way to store backups is likely to store them in a s3 compatible storage, which can be done, but if you really want to you can store them either in a PV or even on the local disk of the node. We can even define multiple storages to use with different schedules!
```
spec:
backup:
image: perconalab/percona-xtradb-cluster-operator:main-pxc8.0-backup
storages:
s3Storage:
type: 's3'
nodeSelector:
kubernetes.io/arch: amd64
s3:
bucket: 'my-bucket'
credentialsSecret: 'my-credentials-secret'
endpointUrl: 'the-s3-service-i-like-to-use.com'
region: 'eu-east-1'
local:
type: 'filesystem'
nodeSelector:
kubernetes.io/arch: amd64
volume:
persistentVolumeClaim:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10G
schedule:
- name: 'daily'
schedule: '0 0 * * *'
keep: 3
storageName: s3Storage
- name: 'hourly'
schedule: '0 * * * *'
keep: 2
storageName: 'local'
```
In the above yaml, we have set up two different storage types. One `s3` type and one `filesystem` type.
The s3 type is pointed to a bucket in my special s3-compatible storage while the filesystem one makes use of a persistent volume.
In the `schedule` section, we set it to create a daily backup to the s3 storage (and keep the 3 latest ones) while the local storage one will keep 3 and run every hour.
Each section under `storages` will spawn a new container, so we can change the resources and such for each of them (and you might want to) and they will by default re-try creation of the backup 6 times (can be changed by setting the `spec.backup.backoffLimit` to a higher value).
There is *a lot* of options for backups, and I would highly recommend to take a look at the [docs](https://docs.percona.com/percona-operator-for-mysql/pxc/operator.html#backup-section) for it!
##### Point in time[Permalink](https://jite.eu/2023/12/7/percona-setup/#point-in-time "Permalink")
One thing that could be quite useful when working with backups for databases is point in time recovery.
Percona xtradb have this available in the backup section under the `pitr` section:
```
spec:
backup:
pitr:
storageName: 'local'
enabled: true
timeBetweenUploads: 60
```
It makes use of the same `storage` as defined in the `storages` section, and you can set the interval on PIT uploads.
#### Restoring a backup[Permalink](https://jite.eu/2023/12/7/percona-setup/#restoring-a-backup "Permalink")
Sometimes our databases fails very badly, or we get some bad data injected into it. In cases like those we need to restore an earlier backup of said database.
I wont cover this in this blogpost, as its too much to cover in a h4 in a tutorial like this, but Ill make sure to create a new post with disaster scenarios and how percona handles them.
If you really need to recover your data right now (before my next post) I would recommend that you either read the [Backup and restore](https://docs.percona.com/percona-operator-for-mysql/pxc/backups.html) and [“How to restore backup to a new kubernetes-based environment”](https://docs.percona.com/percona-operator-for-mysql/pxc/backups-restore-to-new-cluster.html) section in the documentation.
## The full chart[Permalink](https://jite.eu/2023/12/7/percona-setup/#the-full-chart "Permalink")
Now, when we have had a look at the different sections, we can set up our full chart:
```
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBCluster
metadata:
name: cluster2-test
namespace: private
spec:
upgradeOptions:
versionServiceEndpoint: ' https://check.percona.com'
apply: '8.0-latest'
schedule: '0 4 * * *'
pxc:
size: 3
nodeSelector:
kubernetes.io/arch: amd64
image: percona/percona-xtradb-cluster:8.0.32-24.2
autoRecovery: true
expose:
enabled: false
resources:
requests:
memory: 256M
cpu: 100m
limits:
memory: 512M
cpu: 200m
volumeSpec:
persistentVolumeClaim:
storageClassName: 'hcloud-volumes'
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
haproxy:
enabled: true
nodeSelector:
kubernetes.io/arch: amd64
size: 3
image: percona/percona-xtradb-cluster-operator:1.13.0-haproxy
resources:
requests:
memory: 256M
cpu: 100m
proxysql:
enabled: false
logcollector:
enabled: true
image: percona/percona-xtradb-cluster-operator:1.13.0-logcollector
resources:
requests:
memory: 64M
cpu: 50m
backup:
image: perconalab/percona-xtradb-cluster-operator:main-pxc8.0-backup
storages:
s3Storage:
type: 's3'
nodeSelector:
kubernetes.io/arch: amd64
s3:
bucket: 'my-bucket'
credentialsSecret: 'my-credentials-secret'
endpointUrl: 'the-s3-service-i-like-to-use.com'
region: 'eu-east-1'
local:
type: 'filesystem'
nodeSelector:
kubernetes.io/arch: amd64
volume:
persistentVolumeClaim:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10G
schedule:
- name: 'daily'
schedule: '0 0 * * *'
keep: 3
storageName: s3Storage
- name: 'hourly'
schedule: '0 * * * *'
keep: 2
storageName: 'local'
pitr:
storageName: 'local'
enabled: true
timeBetweenUploads: 60
```
Now, to get the cluster running, just invoke kubectl and its done!
```
kubectl apply -f my-awesome-cluster.yml
```
It takes a while for the databases to start up (there are a lot of components to start up!) so you might have to wait a few minutes before you can start play around with the database.
Check the status of the resources with the `get` kubectl command:
```
kubectl get all -n private
NAME READY STATUS RESTARTS AGE
pod/cluster1-test-pxc-0 3/3 Running 0 79m
pod/cluster1-test-haproxy-0 2/2 Running 0 79m
pod/cluster1-test-haproxy-1 2/2 Running 0 78m
pod/cluster1-test-haproxy-2 2/2 Running 0 77m
pod/cluster1-test-pxc-1 3/3 Running 0 78m
pod/cluster1-test-pxc-2 3/3 Running 0 76m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/cluster1-test-pxc ClusterIP None <none> 3306/TCP,33062/TCP,33060/TCP 79m
service/cluster1-test-pxc-unready ClusterIP None <none> 3306/TCP,33062/TCP,33060/TCP 79m
service/cluster1-test-haproxy ClusterIP 10.43.45.157 <none> 3306/TCP,3309/TCP,33062/TCP,33060/TCP 79m
service/cluster1-test-haproxy-replicas ClusterIP 10.43.54.62 <none> 3306/TCP 79m
NAME READY AGE
statefulset.apps/cluster1-test-haproxy 3/3 79m
statefulset.apps/cluster1-test-pxc 3/3 79m
```
When all StatefulSets are ready, you are ready to go!
## Accessing the database[Permalink](https://jite.eu/2023/12/7/percona-setup/#accessing-the-database "Permalink")
When a configuration as the one above is applied, a few services will be created.
The service you most likely want to interact with is called `<your-cluster-name>-haproxy` (or `-proxysql` depending on proxy) which will proxy your commands to the different backend mysql servers.
From within the cluster its quite easy, just accessing the service, while outside will require a loadbalancer service (which can be defined in the manifest) alternatively a ingress which can expose the service to the outer net.
If you wish to test your database from within the cluster, you can run the following command:
```
kubectl run -i --rm --tty percona-client --namespace private --image=percona:8.0 --restart=Never -- bash -il
percona-client:/$ mysql -h cluster1-haproxy -uroot -proot_password
```
The root password can be found in the `<your-cluster-name>-secrets` secret under the `root` key.
## Final words[Permalink](https://jite.eu/2023/12/7/percona-setup/#final-words "Permalink")
I really enjoy using percona xtradb, it allows for really fast setup of mysql clusters with backups enabled and everything one might need.
But, Im quite new to the tool, and might have missed something vital or important!
So please, let me know in the comments if something really important is missing or wrong.
@@ -0,0 +1,81 @@
---
page-title: "Running Percona XtraDB Cluster in a Docker Container - Percona XtraDB Cluster"
url: https://docs.percona.com/percona-xtradb-cluster/8.0/docker.html
date: "2024-11-26 11:15:40"
---
> :8.0
---
[](https://github.com/percona/pxc-docs/edit/8.0/docs/docker.md "Edit this page")[](https://github.com/percona/pxc-docs/raw/8.0/docs/docker.md "View source of this page")
Docker images of Percona XtraDB Cluster are hosted publicly on Docker Hub at [https://hub.docker.com/r/percona/percona-xtradb-cluster/](https://hub.docker.com/r/percona/percona-xtradb-cluster/).
For more information about using Docker, see the [Docker Docs](https://docs.docker.com/). Make sure that you are using the latest version of Docker. The ones provided via `apt` and `yum` may be outdated and cause errors.
We gather [Telemetry data](https://docs.percona.com/percona-xtradb-cluster/8.0/telemetry.html) in the Percona packages and Docker images.
Note
By default, Docker pulls the image from Docker Hub if the image is not available locally.
The image contains only the most essential binaries for Percona XtraDB Cluster to run. Some utilities included in a Percona Server for MySQL or MySQL installation might be missing from the Percona XtraDB Cluster Docker image.
The following procedure describes how to set up a simple 3-node cluster for evaluation and testing purposes. Do not use these instructions in a production environment because the MySQL certificates generated in this procedure are self-signed. For a production environment, you should generate and store the certificates to be used by Docker.
In this procedure, all of the nodes run Percona XtraDB Cluster 8.0 in separate containers on one host:
1. Create a ~/pxc-docker-test/config directory.
2. Create a custom.cnf file with the following contents, and place the file in the new directory:
`[mysqld] ssl-ca = /cert/ca.pem ssl-cert = /cert/server-cert.pem ssl-key = /cert/server-key.pem [client] ssl-ca = /cert/ca.pem ssl-cert = /cert/client-cert.pem ssl-key = /cert/client-key.pem [sst] encrypt = 4 ssl-ca = /cert/ca.pem ssl-cert = /cert/server-cert.pem ssl-key = /cert/server-key.pem`
3. Create a cert directory and generate self-signed SSL certificates on the host node:
`$ mkdir -m 777 -p ~/pxc-docker-test/cert docker run --name pxc-cert --rm -v ~/pxc-docker-test/cert:/cert percona/percona-xtradb-cluster:8.0 mysql_ssl_rsa_setup -d /cert`
4. Create a Docker network:
`$ docker network create pxc-network`
5. Bootstrap the cluster (create the first node):
`$ docker run -d \ -e MYSQL_ROOT_PASSWORD=test1234# \ -e CLUSTER_NAME=pxc-cluster1 \ --name=pxc-node1 \ --net=pxc-network \ -v ~/pxc-docker-test/cert:/cert \ -v ~/pxc-docker-test/config:/etc/percona-xtradb-cluster.conf.d \ percona/percona-xtradb-cluster:8.0`
6. Join the second node:
`$ docker run -d \ -e MYSQL_ROOT_PASSWORD=test1234# \ -e CLUSTER_NAME=pxc-cluster1 \ -e CLUSTER_JOIN=pxc-node1 \ --name=pxc-node2 \ --net=pxc-network \ -v ~/pxc-docker-test/cert:/cert \ -v ~/pxc-docker-test/config:/etc/percona-xtradb-cluster.conf.d \ percona/percona-xtradb-cluster:8.0`
7. Join the third node:
`$ docker run -d \ -e MYSQL_ROOT_PASSWORD=test1234# \ -e CLUSTER_NAME=pxc-cluster1 \ -e CLUSTER_JOIN=pxc-node1 \ --name=pxc-node3 \ --net=pxc-network \ -v ~/pxc-docker-test/cert:/cert \ -v ~/pxc-docker-test/config:/etc/percona-xtradb-cluster.conf.d \ percona/percona-xtradb-cluster:8.0`
To verify the cluster is available, do the following:
1. Access the MySQL client. For example, on the first node:
`$ sudo docker exec -it pxc-node1 /usr/bin/mysql -uroot -ptest1234#`
Expected output
`mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 ... You are enforcing ssl connection via unix socket. Please consider switching ssl off as it does not make connection via unix socket any more secure mysql>`
2. View the wsrep status variables:
`mysql> show status like 'wsrep%';`
Expected output
`+------------------------------+-------------------------------------------------+ | Variable_name | Value | +------------------------------+-------------------------------------------------+ | wsrep_local_state_uuid | 625318e2-9e1c-11e7-9d07-aee70d98d8ac | ... | wsrep_local_state_comment | Synced | ... | wsrep_incoming_addresses | 172.18.0.2:3306,172.18.0.3:3306,172.18.0.4:3306 | ... | wsrep_cluster_conf_id | 3 | | wsrep_cluster_size | 3 | | wsrep_cluster_state_uuid | 625318e2-9e1c-11e7-9d07-aee70d98d8ac | | wsrep_cluster_status | Primary | | wsrep_connected | ON | ... | wsrep_ready | ON | +------------------------------+-------------------------------------------------+ 59 rows in set (0.02 sec)`
## Get expert help[¶](https://docs.percona.com/percona-xtradb-cluster/8.0/docker.html#get-expert-help "Permanent link")
If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services.
---
Last update: 2024-03-14