程序启动管理,用户权限,多实例,systemd

  • 程序,配置,service,用户,这四个是必须的。此外有程序的数据,程序的日志,程序需要的动态库或者插件
  • 程序启动的用户 
  • 程序systemd service文件
  • 主目录
  • 主目录/二进制
  • 主目录/配置
  • 主目录/数据
  • 主目录/日志
  • 动态库或插件
  • 比如filebeat:
  • home

    Home of the Filebeat installation.

     

    path.home主目录

    bin

    The location for the binary files.

    {path.home}/bin二进制

     

    config

    The location for configuration files.

    {path.home}配置

    path.config

    data

    The location for persistent data files.

    {path.home}/data数据

    path.data

    logs

    The location for the logs created by Filebeat.

    {path.home}/logs日志

    path.logs

     
  • mysqld@.service (RPM platforms), mysql@.service (Debian platforms): Like mysqld.service or mysql.service, but used for managing multiple MySQL instances.

  • 用做多实例,并且可搭配%i  指示符,比如以下配置,多实例多用户:
  • [Unit]
    Description=BitTorrent Sync service
    After=network.target
    
    [Service]
    ExecStart=/usr/bin/btsync --nodaemon --config /home/%i/.sync/btsync.conf
    Restart=on-abort
    User=%i
    Group=users
    
    [Install]
    WantedBy=multi-user.target

指示符详解:https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers

二进制安装MySQL的命令序列:

$> groupadd mysql

$> useradd -r -g mysql -s /bin/false mysql

$> cd /usr/local

$> tar xvf /path/to/mysql-VERSION-OS.tar.xz

$> ln -s full-path-to-mysql-VERSION-OS mysql

$> cd mysql

$> mkdir mysql-files

$> chown mysql:mysql mysql-files

$> chmod 750 mysql-files

$> bin/mysqld --initialize --user=mysql

$> bin/mysql_ssl_rsa_setup

$> bin/mysqld_safe --user=mysql & # Next command is optional

$> cp support-files/mysql.server /etc/init.d/mysql.server

可以看到,以某个用户启动程序的本质是:

chown mysql:mysql mysql-files

$> chmod 750 mysql-files

$> bin/mysqld --initialize --user=mysql

$> bin/mysql_ssl_rsa_setup

$> bin/mysqld_safe --user=mysql & 

创建出一个用户,并使这个用户对程序有权限,然后以这个用户启动程序。(三种种方法,1,在systemd配置里指定。2,使用sudo -u  用户名。3,像MySQL一样给二进制mysqld传参 --user=mysql).相应的,如果是以某个用户登录,比如以bob这个用户登录,那么启动起来的程序就属于bob。

Linux下查看所有用户:

cat /etc/passwd

上面mysqld_safe 是一个shell脚本,源码在:https://www.cnblogs.com/mmgithub123/p/15711200.html ,而传参--user=mysql 也是给二进制mysqld传参,就是

bin/mysqld --verbose --help | grep user 的输出

-u, --user=name              Run mysqld daemon as user.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

以redis为例子,见 https://www.cnblogs.com/mmgithub123/p/15702165.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值