CentOS下安装数据库

CentOS下安装数据库

在CentOS下安装MySQL与MongoDB


安装MySQL

CentOS下有更好的MariaDB(MySQL的子项目)代替MySQL,因此我们安装通过yum安装MariaDB

# yum install mariadb-server
# mysql_secure_installation  # 设置MySQL默认用户密码
# systemctl start mariadb.service # 启动mariadb服务
# mysql -uroot -proot # 登录MySQL

开启MySQL远程连接:

# mysql -uroot -proot
# grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; # root是用户名,%代表任意主机,'123456'指定的登录密码(这个和本地的root密码可以设置不同的,互不影响)
# flush privileges; # 重载系统权限
# 允许3306端口
# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
# iptables -L -n
# iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT # # 此时生产环境是不安全的,远程管理之后应该关闭端口,删除之前添加的规则

安装MongoDB

1.添加MongoDB到yum repo

# vim /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB repo
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

2.安装MongoDB

# yum install mongodb-org

3.检查并启动MongoDB

# chkconfig  mongod  on
# service mongod start 
# 或者
# systemctl restart  mongo.service

4.检查是否启动

# ps -ef | grep mongo
mongod    2587     1  1 05:24 ?        00:00:08 /usr/bin/mongod -f /etc/mongod.conf
root      2984  2270  0 05:34 pts/1    00:00:00 grep --color=auto mongo
# netstat -an | grep 27017
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN
unix  2      [ ACC ]     STREAM     LISTENING     20600    /tmp/mongodb-27017.sock

5.开启防火墙远程访问端口

# firewall-cmd --zone=public --add-port=27017/tcp --permanent
success
# firewall-cmd --reload
success

如果关闭了firewall,则在iptables开放远端访问端口:

# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT

修改MongoDB配置

# vi /etc/mongod.conf
# 添加或修改如下配置
bind_ip = 0.0.0.0
port = 27017

6.iptables和firewalld

# yum install iptables-services
# systemctl mask firewalld.service
# systemctl enable iptables.service
# systemctl enable ip6tables.service
# systemctl stop firewalld.service
# systemctl start iptables.service
# systemctl start ip6tables.service
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值