node.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/sh
  2. #move to script directory so all relative paths work
  3. cd "$(dirname "$0")"
  4. #includes
  5. . ../config.sh
  6. #set the date
  7. now=$(date +%Y-%m-%d)
  8. #show this server's addresses
  9. server_address=$(hostname -I);
  10. echo "This Server Address: $server_address"
  11. #nodes addresses
  12. read -p "Enter all Node IP Addresses: " nodes
  13. #determine whether to add iptable rules
  14. read -p 'Add iptable rules (y,n): ' iptables_add
  15. #settings summary
  16. echo "-----------------------------";
  17. echo " Summary";
  18. echo "-----------------------------";
  19. echo "All Node IP Addresses: $nodes";
  20. echo "Add iptable rules: $iptables_add";
  21. echo "";
  22. #verify
  23. read -p 'Is the information correct (y,n): ' verified
  24. if [ .$verified != ."y" ]; then
  25. echo "Goodbye";
  26. exit 0;
  27. fi
  28. #iptables rules
  29. if [ .$iptables_add = ."y" ]; then
  30. for node in $nodes; do
  31. /usr/sbin/iptables -A INPUT -j ACCEPT -p tcp --dport 5432 -s ${node}/32
  32. /usr/sbin/iptables -A INPUT -j ACCEPT -p tcp --dport 22000 -s ${node}/32
  33. done
  34. apt-get remove iptables-persistent -y
  35. echo iptables-persistent iptables-persistent/autosave_v4 boolean true | debconf-set-selections
  36. echo iptables-persistent iptables-persistent/autosave_v6 boolean true | debconf-set-selections
  37. apt-get install -y iptables-persistent
  38. systemctl restart fail2ban
  39. fi
  40. #setup ssl
  41. sed -i /etc/postgresql/$database_version/main/postgresql.conf -e s:'snakeoil.key:snakeoil-postgres.key:'
  42. cp /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/ssl-cert-snakeoil-postgres.key
  43. chown postgres:postgres /etc/ssl/private/ssl-cert-snakeoil-postgres.key
  44. chmod 600 /etc/ssl/private/ssl-cert-snakeoil-postgres.key
  45. #postgresql.conf - append settings
  46. cp /etc/postgresql/$database_version/main/postgresql.conf /etc/postgresql/$database_version/main/postgresql.conf-$now
  47. #cat ../postgresql/postgresql.conf > /etc/postgresql/$database_version/main/postgresql.conf
  48. echo "#listen_addresses = '127.0.0.1,xxx.xxx.xxx.xxx'" >> /etc/postgresql/$database_version/main/postgresql.conf
  49. echo "listen_addresses = '*'" >> /etc/postgresql/$database_version/main/postgresql.conf
  50. echo "wal_level = 'logical'" >> /etc/postgresql/$database_version/main/postgresql.conf
  51. echo "track_commit_timestamp = on" >> /etc/postgresql/$database_version/main/postgresql.conf
  52. echo "max_connections = 100" >> /etc/postgresql/$database_version/main/postgresql.conf
  53. echo "max_wal_senders = 10" >> /etc/postgresql/$database_version/main/postgresql.conf
  54. echo "max_replication_slots = 48" >> /etc/postgresql/$database_version/main/postgresql.conf
  55. echo "max_worker_processes = 48" >> /etc/postgresql/$database_version/main/postgresql.conf
  56. #pg_hba.conf - append settings
  57. cp /etc/postgresql/$database_version/main/pg_hba.conf /etc/postgresql/$database_version/main/pg_hba.conf-$now
  58. cat ../postgresql/pg_hba.conf > /etc/postgresql/$database_version/main/pg_hba.conf
  59. #chmod 640 /etc/postgresql/$database_version/main/pg_hba.conf
  60. #chown -R postgres:postgres /etc/postgresql/$database_version/main
  61. echo "host all all 127.0.0.1/32 trust" >> /etc/postgresql/$database_version/main/pg_hba.conf
  62. echo "hostssl all all 127.0.0.1/32 trust" >> /etc/postgresql/$database_version/main/pg_hba.conf
  63. echo "hostssl replication postgres 127.0.0.1/32 trust" >> /etc/postgresql/$database_version/main/pg_hba.conf
  64. for node in $nodes; do
  65. echo "host all all ${node}/32 trust" >> /etc/postgresql/$database_version/main/pg_hba.conf
  66. echo "hostssl all all ${node}/32 trust" >> /etc/postgresql/$database_version/main/pg_hba.conf
  67. echo "hostssl replication postgres ${node}/32 trust" >> /etc/postgresql/$database_version/main/pg_hba.conf
  68. done
  69. #reload configuration
  70. systemctl daemon-reload
  71. #reload the config
  72. sudo -u postgres psql -p $database_port -c "SELECT pg_reload_conf();"
  73. #restart postgres
  74. systemctl restart postgresql
  75. #set the working directory
  76. cwd=$(pwd)
  77. cd /tmp
  78. #add extension pgcrypto
  79. if [ .$group_create = ."n" ]; then
  80. sudo -u postgres psql -d freeswitch -c "CREATE EXTENSION pgcrypto;";
  81. fi
  82. #message to user
  83. echo "Completed"