Note: For newer versions of NodeJS, Nginx and MongoDB, checkout their websites and update the related parts.
run all the commands in terminal as the root user (sudo su)
yum update
yum install -y epel-release
yum install -y vim wget zip yum-utils net-tools gcc-c++ make chrony jqsince yum install git installs git v1.x, for git v2 we should run the following to install it from another resource.
yum -y install https://packages.endpoint.com/rhel/7/os/x86_64/endpoint-repo-1.7-1.x86_64.rpm
yum -y install gitto check/set server timezone and enable NTP time sync:
timedatectl set-timezone UTC #Asia/Dubai
timedatectl set-ntp on
systemctl enable --now chronyd
## check status
chronyc sources
chronyc activity
timedatectlReplace USER and PASS and PROXY for proxy settings.
export https_proxy=http://USER:PASS@PROXY:443/
vim /etc/yum.conf
#proxy=http://PROXY:443/
#proxy_username=USER
#proxy_password=PASSOR a DNS proxy in the system level dns:
##yum install -y NetworkManager-tui
#nmtui
vim /etc/resolv.conf
#nameserver 185.51.200.2
#nameserver 178.22.122.100Since you have installed epel-release, you have access to the rpm of nginx and you could simply install it with the following command:
yum -y install nginxFor a newer version, of if you have not installed epel-release you have to make the repo file yourself like this:
vim /etc/yum.repos.d/nginx.repothen press i, and paste (ctrl/command+v) this:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
then press esc then type :wq and press enter
yum install -y nginx
service nginx start
chkconfig nginx onFor preventing 403 and permission errors for nginx, if SELinux is in enforcing mode (check with getenforce) use the following to allow serving static files
setsebool -P httpd_can_network_connect on
setsebool -P httpd_setrlimit on
chcon -Rt httpd_sys_content_t /var/www # OR /usr/share/nginx/html/If the configuration above did not resolve permission issues with nginx filea read or proxying, please read https://www.nginx.com/blog/using-nginx-plus-with-selinux/
For preventing (24: Too many open files) errors in nginx, since defaults of ulimit is low (1024 soft, 4096 hard), you can increase it just for the nginx processes by setting specific configurations in it's systemd service file, like this:
# systemctl edit nginx
echo "[Service]" >> /etc/systemd/system/nginx.service.d/override.conf
echo "LimitNOFILE=65536" >> /etc/systemd/system/nginx.service.d/override.conf
systemctl daemon-reload
## Add the following to your main nginx.conf (this number is suitable for 4 workers)
# worker_rlimit_nofile 16384;
systemctl restart nginx
## Check with the following
ps aux | grep nginx
cat /proc/<nginx-pid>/limitsFor SSL: first install certbot with it's nginx extentions like below, then run it to issue or install the certificate(s) for your domain(s). Make sure to create your nginx config for those domains in /etc/nginx/conf.d/DOMAN.conf, and your server_name is similiar to the domain you will issue a certificate for.
yum install -y certbot python2-certbot-nginx
#certbot certonly --nginx #only issues certificate
#certbot install --nginx #only installs an already issued certificate
certbot #issues and installs certificateAlternatively, replace DOMAIN and EMAIL in the following with yours, and choose to run the one that suits you (wildcard or non-wildcard certificate)
# for non-wildcard certificates (automatic challange resolving & renewable):
certbot certonly --nginx --non-interactive --agree-tos --redirect -m [email protected] -d www.DOMAIN.com
echo "0 0,12 * * * root certbot renew" | sudo tee -a /etc/crontab > /dev/null
# for wildcard certificates (manual issue and renew by resolving dns challange each 3 month):
certbot certonly --agree-tos --manual --manual-public-ip-logging-ok --preferred-challenges dns-01 -m [email protected] -d "*.DOMAIN.com,DOMAIN.com"The following commands installs nodejs from NodeSource, you can change its version from 10 to 12, 14 (LTS) or 15.
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
yum install -y nodejs yarn
npm i -g pm2 typescript
#pm2 startup systemd -u gitlab-runner --hp /home/gitlab-runner
pm2 install typescript
pm2 install pm2-logrotatesome other useful npm packages:
npm i -g gulp gulp-cli bowerYou can make a yum repo config and install everything with a single command like:
vim /etc/yum.repos.d/mongodb-org-4.4.repothen press i, and paste (ctrl/command+v) this:
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
then press esc then type :wq and press enter
yum install -y mongodb-orgOR you can install all mongodb packages separately directly with their RPM links found in this link. PS: You have to install them in order to prevent dependancy errors.
yum install -y https://repo.mongodb.org/yum/redhat/7/mongodb-org/???/x86_64/RPMS/mongodb-org-??????.el7.x86_64.rpmAfter installing, run and check like this:
systemctl start mongod
systemctl enable mongod
#mongo
mongoshPlease also consider disabling Transparent Huge Pages for better performance: https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/
yum install -y redis
systemctl start redis
systemctl enable redis
#redis-cli pingYou can also consider the following performance optimizations. First one enables Redis AOF for better data persistense. Second one improves memory performance for Redis.
vim /etc/redis.conf
#appendonly yes
#appendfsync everysec
sysctl vm.overcommit_memory=1
vim /etc/sysctl.conf
vm.overcommit_memory = 1firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --permanent --add-port=3000/tcp
firewall-cmd --reloadOR
yum install -y system-config-firewall-tui
system-config-firewall-tuiAlso if you keep SELinux in enforcing mode, there are restrictions on http ports you can open. this will show a list of ports you can open:
semanage port -l | grep http_port_tand this will add to it
semanage port -a -t http_port_t -p tcp 30000#exec ssh-agent bash
#eval `ssh-agent -s`
#ssh-keygen -t rsa
#ssh-add ~/.ssh/gitlab
#vim /etc/ssh/sshd_config
#Host gitlab.com
#RSAAuthentication yes
#IdentityFile ~/.ssh/gitlab
#systemctl restart sshd.service
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
yum install -y gitlab-runner
gitlab-runner registerenter https://gitlab.com
yum install -y device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
usermod -aG docker $(whoami)
systemctl enable docker
systemctl start dockerFor docker-compose
#yum install -y python-pip python-devel
#yum groupinstall 'development tools'
#pip install --upgrade pip
#pip install docker-compose
curl -L "https://github.com/docker/compose/releases/download/1.25.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
curl -L https://raw.githubusercontent.com/docker/compose/1.25.1/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
source /etc/bash_completion.d/docker-composeFor docker alias commands you can use the ones provided here: https://gist.github.com/cjus/20c2e1026524e83db532b113dce02403
vim ~/.docker_aliasesthen press i, and paste (ctrl/command+v) the content of the .docker_aliases file, then press esc and then shift+Z+Z
vim ~/.bash_profileadd the following to the top of the file (after the similiar script that loads .bashrc) by pressing i, and pasting (ctrl/command+v) this:
if [ -f ~/.docker_aliases ]; then
. ~/.docker_aliases
fi
then press esc and then shift+Z+Z
then run it for the current ssh session:
source ~/.docker_aliasesWhen editing authorized_keys file for each user, paste that user's public keys from each of his machines in a separate line.
adduser username
passwd -d username
su username
mkdir -p ~/.ssh
chmod 700 ~/.ssh
vim ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keysTo enable or disable login with passwords, you should change PasswordAuthentication from the following config file and reload sshd service:
vim /etc/ssh/config
service sshd reloadyum list | grep mongo
yum downgrade mongodb*
yum remove mongodb*
yum clean all
yum makecache fast
package-cleanup --oldkernels --count=1 #for disk cleanup (reboot first to make sure you are using latest downloaded kernel)source and/or destination could be either a local path or a remote path (in host:/path format).
scp -p source destination
scp -rp source destination
docker cp source destination #use docker container ID instead of host name
rsync -azvhP source destination #for fewer files with larger sizes
rsync -ah --info=progress2 source destination #for more files with smaller sizesdf -h #look for the one mounted at /
du -sh #./*netstat -tulpngrep -Po '\d+\.\d+\.\d+\.\d+' /var/log/nginx/access.log | uniq | sort
grep -Po '\d+\.\d+\.\d+\.\d+' /var/log/nginx/access.log | uniq | wc -l#hostnamectl
hostnamectl set-hostname hostname
echo 127.0.0.1 hostname >> /etc/hostsssh-keygen # to create id_rsa & id_rsa.pub
ssh-copy-id SERVER # use password to store your id_rsa.pub into the remote account's authorized_keysyum install -y bash-completion bash-completion-extras
source /etc/profile.d/bash_completion.shyou can change prompt colors by changing 1;34m and 36m from the last line (add/remove 1; for light/bold switch or use other numbers for other colors: 🔴red=31, 🟢green=32, 🟡yellow=33, 🔵blue=34, 🟣purple=35, 💧cyan=36)
curl "https://raw.githubusercontent.com/git/git/$(gitver=$(git --version); echo "${gitver/git version /v}")/contrib/completion/git-prompt.sh" > /etc/.git-prompt.sh
echo "source /etc/.git-prompt.sh" >> /etc/bashrc
echo 'export GIT_PS1_SHOWCOLORHINTS=1 GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 GIT_PS1_SHOWUPSTREAM="auto verbose"' >> /etc/bashrc
echo "export PROMPT_COMMAND='"'__git_ps1 "\033[1;34m[\033[1;36m\u\033[36m@\h\033[1;34m:\w]\\\$\033[m" "\n> "'"'" >> /etc/bashrcyou can use some online ASCII art generator service
vim /etc/issue
# Put banner content here
vim /etc/ssh/sshd_config
# Banner /etc/issue
service sshd restart
To use a jump box in Windows SSH via
ssh -J jumphost hostor via~/.ssh/configfile parameterProxyJump jumphostyou need to use at OpenSSH Win32/64 with version 8+ (default version of OpenSSH Win32/64 in Win 10 (or below) is below v8 and has a bug on interpreting jump host)