vi 文本编辑 /etc/profile 配置全局变量文件
mysql的
export PATH=/usr/local/mysql/bin:$PATH
芒果DB的
export MONGODB_HOME=/usr/local/soft/mongodb
export PATH=$PATH:$MONGODB_HOME/bin
java jdk的
export JAVA_HOME=/usr/local/soft/jdk1.8.0_241
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
让环境变量生效:
[code]source /etc/profile
source /etc/profile或 . /etc/profile
检查是否配置成功
[code]java -version
mongodb 配置开机启动,如下 systemd的方式配置(systemd代替了init.d)
vi /usr/lib/systemd/system/mongodb.service
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
RuntimeDirectory=mongodb
PIDFile=/usr/local/soft/mongodb/data/db/mongod.lock
ExecStart=/usr/local/soft/mongodb/bin/mongod –config /usr/local/soft/mongodb/conf/mgdb.conf
ExecStop=/usr/local/soft/mongodb/bin/mongod –shutdown –config /usr/local/soft/mongodb/conf/mgdb.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
注意: /usr/local/soft/mongodb/ 改成自己的解压路径
systemctl daemon-reload
systemctl start mongodb
systemctl enable mongodb
启动 mongodb
service mongodb stop
service mongodb start
注:设置了 就可以到处用mongo启动了
3 设置zookeeper开机自启动
我们可以将zookeeper作为一个服务,设置其开机自启,这样每次我们打开虚拟机就可以开启zookeeper,彻底解放双手!设置zookeeper开机自启需要以下几个步骤:
- 1、进入
/etc/init.d
目录:
- 2、创建文件zookeeper,并添加脚本:
-
vi zookeeper
脚本内容为:
-
#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
ZK_PATH=/usr/local/soft/zookeeper-3.4.12
export JAVA_HOME=/usr/local/soft/jdk1.8.0_261
case $1 in
start) sh $ZK_PATH/bin/zkServer.sh start;;
stop) sh $ZK_PATH/bin/zkServer.sh stop;;
status) sh $ZK_PATH/bin/zkServer.sh status;;
restart) sh $ZK_PATH/bin/zkServer.sh restart;;
*) echo \”require start|stop|status|restart\” ;;
esac -
- 3、保存脚本之后,执行以下指令将其注册为服务:
chkconfig --add zookeeper
- 4、测试其是否生效,这里采用先停服务,再使用命令启动,注意需要修改创建的zookeeper服务权限: