安装python依赖
cd /etc/yum.repos.d/
mkdir bak
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install zlib-devel bzip2-devel openssl-devel openssl-static ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel lzma gcc
下载python3.7.5
cd /usr/local/src/
下载
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tar.xz
解压移动
tar xvf Python-3.7.5.tar.xz
mv Python-3.7.5 /usr/local/python-3.7
cd /usr/local/python-3.7/
安装编译
./configure --prefix=/usr/local/sbin/python-3.7
make && make install
创建软连接,可以删了之前的python2软连接,也可以新建个python3。
rm -rf /usr/bin/python
ln -sv /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python
这种方法修改完python默认版本之后,会不能执行yum命令
用vim修改/usr/bin/yum文件内容: ① 将/usr/bin/yum的顶部的: !/usr/bin/python 改成 !/usr/bin/python2.7 ② 将/usr/libexec/urlgrabber-ext-down的顶部的: /usr/bin/python 改为 /usr/bin/python2.7 ③ 将/usr/bin/yum-config-manager的顶部的 #!/usr/bin/python 改为 #!/usr/bin/python2.7
最后将pip指向到python3.7
ln -s /usr/local/sbin/python-3.7/bin/pip3 /usr/bin/pip
ln -sv /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python3
ln -s /usr/local/sbin/python-3.7/bin/pip3 /usr/bin/pip3
vim /etc/yum.repos.d/mongodb-org-4.0.repo
写入内容 [mngodb-org] name=MongoDB Repository baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/ gpgcheck=0 enabled=1
yum install -y vim mongodb-org
开机自启
systemctl enable mongod.service
修改配置
vim /etc/mongod.conf
添加用户权限后需要修改配置开启认证,
修改security,注意缩进和空格。
然后给mongod授权
chown -R mongod:mongod /var/lib/mongo
chown -R mongod:mongod /var/log/mongodb
chown mongod:mongod /tmp/*.sock
然后重启
systemctl restart mongod.service