安装数据库Mariadb(脚本安装第4/11步)

        Mariadb数据库(MySQL)用来保存用户校园网唯一id和CARSI eptid的对应关系。eptid是目前CARSI唯一支持的用户id,所有CARSI SP可见(同一用户对同一SP,eptid值唯一)。确因管理需要,SP可通过它联系学校IdP管理员反查校园网id。

        注意:为了同时兼顾sp对用户唯一id的需求和保护用户个人隐私的需要,推荐学校对外公布eptid,而不是其他用户属性。

1.安装Mariadb

CentOS7系统进行以下操作

[root@www ~]# yum --enablerepo=centos-sclo-rh -y install rh-mariadb103-mariadb-server
[root@www ~]# scl enable rh-mariadb103 bash
[root@www ~]# vi /etc/profile.d/rh-mariadb103.sh
# create new
source /opt/rh/rh-mariadb103/enable
export X_SCLS="`scl enable rh-mariadb103 'echo $X_SCLS'`"

[root@www ~]# vi /etc/opt/rh/rh-mariadb103/my.cnf.d/mariadb-server.cnf
[mysqld]
character-set-server=utf8
log_bin = /var/lib/mysql/bin-log
log_bin_index = /var/lib/mysql/mysql-bin.index
expire_logs_days = 7

[root@www ~]# systemctl start rh-mariadb103-mariadb
[root@www ~]# systemctl enable rh-mariadb103-mariadb

CentOS8系统进行以下操作

[root@www ~]# dnf module -y install mariadb:10.3
[root@www ~]# vi /etc/my.cnf.d/charaset.cnf
#create new
[mysqld]
character-set-server = utf8mb4
log_bin = /var/lib/mysql/bin-log
log_bin_index = /var/lib/mysql/mysql-bin.index
expire_logs_days = 7

[client]
default-character-set = utf8mb4

[root@www ~]# systemctl restart mariadb
[root@www ~]# systemctl enable mariadb

2.初始化数据库

[root@www ~]#mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

# 回车
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

# 设置root密码
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

# 删除匿名账户
Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

# 禁止远程登陆
Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

# 删除test数据库
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

# 刷新权限
Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

3. 新建数据库表

[root@www ~]# mysql -u root -p
Enter password: #刚刚创建的root密码
MariaDB [(none)]> CREATE DATABASE idp_db CHARACTER SET utf8 COLLATE utf8_bin;
MariaDB [(none)]> use idp_db;
MariaDB [(none)]> CREATE TABLE shibpid (
    localEntity VARCHAR(255) NOT NULL,
    peerEntity VARCHAR(255) NOT NULL,
    persistentId VARCHAR(50) NOT NULL,
    principalName VARCHAR(50) NOT NULL,
    localId VARCHAR(50) NOT NULL,
    peerProvidedId VARCHAR(50) NULL,
    creationDate TIMESTAMP NOT NULL,
    deactivationDate TIMESTAMP NULL,
    PRIMARY KEY (localEntity, peerEntity, persistentId)
);

4.新建数据库用户

        为了加强安全防护,为IdP新建一个非root用户对接数据库,请勿直接复制下面语句,需要将username替换成新建的用户名,password替换成密码

MariaDB [(none)]> create user 'username'@'localhost' identified by 'password';
MariaDB [(none)]> grant all on idp_db.shibpid to 'username'@'localhost';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

5.修改IdP配置

[root@localhost ~]# vi /opt/shibboleth-idp/conf/global.xml
#将
p:username="xxxxxxx"
p:password="xxxxxxx"
#改成刚刚新建的用户名和密码



版权所有©北京大学计算中心