首页 > 系统相关 >Rocky9 编译安装 Nginx Mariadb Asp.net Core6 (实测 笔记)

Rocky9 编译安装 Nginx Mariadb Asp.net Core6 (实测 笔记)

时间:2022-12-11 19:37:43浏览次数:79  
标签:opt Asp -- root redis Nginx usr && Core6

一、查看硬件信息

查看物理cpu个数、核心数量、线程数
grep 'physical id' /proc/cpuinfo | sort -u | wc -l
grep 'core id' /proc/cpuinfo | sort -u | wc -l
grep 'processor' /proc/cpuinfo | sort -u | wc -l

查看cpu信息
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

查看内存和硬盘
free -h && df -h

查看IP地址
ip addr

查看dns配置文件
cat /etc/resolv.conf

用户和用户组 列表文件
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql

查看可以登录系统的用户
cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1

把 /usr/local/src 目录,转到 /data 下
mkdir -p /data
mv /usr/local/src /data
ln -s /data/src /usr/local/src

主机名设置、查看
hostnamectl --static set-hostname tRocky
hostname

=====================================================
bombardier、iftop
bombardier 安装及使用
ln -s /usr/local/src/bombardier /bin
bombardier -c 125 -n 10000 http://localhost:5000

iftop安装及使用
yum install epel-release
yum install iftop
=====================================================

二、基础设置

Rocky9 换源
cd /etc/yum.repos.d
mkdir backup
cp rocky* backup/
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
-i.bak \
/etc/yum.repos.d/rocky*.repo
dnf makecache

安装基本软件包
dnf install vim wget lsof gcc gcc-c++ tar bzip2 firewalld openssl-devel mlocate make -y

配置Vim显示格式
vim /etc/vimrc,打开文件在末尾添加以下内容
set nocompatible
set number
filetype on
set history=1000
set background=dark
syntax on
set autoindent
set smartindent
set tabstop=2
set shiftwidth=2
set showmatch
set guioptions-=T
set vb t_vb=
set ruler
set nohls
set incsearch
if has("vms")
set nobackup
else
set backup
endif

:wq 保存退出
VIM格式化使用方法(打开文件后,输入以下命令,第二个G是shift+g)
gg=G


三、chrony来实现时间同步(默认不再支持ntp软件包)

设置时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

加入开启启动
systemctl enable chronyd && systemctl start chronyd

设置NTP同步时间,设置时区
timedatectl set-ntp true
timedatectl set-timezone Asia/Shanghai

查看配置文件
cat /etc/chrony.conf

查看和更改系统的时间和日期
timedatectl

修改时间
date -s '2000-1

同步时间
systemctl restart chronyd && chronyc sources -v

设置定时任务,自动执行
mkdir -p /data/crond

添加以下内容 (每天 02:00同步一次,并且日志记录到 /data/crond/ntpdate.log)(或者crontab -e 打开后添加)
echo "00 02 * * * systemctl restart chronyd && chronyc sources -v 1>>/data/crond/ntpdate.log 2>&1" >> /var/spool/cron/root


四、设置网络(使用新的NetworkManager,弃用了原本的 network)

查看配置文件(不建议直接修改)
cat /etc/NetworkManager/system-connections/enp0s3.nmconnection

显示当前网络设置、当前网络连接
nmcli
nmcli d
nmcli c show

常用命令(enp0s3 为网络连接名称、c 为connection 简写 、m 为 modify 简写)

nmcli c m enp0s3 ipv4.address 192.168.0.10/24 # 修改 IP 地址和子网掩码
nmcli c m enp0s3 ipv4.gateway 192.168.0.1 # 修改默认网关
nmcli c m enp0s3 ipv4.method manual # 修改为静态配置,默认是 auto
nmcli c m enp0s3 ipv6.method disabled # 将 IPv6 禁用
nmcli c m enp0s3 connection.autoconnect yes # 开机启动
nmcli c m enp0s3 ipv4.dns 8.8.8.8 # 修改 DNS
nmcli c m enp0s3 +ipv4.dns 8.8.8.8 # (+号,表示添加DNS)
nmcli c m enp0s3 -ipv4.dns 8.8.8.8 # (-号,表示删除 DNS)

