1+x 复习(FTP,NFS,Samba,主从数据库)

该篇博客详细介绍了在Linux环境中如何关闭防火墙、配置yum源、搭建FTP服务器、设置NFS共享、实现Samba服务以及配置MariaDB主从数据库。涉及的命令包括systemctl、setenforce、vi编辑器、yum安装、vsftpd、nfs-utils、samba、mysql安装及权限配置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基础配置(防火墙和yum源)

[root@localhost yum.repos.d]# systemctl stop firewalld
[root@localhost yum.repos.d]# systemctl disable firewalld
[root@localhost yum.repos.d]# setenforce 0
[root@localhost yum.repos.d]# vi /etc/selinux/config
SELINUX=disabled (文件中修改enforcing为disabled)



[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@localhost yum.repos.d]# mkdir /repo
[root@localhost yum.repos.d]# mkdir /cdrom
[root@localhost yum.repos.d]# mv * /repo
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# vi local.repo
[c7]
baseurl=file:///cdrom
gpgcheck=0
enabled=1
[root@localhost yum.repos.d]# mount /dev/cdrom /cdrom
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost yum.repos.d]# yum repolist

一.使用ftp配置yum源

主机名servernode
IP 192.168.10.10192.168.10.100

 server主机的内容

[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# setenforce 0

[root@server ~]# yum install vsftpd -y
[root@server ~]# systemctl start vsftpd
[root@server ~]# mkdir /share
[root@server ~]# vi /etc/vsftpd/vsftpd.conf
anon_root=/share    (在文件内任意处加入这段内容)
[root@server ~]# systemctl restart vsftpd
[root@server ~]# mount /dev/cdrom /share
mount: /dev/sr0 写保护,将以只读方式挂载

node主机的内容

[root@node ~]# systemctl stop firewalld
[root@node ~]# systemctl disable firewalld
[root@node ~]# setenforce 0

[root@node ~]# cd /etc/yum.repos.d/
[root@node yum.repos.d]# mkdir /repo
[root@node yum.repos.d]# mv * /repo
[root@node yum.repos.d]# vi a.repo
[ftp]
baseurl=ftp://192.168.10.10
gpgcheck=0
enabled=1

[root@node ~]# yum repolist

二.NFS 

主机名servernode
IP 192.168.10.10192.168.10.100

 server主机内容

[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# setenforce 0

[root@server ~]# yum install nfs-utils rpcbind
[root@server ~]# mkdir /test
[root@server ~]# vi /etc/exports
/test *(rw)       (添加到文件中)
[root@server ~]# systemctl restart nfs rpcbind
[root@server ~]# showmount -e
Export list for server:
/test *

 node主机内容

[root@node ~]# systemctl stop firewalld
[root@node ~]# systemctl disable firewalld
[root@node ~]# setenforce 0

[root@node ~]# yum install nfs-utils rpcbind
[root@node ~]# systemctl restart rpcbind nfs
[root@node ~]# showmount -e 192.168.10.10
Export list for 192.168.10.10:
/test *
[root@node ~]# mount -t nfs 192.168.10.10:/test /mnt
[root@node ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 475M     0  475M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  7.8M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  1.3G   16G    8% /
/dev/sda1               1014M  136M  879M   14% /boot
tmpfs                     98M     0   98M    0% /run/user/0
192.168.10.10:/test       17G  1.3G   16G    8% /mnt

三.Samba

主机名servernode
IP 192.168.10.10192.168.10.100

server主机内容

[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# setenforce 0

[root@server ~]# useradd user
[root@server ~]# smbpasswd -a user
New SMB password:(输入密码)
Retype new SMB password:(重复密码)
Added user user.
#此处为user用户的网络凭据密码
[root@server ~]# yum install samba -y
[root@server ~]# vi /etc/samba/smb.conf
[samba]
        path = /samba
        public = yes
        admin users = user
        writeable = yes
        browseable = yes
(在最后加入)
[root@server ~]# mkdir /samba
[root@server ~]# systemctl restart smb

使用Windows系统主机验证

使用user用户的网络凭据

 

 使用node主机验证(使用user用户的网络凭据,我设置的密码为123)

[root@node ~]# systemctl stop firewalld
[root@node ~]# systemctl disable firewalld
[root@node ~]# setenforce 0

[root@node ~]# mount -t cifs -o username=user,password=123 //192.168.10.10/samba /opt
[root@node ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 475M     0  475M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  7.8M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  1.3G   16G    8% /
/dev/sda1               1014M  136M  879M   14% /boot
tmpfs                     98M     0   98M    0% /run/user/0
192.168.10.10:/test       17G  1.3G   16G    8% /mnt
//192.168.10.10/samba     17G  1.3G   16G    8% /opt

四.主从数据库

主机名servernode
IP 192.168.10.10192.168.10.100

server主机内容

[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# setenforce 0

[root@server ~]# yum install mariadb mariadb-server -y
[root@server ~]# systemctl restart mariadb
[root@server ~]# systemctl enable mariadb
[root@server ~]# 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.

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.

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!

[root@server ~]# vi /etc/my.cnf
binlog_ignore_db=mysql
log_bin=mysql-bin
server-id=10
(在[mysqld]下添加这三段,server-id一般为ip的尾段,比如ip为192.168.10.10,就写server-id=10)

[root@server ~]# systemctl restart mariadb
[root@server ~]# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

node主机内容

[root@node ~]# systemctl stop firewalld
[root@node ~]# systemctl disable firewalld
[root@node ~]# setenforce 0

[root@node opt]# yum install -y mariadb mariadb-server
[root@node ~]# systemctl start mariadb
[root@node ~]# systemctl enable mariadb
[root@node ~]# 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.

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.

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!
[root@node ~]# vi /etc/my.cnf
binlog_ignore_db=mysql
log_bin=mysql-bin
server-id=100
(在[mysqld]下添加这三段,server-id一般为ip的尾段,比如ip为192.168.10.100,就写server-id=100)

[root@node ~]# systemctl restart mariadb
[root@node ~]# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> change master to master_host='192.168.10.10',master_user='root',master_password='123';
Query OK, 0 rows affected (0.00 sec)
    
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.10.10
                  Master_User: root
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 379
               Relay_Log_File: mariadb-relay-bin.000004
                Relay_Log_Pos: 663
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 379
              Relay_Log_Space: 1243
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 10
1 row in set (0.00 sec)

MariaDB [(none)]>




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值