Project

General

Profile

Database Server Installation Shared » History » Version 39

Amber Herold, 05/17/2010 11:48 AM

1 1 Amber Herold
h1. Database Server Installation
2
3
h2. Install MySQL 
4
5
The following is for the computer that hosts the databases. This involves installing MySQL server and creation/configuration of the leginondb and projectdb databases.
6
7 38 Amber Herold
8 1 Amber Herold
 
9
h3. Install MySQL-Server and MySQL-Client
10 38 Amber Herold
11
*Note:* You may already have MySQL Server and Client installed. Check by typing mysql at the command line. 
12
If you see a MySQL prompt (mysql>), you may skip this step.
13 1 Amber Herold
14 15 Neil Voss
To install Mysql on Linux you have two options (the first option is better):
15 1 Amber Herold
16 15 Neil Voss
# Use your package installer (yum, zypper, YaST, apt-get). For example:
17
<pre>sudo yum install mysql mysql-server</pre>
18
# Download the latest MySQL-server package for Linux from http://www.mysql.com
19 1 Amber Herold
20 15 Neil Voss
h3. Example MySQL configuration files are usually located in /usr/share/mysql.
21 1 Amber Herold
22
<pre>
23
ls /usr/share/mysql/my*
24 15 Neil Voss
    /usr/share/mysql/my-huge.cnf
25
    /usr/share/mysql/my-innodb-heavy-4G.cnf
26
    /usr/share/mysql/my-large.cnf
27
    /usr/share/mysql/my-medium.cnf
28
    /usr/share/mysql/my-small.cnf
29 20 Neil Voss
</pre>
30
If that does not work try the locate function
31
<pre>
32 15 Neil Voss
locate my | egrep "\.cnf$"
33
    /etc/my.cnf
34 1 Amber Herold
    /usr/share/mysql/my-huge.cnf
35
    /usr/share/mysql/my-innodb-heavy-4G.cnf
36
    /usr/share/mysql/my-large.cnf
37
    /usr/share/mysql/my-medium.cnf
38
    /usr/share/mysql/my-small.cnf
39 3 Amber Herold
</pre>
40 1 Amber Herold
41 15 Neil Voss
h3. Configure my.cnf in /etc using my-huge.cnf as the template
42 1 Amber Herold
43 18 Neil Voss
# Copy my-huge.cnf to my.cnf
44 19 Neil Voss
<pre>sudo cp -v /usr/share/mysql/my-huge.cnf /etc/my.cnf</pre>
45 22 Neil Voss
# Edit /etc/my.cnf to add or change query cache variables like these (be sure to place them under the @[mysqld]@ section):
46 1 Amber Herold
<pre>
47 39 Amber Herold
query_cache_type = 1
48 1 Amber Herold
query_cache_size = 100M
49
query_cache_limit= 100M
50 21 Neil Voss
</pre>
51 11 Neil Voss
# Search for the text default-storage-engine in /etc/my.cnf.  If it exists and is set to other than MyISAM, you should change it to:
52 1 Amber Herold
<pre>default-storage-engine=MyISAM</pre>
53 10 Neil Voss
54 22 Neil Voss
h3. Start the MySQL Server
55 1 Amber Herold
56 10 Neil Voss
For CentOS/Fedora/RHEL system use the service command:
57
58 1 Amber Herold
<pre>
59 10 Neil Voss
sudo /sbin/service mysqld start
60 1 Amber Herold
</pre>
61
62 10 Neil Voss
For other Unix systems:
63
64
<pre>
65
sudo /etc/init.d/mysqld start
66
</pre>
67
68 12 Neil Voss
or on some installations,
69 1 Amber Herold
70
<pre>
71 10 Neil Voss
sudo /etc/init.d/mysql start
72 1 Amber Herold
</pre>
73
74
For future reference: start | stop | restart MySQL Server with similar commands:
75
76
<pre>
77 10 Neil Voss
sudo /etc/init.d/mysqld start
78
sudo /etc/init.d/mysqld stop
79
sudo /etc/init.d/mysqld restart
80
sudo /sbin/service mysqld start
81
sudo /sbin/service mysqld stop
82
sudo /sbin/service mysqld restart
83 1 Amber Herold
</pre>
84
85 12 Neil Voss
If you want to start MySQL automatically at boot
86 1 Amber Herold
87
<pre>
88 37 Amber Herold
sudo /sbin/chkconfig mysqld on
89 1 Amber Herold
</pre>
90 23 Neil Voss
or for SuSe:
91
<pre>
92
sudo /sbin/chkconfig mysql on
93
</pre>
94 1 Amber Herold
95
h3. 6. For future reference, the database location will be:
96
97 10 Neil Voss
<pre>
98
ls /var/lib/mysql
99 11 Neil Voss
    ibdata1  ib_logfile0  ib_logfile1  mysql  mysql.sock  test