nmcli connection add type ethernet ifname enp0s3 # 新建网络连接
nmcli c delete enp0s3 # 删除网络连接
nmcli c reload # 重新载入一下配置文件
nmcli c down enp0s3 # 停止网络连接
nmcli c up enp0s3 # 启用网络连接

 

五、设置PUTTY远程登录时,不使用密码,使用密钥文件登录(如不需要,可忽略)

服务器上创建目录
mkdir -p /root/.ssh

在"客户机"生成对称密钥,把客户机上的公钥复制到服务器(公钥文件:id_rsa.pub)
[root@centos ~] ssh-keygen -m PEM -t rsa -b 4096
根据提示操作,生成公钥
上传到服务器指定目录(*** 或使用软件远程复制id_rsa.pub到服务器/root/.ssh中。)
scp id_rsa.pub [email protected]/root/.ssh

查看服务器上,公钥是否已经存在
cd /root/.ssh
ll
-rw-r--r-- 1 root root 394 12月 5 09:33 id_rsa.pub

导入密钥到authorized_keys
cat id_rsa.pub >> authorized_keys

ll /root/.ssh
-rw-r--r-- 1 root root 394 12月 5 09:37 authorized_keys
-rw-r--r-- 1 root root 394 12月 5 09:33 id_rsa.pub

导入后,删除公钥文件
rm id_rsa.pub

设置目录和文件读取权限
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys

设置sshd配置文件
vim /etc/ssh/sshd_config
找到GSSAPICleanupCredentials,并且修改为以下内容
GSSAPICleanupCredentials yes
:wq 保存退出

重启sshd服务,让其生效
systemctl restart sshd


客户端设置PUTTY,进行远程登录
打开软件 PuTTYgen
点击load 选择之前客户机生成私钥文件id_rsa, 点击save private key 生成 pKey.ppk文件
打开软件 PuTTY
点击Session,在HostName(or IP address)输入服务器地址
点击Connection下的DATA,在Auto-login username中输入登录账号(当前账号为root)
点击Connection下的SSH下的Auth,点击Browse 选择之前生成 pKeyppk文件
点击Session,在Saved Sessions中,输入需要保存的Session名称,点击保存

1.7.6 设置完成后,即可以远程连接到服务器
打开软件 PuTTY
点击Session,在"Default Settings"下,找到之前已经保存的Session,双击打开连接
如果显示 Authenticating with public key "xxxxx-xxxx"时,即表未成功

1.8 设置新用户,并且使用密码和证书双重认证远程登录。同时禁止root远程登录 (如不需要,可忽略)
1.8.1 root登录后,修改root密码 (安全建议:密码为15位,大小字母+数字+特殊字符)
passwd


1.8.2 添加新用户,并且设置密码
adduser vicowong
passwd vicowong

1.8.3 创建目录,复制密钥相关文件到用户目录,并且设置权限
mkdir /home/vicowong/.ssh -p
cp /root/.ssh/authorized_keys /home/vicowong/.ssh
chmod 700 /home/vicowong/.ssh
chmod 600 /home/vicowong/.ssh/authorized_keys
chown vicowong:vicowong /home/vicowong/.ssh -R

设置防火墙,设置远程连接端口(这里是26322)
systemctl enable firewalld && systemctl start firewalld
firewall-cmd --zone=public --add-port=26322/tcp --permanent
firewall-cmd --reload && iptables -L --line-numbers|grep ACCEPT

安装semanage(用于设置selinux策略)
yum install -y policycoreutils-python selinux-policy selinux-policy-targeted

查看当前 selinux 是否启用 即 Enforcing 状态 (否则有可能设置 selinux 策略不成功)
getenforce

查看当前 selinux 关于远程ssh连接端口的设置
semanage port -l | grep ssh
ssh_port_t tcp 22
添加新端口
semanage port -a -t ssh_port_t -p tcp 26322

