Centos7安装pgsql

版权声明:仅供学习参考 转载请标明出处。 https://blog.csdn.net/xujiamin0022016/article/details/90293231
yum -y install expect
cd /tmp
wget https://get.enterprisedb.com/postgresql/postgresql-9.6.4-1-linux-x64-binaries.tar.gz
tar zxf postgresql-9.6.4-1-linux-x64-binaries.tar.gz -C  /usr/local


mkdir -p /usr/local/pgsql/data
mkdir -p /usr/local/pgsql/log



useradd  postgres


chown -R postgres.postgres /usr/local/pgsql

cd /usr/local/pgsql

su - postgres -c "/usr/local/pgsql/bin/initdb -E utf8 -D /usr/local/pgsql/data"


cat >>/usr/local/pgsql/data/pg_hba.conf<<EOF
host all all 0.0.0.0/0 md5
EOF


cat >>/usr/local/pgsql/data/postgresql.conf<<EOF
listen_addresses = '*'
EOF


su - postgres -c "/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data/ > /usr/local/pgsql/log/postgres.log &"

echo '/usr/bin/expect <<-EOF
set timeout 1
spawn /usr/local/pgsql/bin/psql

expect "*=#"
send "ALTER USER postgres PASSWORD '''\'hengtian@123''\'';\r"
expect "*-#"
send "\q\r"
interact
expect eof
EOF' >/tmp/pgsql.sh



chmod +x  /tmp/pgsql.sh
su - postgres -c "sh /tmp/pgsql.sh"
rm -rf /tmp/pgsql.sh

echo "安装完成  密码为hengtian@123"





猜你喜欢

转载自blog.csdn.net/xujiamin0022016/article/details/90293231
今日推荐