100 1 Amber Herold
</pre>
101
102
h3. 7. Create the Leginon database, call it leginondb
103 3 Amber Herold
104 1 Amber Herold
<pre>
105 10 Neil Voss
sudo mysqladmin create leginondb
106 1 Amber Herold
</pre>
107
108
h3. 8. Create the Project database, call it projectdb
109
110
<pre>
111
sudo mysqladmin create projectdb
112
</pre>
113
114 11 Neil Voss
h3. 9. Connect to mysql db
115
116 28 Neil Voss
If starting from scratch the mysql root user will have no password. This is assumed to be the case and we will set it later.
117 1 Amber Herold
118 23 Neil Voss
<pre>
119 28 Neil Voss
mysql -u root mysql
120 23 Neil Voss
</pre>
121 1 Amber Herold
122 11 Neil Voss
<pre>
123
mysql> select user, password, host from user;
124 1 Amber Herold
      +------+----------+-----------+
125
      | user | password | host      |
126
      +------+----------+-----------+
127
      | root |          | localhost |
128
      | root |          | host1     |
129
      |      |          | host1     |
130
      |      |          | localhost |
131
      +------+----------+-----------+
132
      4 rows in set (0.00 sec)
133
</pre>
134
135
h3. 10. Create user
136
137 29 Neil Voss
Create and grant privileges to a user called usr_object for the databases on both the localhost and other hosts involved. For example, use wild card '%' for all hosts. You can set specific (@ALTER, CREATE, DROP, DELETE, INSERT, RENAME, SELECT, UPDATE@) privileges or @ALL@ privileges to the user. See MySQL Reference Manual for details.
138 3 Amber Herold
139 36 Amber Herold
At the mysql prompt execute the following commands:
140 1 Amber Herold
<pre>
141 36 Amber Herold
CREATE USER usr_object@'localhost' IDENTIFIED BY 'YOUR PASSWORD';
142
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* TO usr_object@'localhost';
143
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* TO usr_object@'localhost';
144 1 Amber Herold
</pre>
145
146
less secure version (no password and all privileges), we recommend not allowing the DROP and DELETE privileges.
147
148 36 Amber Herold
At the mysql prompt execute the following commands:
149 24 Neil Voss
<pre>
150 36 Amber Herold
CREATE USER usr_object@'localhost';
151
GRANT ALL PRIVILEGES ON leginondb.* TO usr_object@'localhost';
152
GRANT ALL PRIVILEGES ON projectdb.* TO usr_object@'localhost';
153 1 Amber Herold
</pre>
154 24 Neil Voss
155
Similarly, you can assign a domain
156 26 Neil Voss
157 1 Amber Herold
<pre>
158 36 Amber Herold
CREATE USER usr_object@'%.mydomain.edu' IDENTIFIED BY 'YOUR PASSWORD';
159
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* to usr_object@'%.mydomain.edu';
160
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* to usr_object@'%.mydomain.edu';
161 24 Neil Voss
</pre>
162 3 Amber Herold
163 1 Amber Herold
Next, give create and access privileges for the processing databases which begin with "ap".
164 10 Neil Voss
165 24 Neil Voss
<pre>
166 27 Neil Voss
# if your web host is local
167 36 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@localhost; 
168 27 Neil Voss
# for all other hosts if you are accessing the databases from another computer
169 36 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@'%.mydomain.edu';       
170 1 Amber Herold
</pre>
171
172
h3. 11. Change Root password
173
174 28 Neil Voss
To set the root password use the command: 
175 1 Amber Herold
176 28 Neil Voss
<pre>
177
sudo mysqladmin -u root password NEWPASSWORD
178
</pre>
179 1 Amber Herold
180 28 Neil Voss
Or you can do it from within mysql
181 10 Neil Voss
<pre>
182 36 Amber Herold
update user set password=password('your_own_root_password') where user="root";
183 10 Neil Voss
Query OK, 2 rows affected (0.01 sec)
184 1 Amber Herold
Rows matched: 2  Changed: 2  Warnings: 0
185
186 36 Amber Herold
flush privileges;
187
^D or exit;
188 3 Amber Herold
</pre>
189 1 Amber Herold
190 3 Amber Herold
191 1 Amber Herold
From now on, you will need to specify the password to connect to the database as root user like this:
192
193 30 Neil Voss
<pre>
194 36 Amber Herold
mysql -u root -p mysql
195 1 Amber Herold
</pre>
196
197
h3. 12. Check MySQL variables
198
199 31 Neil Voss
<pre>
200 36 Amber Herold
mysql -u usr_object -p leginondb
201 1 Amber Herold
202 36 Amber Herold
SHOW VARIABLES LIKE 'query%';
203 1 Amber Herold
      +------------------------------+-----------+
