美文网首页
deepin 环境变量和启动项设置

deepin 环境变量和启动项设置

作者: 阿杰_96c5 | 来源:发表于2020-01-30 18:07 被阅读0次

环境变量

etc/profile文件中修改环境变量,在这里修改的内容是对所有用户起作用的

sudo dedit /etc/profile  

事例模板

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin:/usr/sbin"
fi
export PATH

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
tty | egrep -q tty[1-6] && export LC_ALL=C

# java 环境变量
export JAVA_HOME=/usr/local/jdk1.8.0_11  
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

# nginx 环境变量
export PATH="$PATH:/usr/local/nginx/sbin"

# mongodb 环境变量
export PATH=$PATH:/usr/local/mongodb/bin

**让环境变量立即生效

# 重新加载配置文件
source /etc/profile


启动项

新建 /etc/rc.local 文件

dedit /etc/rc.local 

事例模板

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# 开机启动 mongod
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf 


exit 0

在 exit 0 上方插入你需要自启的命令(一行一个)后保存文件

给脚本加上 755 权限

sudo chmod +755 /etc/rc.local

调试脚本

sudo /etc/rc.local # 使用 sudo 模拟 root 用户开机自启 /etc/rc.local 文件

rc.local 开机时是以 root 用户启动的,所以写在 rc.local 文件中命令不需要带有 sudo 前缀
个人建议每当往 rc.local 文件中添加了一个需要自启的命令时,可以先用 sudo /etc/rc.local 命令模拟一下看看是否能够执行成功(如果执行失败也能够直观地看到出错的原因),这样能够有效减少你重启电脑来调试的次数。

使用systemctl管理服务

1.开启 mysql 服务
sudo systemctl start mysql

2.停止 mysql 服务
sudo systemctl stop mysql

3.重启 mysql 服务
sudo systemctl restart mysql

4.设置开机启动或禁用 mysql服务
设置开机启动:
sudo systemctl enable mariadb.service
如果你不想开机启动,也可以禁用开机启动
sudo systemctl disable mariadb.service

相关文章

网友评论

      本文标题:deepin 环境变量和启动项设置

      本文链接:https://www.haomeiwen.com/subject/hkzithtx.html