--------------------------------------------------------------------------------------------
移除端口
semanage port -d -t ssh_port_t -p tcp 26322
-------------------------------------------------------------------------------------------
1.8.6 设置sshd配置文件
vim /etc/ssh/sshd_config
找到以下内容,并且进行修改
Port 26322
Protocol 2
ServerKeyBits 1024
PermitRootLogin no
AllowUsers vicowong
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PermitEmptyPasswords no
PasswordAuthentication yes
AuthenticationMethods publickey,password
X11Forwarding no
MaxStartups 10:30:60
:wq 保存退出

# AuthorizedKeysFile
# PasswordAuthentication
# X11Forwarding

以上三个搜索,查看是否有重复设置


重启sshd服务,让其生效
systemctl restart sshd


使用新用户登录(重新打开一个新终端,原来的终端先不关,避免因设置不当导致没法连接远程)
打开软件 PuTTY,点击之前保存的Sessions,点击Load读取之前的配置
在Port框输入端口(当前账号为26322)
点击Connection下的DATA,在Auto-login username中输入登录账号(当前账号为vicowong)
点击Session 点击Save。保存当前修改。
点击Open,打开终端。

设置后,必须远程将进行密码和证书双重认证。
远程登录会以vicowong这个账号进行登录。安装维护需要root权限时,可以使用su实现
su root


=================================================================================

一、编译 升级 gcc
cd /usr/local/src/
wget http://mirrors.concertpass.com/gcc/releases/gcc-12.2.0/gcc-12.2.0.tar.gz
tar zvxf gcc-12.2.0.tar.gz && cd gcc-12.2.0/
./contrib/download_prerequisites && ldconfig
mkdir gcc-build && cd gcc-build
../configure --enable-languages=c,c++ --disable-multilib --enable-checking=release --prefix=/opt/gcc
make -j8
make install
echo '/opt/gcc/lib64' > /etc/ld.so.conf.d/local-lib64.conf
ldconfig -v
mv /usr/bin/gcc /usr/bin/gcc.bak
mv /usr/bin/g++ /usr/bin/g++.bak
ln -s /opt/gcc/bin/gcc /usr/bin/gcc
ln -s /opt/gcc/bin/g++ /usr/bin/g++
update-alternatives --install /usr/bin/gcc gcc /opt/gcc/bin/gcc 999
gcc --version
shutdown -r now

二、编译 升级 内核
yum -y install gcc gcc-c++ make autoconf automake libtool ncurses-devel flex bison openssl openssl-devel bc elfutils-libelf-devel zlib zlib-devel pcre pcre-devel
cd /usr/local/src/
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.82.tar.xz
tar vxf linux-5.15.82.tar.xz && cd linux-5.15.82/
cp /boot/config-5.14.0-162.6.1.el9_1.x86_64 .config
=======================================================================
vim .config
在.config文件中找到CONFIG_SYSTEM_TRUSTED_KEYS,CONFIG_DEBUG_INFO_BTF这两行,并将这两行注释。
=======================================================================
make menuconfig
make -j8
make modules
make modules_install
make install

grubby --info=ALL | grep ^kernel
grubby --default-kernel
grubby --set-default=/boot/vmlinuz-5.16.2
grubby --remove-kernel /boot/vmlinuz-4.18.0-348.el8.0.2.x86_64

rpm -qa | grep kernel
yum remove kernel-core-4.18.0 kernel-devel-4.18.0 kernel-tools-libs-4.18.0 kernel-headers-4.18.0

删除内核,会删除gcc环境,重新安装GCC
yum installgcc gcc-c++ -y


三、安装jemalloc(需要 bzip2 库解压)
cd /usr/local/src/
wget https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2
tar xjf jemalloc-5.3.0.tar.bz2 && cd jemalloc-5.3.0
./configure && make && make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig -v
find / -name jemalloc


四、编译 升级 zlib
cd /usr/local/src/
wget http://zlib.net/zlib-1.2.13.tar.gz
tar zvxf zlib-1.2.13.tar.gz && cd zlib-1.2.13
./configure && make && make install
ldconfig -v
find / -name libz.so.1.2.13
ll /usr/local/lib

