Skip to content

Instantly share code, notes, and snippets.

@ishto7
Last active September 25, 2021 16:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ishto7/0a941b73e816f6a7dc001d802db5332e to your computer and use it in GitHub Desktop.
Save ishto7/0a941b73e816f6a7dc001d802db5332e to your computer and use it in GitHub Desktop.
Initial Setup for a CentOS 7 Server with DirectAdmin, Nginx, Python3.6 & MongoDB
#!/bin/bash
# What do I do when I setup a new server? I use MongoDB and Nginx for my apps. So let's get down to business
# Install Nginx with Directadmin. (!Make sure you have DA v2.0 or above)
cd /usr/local/directadmin/cusombuild
./build set webserver nginx
./build set php1_mode php-fpm
./build update
./build all d
./build rewrite_confs
# Install Tmux. (It's a godbless teminal multiplexer)
yum install tmux
# Install MongoDB v4.0
# Make a new repo with nano (or vim)
nano /etc/yum.repos.d/mongodb-org.repo
# Then paste the code bellow to it:
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
# Then save the file with ^x in nano
sudo yum install -y mongodb-org
systemctl start mongod
# Ensure that MongoDB will start following a system reboot by issuing the following command:
sudo chkconfig mongod on
# to configure mongo admin user and make a port public
mongo
# Then enter the code bellow in the mongo environment:
use admin
db.createUser(
{
user: "admindb",
pwd: "YOUR_PASSWORD",
roles: [ "root" ]
}
)
exit
# Next, we edit MongoDB config /etc/mongod.conf file and add our wanted configurations
nano /etc/mongod.conf
# Add or edit the section to have:
security:
authorization: enabled
# set if needed to be public???
net:
bindIp: 0.0.0.0
# Just save and exit nano
# If you did make your db public, just open the port. Otherwise, Don't!
firewall-cmd --zone=public --add-port=27017/tcp --permanent
# Sometimes you are in lack of memory. if so, you can run a clearcache.sh file so it unleashes the momory used by apps cache. But be carefull!
nano ~/clearcache.sh
# Paste the code to it:
#!/bin/bash
# Note, we are using "echo 3", but it is not recommended in production. use "echo 2" instead $
echo "echo 3 > /proc/sys/vm/drop_caches"
sync; echo 3 > /proc/sys/vm/drop_caches
# Save and exit. Then run the file with:
bash ~/clearcache.sh
# Of course you need Python3.6.5
sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
sudo yum update
sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
alias pip3='pip3.6'
alias python3='python3.6'
pip3 install --upgrade pip
pip3 install virtualenv
# Enjoy Your New Server :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment