CentOS7 可以在SystemD管理服务Service方式实现服务的自启动 SystemD即为System Daemon,是linux下的一种init软件,开发目标是提供 更优秀的框架以表示系统服务间的依赖关系,并依此实现系统初始化时服务的并行启动, 同时达到降低Shell的系统开销的效果。 这里假设需要启动 # /usr/share/autostartup/foobar.sh STEP1.创建SystemD管理服务使用的.service文件 /usr/share/autostartup/foobar.service 以下是测试service文件,.service的具体编写,参考systemd相关文档 [Unit] Description=foobar Documentation=http://www.doc.com/doc.html After=network.target [Service] Type=simple WorkingDirectory=/home/foobar ExecStart=/usr/share/autostartup/foobar.sh ExecStop=/bin/kill -s QUIT $MAINPID Restart=always StandardOutput=syslog StandardError=syslog SyslogIdentifier=foobar User=foobar Group=foobar Environment= [Install] WantedBy=multi-user.target
Tag Archives: CentOS
CentOS6 使用rc.local实现开机自启动
CentOS6 可以在rc.local中增加启动shell脚本实现开启自启动 这里假设需要启动 /usr/share/autostartup/demo-service.sh STEP1. 将需要开启启动的脚本设置为标记为可执行文件 chmod +x /usr/share/autostartup/demo-service.sh STEP2. 执行如下命令将/etc/rc.d/rc.local文件标记为可执行文件 chmod +x /etc/rc.d/rc.local 在CentOS7 中,/etc/rc.d/rc.local文件的权限被降低了,开机的时候执行在自己的脚本是不能起动一些服务的。 将需要执行的脚本写入到 /etc/rc.d/rc.local echo “/usr/share/autostartup/demo-service.sh” >> /etc/rc.d/rc.local
CentOS使用run-as-user.sh处理运行环境的用户不同问题
很多时候,部署运行环境的用户和实际运行的用户是不同的, 当因为环境限制,当时碰到以下场景的时候,就比较麻烦了,需要编写一个脚本来实现运行。 1.不能使用su和sudo时 2.用户没有shell不支持login时,比如nobody,服务用户 3.使用Docker等容器时 4.使用SSH远程执行命令,但是不能使用登陆用户 实现前提 1.需要运行用户的用户名和用户分组以及密码 2.需要运行用户的PUID和PGID 使用前请修改代码中实际运行的用户名,且用户存在 ./run-as-user.sh 命令 命令参数
CentOS一键编译安装 NodeJS脚本
如题 CentOS一键编译安装 NodeJS脚本,使用NodeJS源代码编译,适用于CentOS和Debian, 默认安装的Nodejs版本已经老掉牙了 脚本支持选择node的版本和prefix 两个编译变量 NODE_VERSION=v8.11.3 NODE_PREFIX=/usr/local 使用了系统vCPU数量来控制NPROC数量,支持各种虚拟机的情况 NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) 对于物理机编译安装,建议按实际CPU数量*单个CPU核心数量进行参数设置 另外使用国内的taobao作为NPM的第一来源镜像。 #!/bin/bash ############################################################################## # Build develop enviroment for running npm and nodejs # # version=”1.0.0″ # node=”v8″ # os=”CentOS v7.4″ # user=“dev” # description=”Node v8 compiled from source running on CentOS v7.4″ ############################################################################## ############################################################################## # If is root …
CentOS 图形界面和字符界面切换
使用Centos的版本安装进入系统后,默认是进入到命令行界面, 可以通过以下步骤配置CentOS图形界面。 STEP1. 安装桌面环境 # yum groupinstall “X Window System” “GNOME Desktop” “Graphical Administration Tools” STEP2. 根据需要转换为图形模式和文本模式 默认级别转换为3(文本模式): # ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target 默认级别转换为5(图形模式): # ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
[CentOS] 使用s3fs-fuse挂载S3Bucket到本地分区
准备工作 1.创建接入S3 Bucket的IAM用户 2.创建S3 Bucket,赋予IAM用户读写S3 Bucket的权限 测试环境 Amazon AMI Linux CentOS 7.5 s3fs s3fs allows Linux and macOS to mount an S3 bucket via FUSE. s3fs preserves the native object format for files, allowing use of other tools like s3cmd. STEP1. 安装s3fs-fuse相关依赖包 # install automake fuse fuse-devel gcc-c++ git \ libcurl-devel libxml2-devel make openssl-devel STEP2.下载s3fs-fuse,编译安装s3fs-fuse …
CentOS6.x/7.x配置Nginx系统服务
使用源代码编译方式安装Nginx的时候,肯定不如用用yum方式安装来得便捷,CentOS的系统服务需要自行配置。 自行配置Nginx为CentOS的系统服务时,出于进程管理考虑需要首先配置pid,出于安全考虑建议修改nginx的运行用户。 创建nginx.pid文件用于nginx主进程 touch /usr/local/nginx/logs/nginx.pid 修改conf/nginx.conf,设置pid和user user nobody; pid logs/nginx.pid; CentOS6.x配置nginx系统服务 创建一个/etc/init.d/nginx文件 touch /etc/init.d/nginx chmod 755 /etc/init.d/nginx /etc/init.d/nginx文件中写入以下内容, 源文件取自yum方式安装后的文件,不过需要自己修改一下nginx的指向位置 nginx=”/usr/local/nginx/sbin/nginx” NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”