forked from jtnelson/centos-server-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_centos.sh
executable file
·115 lines (94 loc) · 3.23 KB
/
setup_centos.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
#########################################
### Centos 6 Server Setup (Rackspace) ###
### ###
######## RUN THIS SCRIPT AS ROOT ########
#########################################
USER=$1
trap 'echo interrupted; exit' INT
# Send an alert if the previous command exited with 0 status
alert (){
STATUS=$?
if [ $STATUS -eq 0 ]; then
echo $1
fi
}
die (){
MSG=$1
echo "ERROR: $MSG" >&2
exit 127
}
if [ -z $USER ]; then
die "Please specify a username"
fi
# Create user account with sudo access and force password change
# on initial login
adduser $USER
echo $USER | passwd $USER --stdin
chage -d 0 $USER
echo "$USER ALL=(ALL) ALL" >> /etc/sudoers
alert "Created account for $USER"
# Install apache2 and mod-ssl, make sure apache starts and boot time and open port 80
yum -y -q install httpd mod_ssl
SERVER_NAME=`hostname`
sed -i 's/#ServerName www\.example\.com:80/ServerName $SERVER_NAME\.com/g' /etc/httpd/conf/httpd.conf
chkconfig --levels 2345 httpd on
service httpd start
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
chown -R apache /var/www/html/
alert "Installed Apache with mod-ssl enabled"
# Install the latest version of JAVA (openjdk)
yum -y -q install java-1.7.0-openjdk java-1.7.0-openjdk-devel.x86_64
export JAVA_HOME=/usr/lib/jvm/jre/
alert "Installed Java"
# Install the latest version of PHP
yum -y -q install php php-cli php-common php-dba php-gd php-imap php-mbstring php-mysql php-pdo php-pear php-pecl-apc php-process php-xml cups-php php-pecl-memcache uuid-php
alert "Installed PHP"
# Install memcached
yum -y -q install memcached
chkconfig --level 2345 memcached on
iptables -I INPUT -p tcp --dport 11211 -j ACCEPT
iptables -I INPUT -i eth1 -p tcp --dport 11211 -j ACCEPT
service iptables save
alert "Installed memcached"
# Install gcc
yum -y -q install gcc gcc-c++
alert "Installed gcc"
# Install mysql
yum -y -q install mysql mysql-server mysql-devel
chkconfig --levels 2345 mysqld on
service mysqld start
alert "Installed mysql"
# Set root password for mysql
PASSWORD=`openssl rand -base64 32 | cut -c1-20`
echo $PASSWORD > .mysqlrootpass
mysqladmin -u root password $PASSWORD
alert "Set mysql root password to $PASSWORD"
# Install phpMyAdmin
wget -q http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
wget -c -q http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/3.4.9/phpMyAdmin-3.4.9-english.tar.gz
tar xf phpMyAdmin*
rm phpMyAdmin-3.4.9-english.tar.gz
rm rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
mv phpMyAdmin-3.4.9-english /usr/share/phpmyadmin
cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php
sed -i 's/'\''cookie'\''/'\''http'\''/g' /usr/share/phpmyadmin/config.inc.php
echo "Alias /phpmyadmin /usr/share/phpmyadmin" >> /etc/httpd/conf/httpd.conf
service httpd restart
alert "Installed phpMyAdmin"
# Install nfs and rcpbind
yum -y -q install nfs-utils nfs-utils-lib
service rpcbind start
service nfs start
chkconfig --levels 2345 nfs on
chkconfig --levels 2345 rpcbind on
alert "Installed nfs and rpcbind"
# Manually copy over files in the "fs" directory
declare -a arr=("/etc/init.d/iptables" "/etc/sysconfig/iptables")
for i in "${arr[@]}"
do
cat fs"$i" > "$i"
done
service iptables restart
exit 0