204
      | Variable_name                | Value     |
205
      +------------------------------+-----------+
206
      | ft_query_expansion_limit     | 20        |
207
      | have_query_cache             | YES       |
208
      | long_query_time              | 10        |
209
      | query_alloc_block_size       | 8192      |
210
      | query_cache_limit            | 104857600 | <<---This should correspond to your change
211
      | query_cache_min_res_unit     | 4096      |
212
      | query_cache_size             | 104857600 | <<---This should correspond to your change
213
      | query_cache_type             | ON        | <<---This should correspond to your change
214
      | query_cache_wlock_invalidate | OFF       |
215
      | query_prealloc_size          | 8192      |
216
      +------------------------------+-----------+
217
      10 rows in set (0.00 sec)
218
219 36 Amber Herold
exit;
220 1 Amber Herold
</pre>
221
222
h3. Make sure MySQL is running
223
224 3 Amber Herold
<pre>
225 36 Amber Herold
mysqlshow
226 1 Amber Herold
      +--------------+
227
      | Databases    |
228 30 Neil Voss
      +--------------+
229
      | mysql        |
230
      | leginondb    |
231
      | projectdb    |
232 1 Amber Herold
      +--------------+
233
</pre>
234 30 Neil Voss
235 36 Amber Herold
h3. Run the following command from the command line:
236 1 Amber Herold
237 30 Neil Voss
<pre>
238 1 Amber Herold
php -r "mysql_connect('localhost', 'usr_object', 'PASSWORD', 'leginondb'); echo mysql_stat();"; echo ""
239
</pre>
240 30 Neil Voss
241 1 Amber Herold
Expected output:
242
243 30 Neil Voss
<pre>
244
Uptime: 1452562 Threads: 1 Questions: 618 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 106 Queries per second avg: 0.000
245 1 Amber Herold
</pre>
246 30 Neil Voss
247 36 Amber Herold
If there are any error messages, mysql may be configured incorrectly.
248 30 Neil Voss
249 1 Amber Herold
h2. Configure phpMyAdmin 
250 30 Neil Voss
251 1 Amber Herold
Edit the phpMyAdmin config file @/etc/phpMyAdmin/config.inc.php@ and change the following lines:
252 12 Neil Voss
253 30 Neil Voss
<pre>
254 1 Amber Herold
$cfg['Servers'][$i]['AllowRoot']     = FALSE;
255
</pre>
256 30 Neil Voss
257 1 Amber Herold
Edit the phpMyAdmin apache config file @/etc/httpd/conf.d/phpMyAdmin.conf@ and change the following lines:
258
259
<pre>
260
<Directory /usr/share/phpMyAdmin/>
261
   order deny,allow
262
   deny from all
263
   allow from 127.0.0.1
264
   allow from YOUR_IP_ADDRESS
265
</Directory>
266 31 Neil Voss
</pre>
267
268 1 Amber Herold
*Note:* If you want to access phpMyAdmin from another computer, you can also add it to this config file with an @allow from@ tag
269 33 Neil Voss
270
Next restart the web server to take on the new setting
271
<pre>
272
sudo /sbin/service httpd restart
273
</pre>
274 1 Amber Herold
275 35 Neil Voss
To test the phpMyAdmin configuration, point your browser to http://YOUR_IP_ADDRESS/phpMyAdmin or http://localhost/phpMyAdmin and login with the usr_object user.
276
277 33 Neil Voss
!phpMyAdmin.png!
278
279
A common problem is that the firewall may be blocking access to the web server and mysql server. On CentOS/Fedora you can configure this with the system config:
280
281
<pre>
282
system-config-securitylevel
283
</pre>
284
285 1 Amber Herold
Firewall configuration is specific to different Unix distributions, so consult a guide on how to do this on non-RedHat machines.