systemd最新的教程mariadb做为mysql的替代品 现在centos的新版本yum包已换成mariadbsystemctl控制启动关闭
安装一些库
yum install gcc gcc-c++ wget net-tools
1
yuminstallgccgcc-c++wgetnet-tools
查看SELinux状态:
/usr/sbin/sestatus -v
#如果SELinux status参数为enabled即为开启状态;
如果为关闭可以跳过
修改/etc/selinux/config文件
vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
重启机器
下载mariadb安装包到cd /usr/local/src/
cd /usr/local/src/
1
cd/usr/local/src/
wget http://mirrors.opencas.cn/mariadb/mariadb-10.0.21/bintar-linux-glibc_214-x86_64/mariadb-10.0.21-linux-glibc_214-x86_64.tar.gz
1
wgethttp://mirrors.opencas.cn/mariadb/mariadb-10.0.21/bintar-linux-glibc_214-x86_64/mariadb-10.0.21-linux-glibc_214-x86_64.tar.gz
下载地址分linux64位linux32位
linux64位下载地址
http://mirrors.opencas.cn/mariadb/mariadb-10.0.21/bintar-linux-glibc_214-x86_64/mariadb-10.0.21-linux-glibc_214-x86_64.tar.gz
linux32位下载地址
http://mirrors.opencas.cn/mariadb/mariadb-10.0.21/bintar-linux-glibc_214-x86/mariadb-10.0.21-linux-glibc_214-i686.tar.gz
将压缩包解压到/usr/local 目录下
tar zvxf mariadb-10.0.21-linux-glibc_214-x86_64.tar.gz -C /usr/local/
1
tarzvxfmariadb-10.0.21-linux-glibc_214-x86_64.tar.gz-C/usr/local/
创建mariadb 数据初始化目录/data/mysql这边把mysql放到云盘上data为新挂载盘
mkdir -p /data/mysql
1
mkdir-p/data/mysql
添加系统用户mysql,禁止登陆系统目录所属主和组都修改为mysql
useradd -r -s /sbin/nologin mysql ;chown -R mysql.mysql /data/mysql/
1
useradd-r-s/sbin/nologinmysql;chown-Rmysql.mysql/data/mysql/
做个mariadb 目录的连接
ln -s /usr/local/mariadb-10.0.21-linux-x86_64/ /usr/local/mysql
1
ln-s/usr/local/mariadb-10.0.21-linux-x86_64//usr/local/mysql
进入目录
cd /usr/local/mysql/
1
cd/usr/local/mysql/
开始安装
./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
1
./scripts/mysql_install_db--datadir=/data/mysql--user=mysql
如果没有报错就复制配置文件到etc目录下
cp support-files/my-large.cnf /etc/my.cnf
1
cpsupport-files/my-large.cnf/etc/my.cnf
是否覆盖 选 y
来启动下mysql
/usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql
1
/usr/local/mysql/bin/mysqld_safe--datadir=/data/mysql
ps aux|grep mysql
1
psaux|grepmysql
看出来–pid-file=V_centos.pid 把V_centos.pid 替换到mysql.service中
把mysql写入service中
vim /usr/lib/systemd/system/mysql.service
1
vim/usr/lib/systemd/system/mysql.service
.按i写入以下内容
[Unit]
Description=MySQL DBMS
[Service]
LimitNOFILE=10000
Type=simple
User=mysql
Group=mysql
PIDFile=/data/mysql/V_centos.pid
ExecStart=/usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql
ExecStop=/bin/kill -9 $MAINPID
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=MySQLDBMS
[Service]
LimitNOFILE=10000
Type=simple
User=mysql
Group=mysql
PIDFile=/data/mysql/V_centos.pid
ExecStart=/usr/local/mysql/bin/mysqld_safe--datadir=/data/mysql
ExecStop=/bin/kill-9$MAINPID
[Install]
WantedBy=multi-user.target
写好后保存
systemctl启动mariadb 启动mysql
systemctl start mysql.service
1
systemctlstartmysql.service
添加到开机启动
systemctl enable mysql.service
1
systemctlenablemysql.service
最后一步很重要哦 删除不用的用户新建用户
mysql_secure_installation
1
mysql_secure_installation
回车
y回车
输入root密码
再输入root密码
再回车
回车
回车 到出现
All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!