1、下载源代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Debian
sed -i "s|deb.debian.org|mirrors.aliyun.com|g" /etc/apt/sources.list && \
sed -i "s|security.debian.org|mirrors.aliyun.com|g" /etc/apt/sources.list && \
apt-get clean && \
apt-get update && \
apt-get install build-essential openssl libssl-dev curl vim ca-certificates git libpcap-dev libreadline-dev libsystemd-dev libz-dev -y
## Centos7
#curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && \
sed -i "s@#baseurl@baseurl@g" /etc/yum.repos.d/CentOS-Base.repo && \
sed -i "s@mirrorlist=http@#mirrorlist=http@g" /etc/yum.repos.d/CentOS-Base.repo && \
sed -i "s@baseurl=.*/centos@baseurl=https://mirrors.huaweicloud.com/centos@g" /etc/yum.repos.d/CentOS-Base.repo && \
yum clean all && \
yum makecache && \
yum update -y && \
yum install -y gcc gcc-c++ cmake make automake autoconf libtool readline-devel systemd-devel openssl-devel curl
###############################################################
curl -sSLk https://mirrors.ustc.edu.cn/postgresql/source/v11.6/postgresql-11.6.tar.gz | tar -xvz
cd postgresql-11.6
./configure --prefix=/data/postgresql --with-systemd --with-openssl
make && make install
## add user and group
groupadd postgres
useradd -g postgres postgres
mkdir -p /data/postgresql/data && chown postgres:postgres /data/postgresql/data

# 初始化数据库
su --login postgres --command "/data/postgresql/bin/initdb -D /data/postgresql/data"
# 启动数据库
su --login postgres --command "/data/postgresql/bin/pg_ctl -D /data/postgresql/data -l logfile start"
# 关闭数据库
su --login postgres --command "/data/postgresql/bin/pg_ctl stop -D /data/postgresql/data -m fast";

2、默认用户名密码

1
2
3
su --login postgres
vi ~/.bashrc
export PATH=$PATH:/data/postgresql/bin
1
2
psql postgres
\password postgres
1
2
3
4
## 
CREATE USER gitea WITH PASSWORD '123456ABCD$';
CREATE DATABASE gitea OWNER gitea;
GRANT ALL PRIVILEGES ON DATABASE gitea TO gitea;

3、systemd启动

1
2
3
vi /lib/systemd/system/postgresql.service
systemctl enable postgresql.service
systemctl start postgresql.service
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)

[Service]
Type=notify
User=postgres
#Group=postgres
ExecStart=/data/postgresql/bin/postgres -D /data/postgresql/data
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target

4、参考资料