四、编译 openssl3
find / -name openssl

编译时需要用到 Perl 的 Text::Template 模块和IPC::Cmd 模块
yum -y install perl-CPAN
cpan -i Text::Template
cpan -i IPC::Cmd

cd /usr/local/src
wget https://www.openssl.org/source/openssl-3.0.7.tar.gz
tar zvxf openssl-3.0.7.tar.gz && cd openssl-3.0.7
"--prefix=/usr"头文件和库文件路径,"--openssldir=/usr"证书等文件路径:
./config shared zlib --prefix=/opt/openssl3 --openssldir=/opt/openssl3
make update && make && make install

rm -rf /usr/bin/openssl
rm -rf /usr/include/openssl
ln -s /opt/openssl3/bin/openssl /usr/bin/openssl
ln -s /opt/openssl3/include/openssl /usr/include/openssl


rm -rf /usr/lib64/libssl.so
rm -rf /usr/lib/libssl.so
ln -s /opt/openssl3/lib64/libssl.so /usr/lib64/libssl.so
ln -s /opt/openssl3/lib64/libssl.so /usr/lib/libssl.so

rm -rf /usr/lib64/libssl.so.3
rm -rf /usr/lib/libssl.so.3
ln -s /opt/openssl3/lib64/libssl.so.3 /usr/lib64/libssl.so.3
ln -s /opt/openssl3/lib64/libssl.so.3 /usr/lib/libssl.so.3

rm -rf /usr/lib64/libcrypto.so
rm -rf /usr/lib/libcrypto.so
ln -s /opt/openssl3/lib64/libcrypto.so /usr/lib64/libcrypto.so
ln -s /opt/openssl3/lib64/libcrypto.so /usr/lib/libcrypto.so

ln -s /opt/openssl3/lib64/libcrypto.so.3 /usr/lib64/libcrypto.so.3


# 根据需要引入库
export LD_LIBRARY_PATH=/opt/openssl3/lib64:$LD_LIBRARY_PATH

ldconfig -v | grep ssl
openssl version -a
openssl ciphers -v


四、编译 openssh
yum install zlib* pam*
cd /usr/local/src/
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.1p1.tar.gz
tar zvxf openssh-8.8p1.tar.gz && cd openssh-8.8p1/
./configure --with-zlib --with-md5-passwords --with-pam --without-openssl-header-check
make && make install
ssh -V
OpenSSH_9.1p1, OpenSSL 3.0.1 14 Dec 2021


五、安装nginx
cd /usr/local/src
wget https://github.com/PhilipHazel/pcre2/releases/download/pcre2-10.41/pcre2-10.41.tar.gz
tar zvxf pcre2-10.41.tar.gz && cd pcre2-10.41
./configure && make && make install
pcre2-config --version

groupadd www
useradd -g www www -s /sbin/nologin -M
mkdir -p /data/www/web
chmod +w /data/www/web
chown -R www:www /data/www/web

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.22.1.tar.gz
tar zvxf nginx-1.22.1.tar.gz && cd nginx-1.22.1

vim src/core/nginx.h
#define nginx_version 1000000
#define NGINX_VERSION "1.0.0"
#define NGINX_VER   "IIS"

./configure --prefix=/opt/nginx \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-ld-opt="-ljemalloc" \
--with-http_v2_module \
--with-pcre \
--with-zlib=/usr/local/src/zlib-1.2.13 \
--with-openssl

make && make install

vim /opt/nginx/conf/nginx.conf
user www www;
worker_processes auto;
error_log logs/error.log crit;
pid logs/nginx.pid;

events {
use epoll;
worker_connections 1024;
}

