一.思路:
1.修改服务文件相关变量;
2.测试服务式启动
3.加入自启动
二.开整:
1、查找自启动服务文件路径;
[root@localhost]# find / -name start-scripts
/opt/postgresql/postgresql-9.6.0/contrib/start-scripts
2、将linux文件拷贝到/etc/init.d/目录下,并命名为postgresql;(服务名为postgresql)
[root@localhost ]# cp
/opt/postgresql/postgresql-9.6.0/contrib/start-scripts/linux /etc/init.d/postgresql
3、修改服务文件 /etc/init.d/postgresql
# Installation prefix
#prefix=/usr/local/pgsql
#安装路径
prefix=/home/postgres
#echo “-----$prefix-----”
# Data directory
#PGDATA="/usr/local/pgsql/data"
#数据存放路径
PGDATA="/home/postgres/pgdata"
4、修改文件执行权限
[root@localhost ]#chmod a+x postgresql
[root@localhost]# ll /etc/init.d/
total 40
-rw-r–r--. 1 root root 18281 Aug 24 2018 functions
-rwxr-xr-x. 1 root root 3657 Aug 24 2018 postgresql
-rw-r–r--. 1 root root 1160 Oct 31 2018 README
5、启动服务
[root@localhost]# service postgresql restart
Restarting PostgreSQL: ok
[root@localhost]# service postgresql stop
Stopping PostgreSQL: ok
[root@localhost]# service postgresql start
Starting PostgreSQL: ok
6、设置开机自启动
[root@localhost]# chkconfig --add postgresql
[root@localhost]# chkconfig --list postgresql
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off