http {
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

include mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

include /opt/nginx/conf/vhosts/*.conf;
}


mkdir -p /opt/nginx/conf/vhosts
vim /opt/nginx/conf/vhosts/web.conf

server {
listen 80;
server_name localhost;
set $root /data/www/web;
root $root;

location / {
index index.html index.htm;
}
}

vim /data/www/web/index.html
<html>
<head><title>nginx index.html</title></head>
<body>
<h1>index.html</h1>
</body>
</html>

vim /etc/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf -t
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl enable nginx.service
systemctl list-unit-files|grep enabled|grep nginx
systemctl start nginx.service

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload && iptables -L --line-numbers|grep ACCEPT

查看nginx版本
/opt/nginx/sbin/nginx -V
ps -ef|grep nginx
lsof -n | grep jemalloc


六、安装 dotnet core6
-------------------------------------------------
删除 dotnet-sdk-6.0
dnf remove dotnet-sdk-6.0
rm -rf /usr/share/dotnet
rm -rf /usr/bin/dotnet
rm -rf /etc/yum.repos.d/microsoft-prod.repo
dnf clean all
dnf upgrade
shutdown -r now
dnf install dotnet-sdk-6.0
-------------------------------------------------


dnf install dotnet-sdk-6.0
dotnet --info

mkdir -p /data/www/netcore6
复制编译好的代码到 /data/www/netcore6

vim /opt/nginx/conf/vhosts/web.conf

server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}
}

systemctl restart nginx
systemctl status nginx


安装 python3-setuptools
yum install python-setuptools unzip -y

安装 Supervisor (低于 3.3.3 会有安全漏洞)
cd /usr/local/src
wget https://files.pythonhosted.org/packages/b3/41/2806c3c66b3e4a847843821bc0db447a58b7a9b0c39a49b354f287569130/supervisor-4.2.4.tar.gz
tar zvxf supervisor-4.2.0.tar.gz && cd supervisor-4.2.0
python setup.py install
find / -name supervisor

配置Supervisor
mkdir -p /etc/supervisor/conf.d
echo_supervisord_conf > /etc/supervisor/supervisord.conf

vim /etc/supervisor/supervisord.conf

查找
;[include]
;files = relative/directory/*.ini

修改为
[include]
files=conf.d/*.conf

查找 [unix_http_server] 下账号和密码设置,设置密码 (使用 supervisorctl 强制输入密码,增强安全性)
username=supervisor_user
password=supervisor_userpwd

:wq 保存退出


假设有一个 asp.net core mvc项目 netcore6
cd /data/www/netcore6
dotnet netcore6.dll

vim /etc/supervisor/conf.d/netcore6.conf
输入以下内容

[program:netcore6]
command=dotnet netcore6.dll --urls="http://[*]:5000"; 运行的命令
directory=/data/www/netcore6/ ; 命令执行目录
autorestart=true ; 自动重启
stderr_logfile=/var/log/netcore6.err.log ; 错误日志
stdout_logfile=/var/log/netcore6.out.log ; 输出日志
environment=ASPNETCORE_ENVIRONMENT=Production ; 环境变量
user=www ; 进程执行的用户身份
stopsignal=INT

:wq 保存退出


配置 Supervisor 开机启动
vim /etc/systemd/system/supervisord.service

[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=supervisord -c /etc/supervisor/supervisord.conf
ExecStop=supervisorctl shutdown
ExecReload=supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

:wq 保存退出

systemctl enable supervisord && systemctl restart supervisord && systemctl status supervisord

查看supervisor运行状态
supervisorctl status

安装libgdiplus组件,支持 core 图片生成
dnf install automake autoconf libtool glib2-devel cairo-devel libjpeg* libtiff*

cd /usr/local/src
wget https://github.com/mono/libgdiplus/archive/6.0.5.tar.gz
tar zvxf libgdiplus-6.0.5.tar.gz && cd libgdiplus-6.0.5
./autogen.sh && make && make install
ln -s /usr/local/lib/libgdiplus.so /usr/lib64/gdiplus.dll

安装字体
dnf install mkfontscale fontconfig -y

//假设把windows下font目录的相应字体上传到服务器 /usr/local/src/TrueType
mkdir -p /usr/share/fonts/chinese
cd /usr/share/fonts/chinese
cp /usr/local/src/TrueType/* ./
mkfontscale && mkfontdir && fc-cache -fv
fc-list | grep times.ttf
fc-list :lang=zh

shutdown -r now


七、安装redis

dnf install tcl -y

cd /usr/local/src
wget http://download.redis.io/releases/redis-stable.tar.gz
tar zvxf redis-stable.tar.gz && cd redis-stable/
make && make PREFIX=/opt/redis install

groupadd redis
useradd -g redis redis -s /sbin/nologin -M
mkdir -p /opt/redis/logs
cp redis.conf /opt/redis
ll /opt/redis
chown -R redis:redis /opt/redis

vim /opt/redis/redis.conf
找到相关的行,修改

#bind 127.0.0.1
protected-mode no
requirepass redispwd
daemonize no
supervised no
pidfile /opt/redis/redis_6379.pid
logfile /opt/redis/redis_6379.log
dir /opt/redis

vim /usr/lib/systemd/system/redis.service

[Unit]
Description=Redis Server
After=network.target

[Service]
Type=simple
PIDFile=/opt/redis/redis_6379.pid
ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=on-failure
User=redis

[Install]
WantedBy=multi-user.target


systemctl enable redis && systemctl daemon-reload && systemctl start redis
systemctl status firewalld

firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload && iptables -L --line-numbers|grep ACCEPT

**************************************************************************************************
指定IP可以访问
[root@centos ~]# firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.25" port protocol="tcp" port="6379" accept"

显示所有规则
[root@centos ~]# firewall-cmd --list-all

移除指定IP可以访问
[root@centos ~]# firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.25" port protocol="tcp" port="6379" accept"

**************************************************************************************************

查看当前版本
/opt/redis/bin/redis-server -v
/opt/redis/bin/redis-cli -v

安装完成后,打开客户端
[root@centos ~]# /opt/redis/bin/redis-cli -h 127.0.0.1 -p 6379

输入以下命令,测试写入及读取
127.0.0.1:6379 > auth redispwd
127.0.0.1:6379 > set name abc123
127.0.0.1:6379 > get name
退出
127.0.0.1:6379 >quit


八、安装 mariadb 数据库
dnf install mariadb-server
systemctl enable mariadb && systemctl restart mariadb && systemctl status mariadb
mysql_secure_installation

mkdir /data/mysql_data
chown -R mysql:mysql /data/mysql_data
cp -a /var/lib/mysql /data/mysql_data

vim /etc/my.cnf.d/mariadb-server.cnf

[mysqld]
datadir=/data/mysql_data/mysql
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
ssl
max_connections=1000

systemctl restart mariadb
mysql -u root -p

MariaDB [(none)]> status;
MariaDB [(none)]> show engines;
MariaDB [(none)]> SHOW VARIABLES LIKE '%have%ssl%';

增加远程访问用户,
root是用户名,%是主机名或IP地址,这里的%代表任意主机或IP地址,也可指定唯一的IP地址
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;

解决本地账号,没需密码就可以登录问题
仅保留mysql.user 表下的 mariadb.sys@localhost 和 root@% 这两个用户对应的记录,其它记录删除
MariaDB [(none)]> exit;

ps -ef|grep mysqld
lsof -n | grep jemalloc

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload && iptables -L --line-numbers|grep ACCEPT

======================================================================
配置MariaDB慢查询
touch /data/mysql_data/slow_query_log.log
chown mysql:mysql /data/mysql_data/slow_query_log.log

在[mysqld]标签下添加如下内容
slow_query_log=on
slow_query_log_file=/data/mysql_data/slow_query_log.log
long_query_time=2


数据备份与恢复
导出当前数据库的所有db,到一个文件中
mysqldump -u root -p --all-databases > /data/AllMysql.dump

导入数据
mysql -uroot -p < /data/AllMysql.dump
mysql -u root -p
> source /data/AllMysql.dump
======================================================================

标签:opt,Asp,--,root,redis,Nginx,usr,&&,Core6
From: https://www.cnblogs.com/vicowong/p/16974219.html

相关文章